mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 01:38:56 -04:00
[Upgrade Assistant] Avoid creating the new index if it already exists when reindexing (#123817) (#123865) (#123922)
(cherry picked from commit 481fb8f536
)
This commit is contained in:
parent
a6ffe9cd65
commit
2d12a9dbeb
2 changed files with 45 additions and 8 deletions
|
@ -191,15 +191,26 @@ export const reindexServiceFactory = (
|
|||
|
||||
const { settings, mappings } = transformFlatSettings(flatSettings);
|
||||
|
||||
const { body: createIndex } = await esClient.indices.create({
|
||||
index: newIndexName,
|
||||
body: {
|
||||
settings,
|
||||
mappings,
|
||||
},
|
||||
});
|
||||
let createIndex;
|
||||
try {
|
||||
createIndex = await esClient.indices.create({
|
||||
index: newIndexName,
|
||||
body: {
|
||||
settings,
|
||||
mappings,
|
||||
},
|
||||
});
|
||||
} catch (err) {
|
||||
// If for any reason the new index name generated by the `generateNewIndexName` already
|
||||
// exists (this could happen if kibana is restarted during reindexing), we can just go
|
||||
// ahead with the process without needing to create the index again.
|
||||
// See: https://github.com/elastic/kibana/issues/123816
|
||||
if (err?.body?.error?.type !== 'resource_already_exists_exception') {
|
||||
throw err;
|
||||
}
|
||||
}
|
||||
|
||||
if (!createIndex.acknowledged) {
|
||||
if (createIndex && !createIndex?.body?.acknowledged) {
|
||||
throw error.cannotCreateIndex(`Index could not be created: ${newIndexName}`);
|
||||
}
|
||||
|
||||
|
|
|
@ -83,6 +83,32 @@ export default function ({ getService }) {
|
|||
});
|
||||
});
|
||||
|
||||
it('can resume after reindexing was stopped right after creating the new index', async () => {
|
||||
await esArchiver.load('x-pack/test/functional/es_archives/upgrade_assistant/reindex');
|
||||
|
||||
// This new index is the new soon to be created reindexed index. We create it
|
||||
// upfront to simulate a situation in which the user restarted kibana half
|
||||
// way through the reindex process and ended up with an extra index.
|
||||
await es.indices.create({ index: 'reindexed-v7-dummydata' });
|
||||
|
||||
const { body } = await supertest
|
||||
.post(`/api/upgrade_assistant/reindex/dummydata`)
|
||||
.set('kbn-xsrf', 'xxx')
|
||||
.expect(200);
|
||||
|
||||
expect(body.indexName).to.equal('dummydata');
|
||||
expect(body.status).to.equal(ReindexStatus.inProgress);
|
||||
|
||||
const lastState = await waitForReindexToComplete('dummydata');
|
||||
expect(lastState.errorMessage).to.equal(null);
|
||||
expect(lastState.status).to.equal(ReindexStatus.completed);
|
||||
|
||||
// Cleanup newly created index
|
||||
await es.indices.delete({
|
||||
index: lastState.newIndexName,
|
||||
});
|
||||
});
|
||||
|
||||
it('should update any aliases', async () => {
|
||||
await esArchiver.load('x-pack/test/functional/es_archives/upgrade_assistant/reindex');
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue