Fix elastic restore (#1038)

Signed-off-by: Andrey Sobolev <haiodo@gmail.com>
This commit is contained in:
Andrey Sobolev 2022-02-22 16:09:43 +07:00 committed by GitHub
parent d8de94da59
commit 2691ac930e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -195,6 +195,7 @@ async function restoreElastic (mongoUrl: string, dbName: string, minio: Client,
const isCollectionCreateTx = (tx: Tx): boolean => tx._class === core.class.TxCollectionCUD && (tx as TxCollectionCUD<Doc, AttachedDoc>).tx._class === core.class.TxCreateDoc
const tdata = data.filter(tx => isCreateTx(tx) || isMixinTx(tx) || isCollectionCreateTx(tx))
const removedDocument = new Set<Ref<Doc>>()
for (const tx of tdata) {
pos++
if (pos % 5000 === 0) {
@ -219,12 +220,27 @@ async function restoreElastic (mongoUrl: string, dbName: string, minio: Client,
} catch (err: any) {
console.error('failed to replay tx', tx, err.message)
}
} else {
removedDocument.add(createTx.objectId)
}
}
// We need process mixins.
if (isMixinTx(tx)) {
await tool.storage.tx(metricsCtx, tx)
try {
let deleted = false
if (tx._class === core.class.TxMixin) {
deleted = removedDocument.has((tx as TxMixin<Doc, Doc>).objectId)
}
if (tx._class === core.class.TxCollectionCUD && (tx as TxCollectionCUD<Doc, AttachedDoc>).tx._class === core.class.TxMixin) {
deleted = removedDocument.has((tx as TxCollectionCUD<Doc, AttachedDoc>).tx.objectId)
}
if (!deleted) {
await tool.storage.tx(metricsCtx, tx)
}
} catch (err: any) {
console.error('failed to replay tx', tx, err.message)
}
}
// We need process collection creations.
@ -273,6 +289,7 @@ async function restoreElastic (mongoUrl: string, dbName: string, minio: Client,
console.log('replay elastic transactions done')
console.log(metricsToString(m))
} finally {
console.log('Elastic restore done')
await done()
}
}