Skip to content
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

[migration] Retry attempts for ES service unavailable #25255

Merged
merged 2 commits into from
Nov 7, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 38 additions & 26 deletions src/server/saved_objects/migrations/core/elastic_index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,39 +150,51 @@ export async function write(callCluster: CallCluster, index: string, docs: RawDo
export async function migrationsUpToDate(
callCluster: CallCluster,
index: string,
migrationVersion: MigrationVersion
migrationVersion: MigrationVersion,
retryCount: number = 10
): Promise<boolean> {
const indexInfo = await fetchInfo(callCluster, index);
try {
const indexInfo = await fetchInfo(callCluster, index);

if (!_.get(indexInfo, 'mappings.doc.properties.migrationVersion')) {
return false;
}
if (!_.get(indexInfo, 'mappings.doc.properties.migrationVersion')) {
return false;
}

// If no migrations are actually defined, we're up to date!
if (Object.keys(migrationVersion).length <= 0) {
return true;
}
// If no migrations are actually defined, we're up to date!
if (Object.keys(migrationVersion).length <= 0) {
return true;
}

const { count } = await callCluster('count', {
body: {
query: {
bool: {
should: Object.entries(migrationVersion).map(([type, latestVersion]) => ({
bool: {
must: [
{ exists: { field: type } },
{ bool: { must_not: { term: { [`migrationVersion.${type}`]: latestVersion } } } },
],
},
})),
const { count } = await callCluster('count', {
body: {
query: {
bool: {
should: Object.entries(migrationVersion).map(([type, latestVersion]) => ({
bool: {
must: [
{ exists: { field: type } },
{ bool: { must_not: { term: { [`migrationVersion.${type}`]: latestVersion } } } },
],
},
})),
},
},
},
},
index,
type: ROOT_TYPE,
});
index,
type: ROOT_TYPE,
});

return count === 0;
} catch (e) {
// retry for Service Unavailable
if (e.status !== 503 || retryCount === 0) {
throw e;
}

return count === 0;
await new Promise(r => setTimeout(r, 1000));

return await migrationsUpToDate(callCluster, index, migrationVersion, retryCount - 1);
}
}

/**
Expand Down