-
Notifications
You must be signed in to change notification settings - Fork 20
ARSN-596: treat NamespaceExists as idempotent success in createBucket #2643
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: development/8.4
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -466,21 +466,28 @@ class MongoClientInterface { | |
| // "constants.usersBucket" and "PENSIEVE" since it has already | ||
| // been created | ||
| if (bucketName !== constants.usersBucket && bucketName !== PENSIEVE) { | ||
| return this.db!.createCollection(bucketName).then(() => { | ||
| if (this.shardCollections) { | ||
| const cmd = { | ||
| shardCollection: `${this.database}.${bucketName}`, | ||
| key: { _id: 1 }, | ||
| }; | ||
| return this.adminDb!.command(cmd, {}) | ||
| .then(() => cb(null)) | ||
| .catch(err => { | ||
| log.error('createBucket: enabling sharding', { error: err }); | ||
| return cb(errors.InternalError); | ||
| }); | ||
| } | ||
| return cb(null); | ||
| }); | ||
| return this.db!.createCollection(bucketName) | ||
| .catch(err => { | ||
| if (err.codeName === 'NamespaceExists') { | ||
| return; | ||
| } | ||
| throw err; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we could call |
||
| }) | ||
| .then(() => { | ||
| if (this.shardCollections) { | ||
| const cmd = { | ||
| shardCollection: `${this.database}.${bucketName}`, | ||
| key: { _id: 1 }, | ||
| }; | ||
| return this.adminDb!.command(cmd, {}) | ||
| .then(() => cb(null)) | ||
| .catch(err => { | ||
| log.error('createBucket: enabling sharding', { error: err }); | ||
| return cb(errors.InternalError); | ||
| }); | ||
| } | ||
| return cb(null); | ||
| }); | ||
| } | ||
| return cb(null); | ||
| }) | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
will this not make us go through the
shardCollectionsbelow?could this cause a race condition if 2
shardCollectioncommands are sent to mongo in parallel, and possibly let the call fail (and still return an error)?