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
fix(mongo): retry only 3 times if ensuring indexes fails #3272
Conversation
Codecov Report
@@ Coverage Diff @@
## master #3272 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 194 194
Lines 12094 12097 +3
Branches 2806 2807 +1
=========================================
+ Hits 12094 12097 +3
Continue to review full report at Codecov.
|
Here it should be enough if you define the unique constraint, but dont create it right ahead, create the two rows, and then call Note that to have that test "work" on every run, you will also need to wipe the collections so the indexes also get wiped. |
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.
thanks! just few nits before we merge
@@ -74,7 +74,7 @@ export class MongoSchemaGenerator extends AbstractSchemaGenerator<MongoDriver> { | |||
await Promise.all(promises); | |||
} | |||
|
|||
async ensureIndexes(options: EnsureIndexesOptions = {}): Promise<void> { | |||
async ensureIndexes(options: EnsureIndexesOptions = {}, retryLimit = 3): Promise<void> { |
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.
actually, lets not introduce another parameter, we already have the options there, so lets just add the retryLimit
inside that
async ensureIndexes(options: EnsureIndexesOptions = {}, retryLimit = 3): Promise<void> { | |
async ensureIndexes(options: EnsureIndexesOptions = {}): Promise<void> { | |
options.retryLimit ??= 3 |
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.
Updated!
if (retryLimit === 1) { | ||
const failedIndexes = res.filter(r => r.status === 'rejected').map((r: Dictionary, id) => `${promises[id][0]} - ${r.reason}`); | ||
throw new Error(`Failed to create indexes: ${failedIndexes.join(', ')}`); | ||
} | ||
await this.ensureIndexes({ retry: collectionsWithFailedIndexes }, retryLimit - 1); |
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.
if (retryLimit === 1) { | |
const failedIndexes = res.filter(r => r.status === 'rejected').map((r: Dictionary, id) => `${promises[id][0]} - ${r.reason}`); | |
throw new Error(`Failed to create indexes: ${failedIndexes.join(', ')}`); | |
} | |
await this.ensureIndexes({ retry: collectionsWithFailedIndexes }, retryLimit - 1); | |
if (options.retryLimit === 1) { | |
const failedIndexes = res.filter(r => r.status === 'rejected').map((r: Dictionary, id) => `${promises[id][0]} - ${r.reason}`); | |
throw new Error(`Failed to create indexes: ${failedIndexes.join(', ')}`); | |
} | |
await this.ensureIndexes({ | |
retry: collectionsWithFailedIndexes, | |
retryLimit: retryLimit - 1, | |
}); |
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.
Updated
Thanks! |
Closes #3261
@B4nan I am not sure how would I reproduce the error on tests, they are not complete as of now, any suggestions ?