Skip to content

Commit 2230e76

Browse files
committed
ft: ZENKO-2968 enable sharding on bucket creation
1 parent d27c057 commit 2230e76

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

lib/storage/metadata/mongoclient/MongoClientInterface.js

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,8 @@ class MongoClientInterface {
9595
isLocationTransient } = params;
9696
const cred = MongoUtils.credPrefix(authCredentials);
9797
this.mongoUrl = `mongodb://${cred}${replicaSetHosts}/` +
98-
`?w=${writeConcern}&replicaSet=${replicaSet}` +
98+
`?w=${writeConcern}` +
99+
`${!!replicaSet ? `&replicaSet=${replicaSet}` : ''}` +
99100
`&readPreference=${readPreference}`;
100101
this.logger = logger;
101102
this.client = null;
@@ -104,6 +105,7 @@ class MongoClientInterface {
104105
this.replicationGroupId = replicationGroupId;
105106
this.database = database;
106107
this.isLocationTransient = isLocationTransient;
108+
this.replicaSet = replicaSet;
107109

108110
this.concurrentCursors = (process.env.CONCURRENT_CURSORS &&
109111
!Number.isNaN(process.env.CONCURRENT_CURSORS))
@@ -142,6 +144,7 @@ class MongoClientInterface {
142144
this.db = client.db(this.database, {
143145
ignoreUndefined: true,
144146
});
147+
this.adminDb = client.db('admin');
145148
return this.usersBucketHack(cb);
146149
});
147150
}
@@ -219,6 +222,21 @@ class MongoClientInterface {
219222
{ error: err.message });
220223
return cb(errors.InternalError);
221224
}
225+
if (this.replicaSet === undefined) {
226+
const cmd = {
227+
shardCollection: `${this.database}.${bucketName}`,
228+
key: { _id: 1 },
229+
};
230+
return this.adminDb.command(cmd, {}, err => {
231+
if (err) {
232+
log.error(
233+
'createBucket: enabling sharding',
234+
{ error: err.message });
235+
return cb(errors.InternalError);
236+
}
237+
return cb();
238+
});
239+
}
222240
return cb();
223241
});
224242
}

0 commit comments

Comments
 (0)