Skip to content

Commit

Permalink
[OS] allow opt-in for old version
Browse files Browse the repository at this point in the history
  • Loading branch information
aricart committed Jun 8, 2023
1 parent 98460ae commit b115d4c
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
18 changes: 13 additions & 5 deletions jetstream/objectstore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -835,6 +835,10 @@ export class ObjectStoreImpl implements ObjectStore {
}

async init(opts: Partial<ObjectStoreOptions> = {}): Promise<void> {
const adapters = [
new ObjectStoreKeysV1(this.name),
new ObjectStoreKeysV2(this.name),
];
try {
this.stream = objectStoreStreamName(this.name);
} catch (err) {
Expand All @@ -844,11 +848,6 @@ export class ObjectStoreImpl implements ObjectStore {
const si = await this.jsm.streams.info(this.name);
const { subjects } = si.config;

// if we are here, we could we have different versions
const adapters = [
new ObjectStoreKeysV1(this.name),
new ObjectStoreKeysV2(this.name),
];
const keys = adapters.find((k) => {
const a = k.streamSubjectNames();
return a.includes(subjects[0]) && a.includes(subjects[1]);
Expand All @@ -859,6 +858,15 @@ export class ObjectStoreImpl implements ObjectStore {
this.keys = keys;
} catch (err) {
if (err.message === "stream not found") {
// honor the version given, if specified - otherwise best version
switch (opts.version) {
case 1:
this.keys = adapters[0];
break;
case 2:
this.keys = adapters[1];
break;
}
const sc = Object.assign({}, opts) as StreamConfig;
sc.name = this.stream;
sc.allow_rollup_hdrs = true;
Expand Down
1 change: 1 addition & 0 deletions jetstream/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1250,6 +1250,7 @@ export type ObjectStoreOptions = {
replicas: number;
"max_bytes": number;
placement: Placement;
version: number;
};
export type ObjectResult = {
info: ObjectInfo;
Expand Down

0 comments on commit b115d4c

Please sign in to comment.