UBERF-6557: Clean old domains during clone of workspace to new place (#5361)

Signed-off-by: Andrey Sobolev <haiodo@gmail.com>
This commit is contained in:
Andrey Sobolev 2024-04-15 16:11:53 +07:00 committed by GitHub
parent cd696ec845
commit 04bb873191
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -287,6 +287,9 @@ export async function cloneWorkspace (
console.log('Retrieve chunk:', needRetrieve.length)
let docs: Doc[] = []
try {
// We need to clean target connection before copying something.
await cleanDomain(targetConnection, c)
docs = await sourceConnection.loadDocs(c, needRetrieve)
if (clearTime) {
docs = docs.map((p) => {
@ -337,6 +340,32 @@ export async function cloneWorkspace (
}
}
async function cleanDomain (connection: CoreClient & BackupClient, domain: Domain): Promise<void> {
// Load all digest from collection.
let idx: number | undefined
const ids: Ref<Doc>[] = []
while (true) {
try {
const it = await connection.loadChunk(domain, idx)
idx = it.idx
ids.push(...it.docs.map((it) => it.id as Ref<Doc>))
if (it.finished) {
break
}
} catch (err: any) {
console.error(err)
if (idx !== undefined) {
await connection.closeChunk(idx)
}
}
}
while (ids.length > 0) {
const part = ids.splice(0, 5000)
await connection.clean(domain, part)
}
}
/**
* @public
*/