Skip to content
Merged
Show file tree
Hide file tree
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
12 changes: 10 additions & 2 deletions src/server/saved_objects/migrations/core/call_cluster.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,10 @@ export interface CallCluster {
(path: 'reindex', opts: ReindexOpts): Promise<any>;
(path: 'scroll', opts: ScrollOpts): Promise<SearchResults>;
(path: 'search', opts: SearchOpts): Promise<SearchResults>;
(path: 'tasks.get', opts: { taskId: string }): Promise<{ completed: boolean }>;
(path: 'tasks.get', opts: { taskId: string }): Promise<{
completed: boolean;
error?: ErrorResponse;
}>;
}

///////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -171,8 +174,13 @@ export interface SearchResults {
_scroll_id?: string;
}

export interface ErrorResponse {
type: string;
reason: string;
}

export interface BulkResult {
items: Array<{ index: { error?: { type: string; reason: string } } }>;
items: Array<{ index: { error?: ErrorResponse } }>;
}

export interface IndexInfo {
Expand Down
62 changes: 62 additions & 0 deletions src/server/saved_objects/migrations/core/elastic_index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,68 @@ describe('ElasticIndex', () => {
'indices.refresh',
]);
});

test('throws error if re-index task fails', async () => {
const callCluster = sinon.spy(async (path: string, arg: any) => {
switch (path) {
case 'indices.create':
expect(arg.body).toEqual({
mappings: {
doc: {
dynamic: 'strict',
properties: { foo: 'bar' },
},
},
settings: { auto_expand_replicas: '0-1', number_of_shards: 1 },
});
expect(arg.index).toEqual('.ze-index');
return true;
case 'reindex':
expect(arg).toMatchObject({
body: {
dest: { index: '.ze-index' },
source: { index: '.muchacha' },
},
refresh: true,
waitForCompletion: false,
});
return { task: 'abc' };
case 'tasks.get':
expect(arg.taskId).toEqual('abc');
return {
completed: true,
error: {
type: 'search_phase_execution_exception',
reason: 'all shards failed',
failed_shards: [],
},
};
default:
throw new Error(`Dunnoes what ${path} means.`);
}
});

const info = {
aliases: {},
exists: true,
indexName: '.ze-index',
mappings: {
doc: {
dynamic: 'strict',
properties: { foo: 'bar' },
},
},
};
await expect(Index.convertToAlias(callCluster, info, '.muchacha', 10)).rejects.toThrow(
/Re-index failed \[search_phase_execution_exception\] all shards failed/
);

expect(callCluster.args.map(([path]) => path)).toEqual([
'indices.create',
'reindex',
'tasks.get',
]);
});
});

describe('write', () => {
Expand Down
9 changes: 8 additions & 1 deletion src/server/saved_objects/migrations/core/elastic_index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,13 @@ async function reindex(callCluster: CallCluster, source: string, dest: string, b

completed = await callCluster('tasks.get', {
taskId: task,
}).then(result => result.completed);
}).then(result => {
if (result.error) {
const e = result.error;
throw new Error(`Re-index failed [${e.type}] ${e.reason} :: ${JSON.stringify(e)}`);
}

return result.completed;
});
}
}