mirror of
https://github.com/hcengineering/platform.git
synced 2026-08-17 18:05:42 +02:00
Handle indexer init mapping errors (#9577)
* Retry initMapping for FulltextAdapter Signed-off-by: Nikolay Marchuk <nikolay.marchuk@hardcoreeng.com> * Recreate elastic index when mapping is not compatible Signed-off-by: Nikolay Marchuk <nikolay.marchuk@hardcoreeng.com> * Fix formatting Signed-off-by: Nikolay Marchuk <nikolay.marchuk@hardcoreeng.com> --------- Signed-off-by: Nikolay Marchuk <nikolay.marchuk@hardcoreeng.com>
This commit is contained in:
@@ -92,7 +92,14 @@ export class WorkspaceManager {
|
||||
)
|
||||
this.fulltextAdapter = await this.opt.config.fulltextAdapter.factory(this.opt.config.fulltextAdapter.url)
|
||||
|
||||
await this.fulltextAdapter.initMapping(this.ctx)
|
||||
let adapterInitialized = false
|
||||
while (!adapterInitialized) {
|
||||
adapterInitialized = await this.fulltextAdapter.initMapping(this.ctx)
|
||||
if (!adapterInitialized) {
|
||||
this.ctx.warn('Failed to initialize indexer mapping, retrying in 5 s')
|
||||
await new Promise((resolve) => setTimeout(resolve, 5000))
|
||||
}
|
||||
}
|
||||
|
||||
this.shutdownInterval = setInterval(() => {
|
||||
for (const [k, v] of [...this.indexers.entries()]) {
|
||||
|
||||
@@ -127,15 +127,29 @@ class ElasticAdapter implements FullTextAdapter {
|
||||
)
|
||||
const allIndexes = Object.keys(existingVersions.body)
|
||||
const existingOldVersionIndices = allIndexes.filter((name) => name !== indexName)
|
||||
if (existingOldVersionIndices.length > 0) {
|
||||
const existsIndex = allIndexes.find((it) => it === indexName) !== undefined
|
||||
let shouldDropExistingIndex = false
|
||||
if (existsIndex) {
|
||||
const mapping = await ctx.with('get-mapping', { indexName }, () =>
|
||||
this.client.indices.getMapping({
|
||||
index: indexName
|
||||
})
|
||||
)
|
||||
for (const [propName, propType] of Object.entries(mappings.properties)) {
|
||||
if (mapping.body[indexName]?.mappings.properties?.[propName]?.type !== propType.type) {
|
||||
shouldDropExistingIndex = true
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
if (existingOldVersionIndices.length > 0 || shouldDropExistingIndex) {
|
||||
await ctx.with('delete-old-index', {}, () =>
|
||||
this.client.indices.delete({
|
||||
index: existingOldVersionIndices
|
||||
index: shouldDropExistingIndex ? allIndexes : existingOldVersionIndices
|
||||
})
|
||||
)
|
||||
}
|
||||
const existsIndex = allIndexes.find((it) => it === indexName) !== undefined
|
||||
if (!existsIndex) {
|
||||
if (!existsIndex || shouldDropExistingIndex) {
|
||||
await ctx.with('create-index', { indexName }, () =>
|
||||
this.client.indices.create({
|
||||
index: indexName,
|
||||
|
||||
Reference in New Issue
Block a user