Skip to content

Commit 4c1d2f6

Browse files
committed
Re-added Migration retries to handle concurrent server startups
1 parent 24c2a1c commit 4c1d2f6

File tree

2 files changed

+16
-9
lines changed

2 files changed

+16
-9
lines changed

spec/DefinedSchemas.spec.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -605,7 +605,7 @@ describe('DefinedSchemas', () => {
605605

606606
expect(logger.error).toHaveBeenCalledWith(`Failed to run migrations: ${error.toString()}`);
607607
});
608-
xit('should perform migration in parallel without failing', async () => {
608+
it('should perform migration in parallel without failing', async () => {
609609
const server = await reconfigureServer();
610610
const logger = require('../lib/logger').logger;
611611
spyOn(logger, 'error').and.callThrough();
@@ -632,7 +632,7 @@ describe('DefinedSchemas', () => {
632632
]);
633633

634634
const testSchema = (await Parse.Schema.all()).find(
635-
({ className }) => className === migrationOptions.schema[0].className
635+
({ className }) => className === migrationOptions.definitions[0].className
636636
);
637637

638638
expect(testSchema.indexes.aField).toEqual({ aField: 1 });

src/SchemaMigrations/DefinedSchemas.js

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -92,9 +92,18 @@ export class DefinedSchemas {
9292

9393
logger.info('Running Migrations Completed');
9494
} catch (e) {
95-
logger.error(`Failed to run migrations: ${e}`);
96-
97-
if (this.migrationsOptions.strict) process.exit(1);
95+
if (timeout) clearTimeout(timeout);
96+
if (this.retries < this.maxRetries) {
97+
this.retries++;
98+
// first retry 1sec, 2sec, 3sec total 6sec retry sequence
99+
// retry will only happen in case of deploying multi parse server instance
100+
// at the same time. Modern systems like k8 avoid this by doing rolling updates
101+
await this.wait(1000 * this.retries);
102+
await this.execute();
103+
} else {
104+
logger.error(`Failed to run migrations: ${e}`);
105+
if (process.env.NODE_ENV === 'production') process.exit(1);
106+
}
98107
}
99108
}
100109

@@ -160,15 +169,13 @@ export class DefinedSchemas {
160169
try {
161170
await this.updateSchema(localSchema, cloudSchema);
162171
} catch (e) {
163-
logger.error(`Error during update of schema for type ${cloudSchema.className}: ${e}`);
164-
throw e;
172+
throw `Error during update of schema for type ${cloudSchema.className}: ${e}`;
165173
}
166174
} else {
167175
try {
168176
await this.saveSchema(localSchema);
169177
} catch (e) {
170-
logger.error(`Error while saving Schema for type ${localSchema.className}: ${e}`);
171-
throw e;
178+
throw `Error while saving Schema for type ${localSchema.className}: ${e}`;
172179
}
173180
}
174181
}

0 commit comments

Comments
 (0)