fix: 二道防线(服务器行数少于镜像即判定数据丢失,自动全量重推自救,首次升级即可生效) + 灾难恢复冒烟7项
This commit is contained in:
@@ -373,6 +373,16 @@ async function doRunSync(config: SyncConfig, epochRetry = false): Promise<SyncRe
|
||||
const serverTables: Record<string, AnyRow[]> = data.tables || {}
|
||||
const serverTombstones: { table: string; uuid: string; deleted_at: string }[] = data.tombstones || []
|
||||
|
||||
// 二道防线(不依赖纪元存储,首次升级即可生效):
|
||||
// 本地镜像认为服务器应有 N 行,但服务器实际行数更少 —— 说明服务器数据发生过丢失/重建。
|
||||
// 此时若照常拉快照,会把本地缓存也清空。处置:作废镜像并以本地全量数据重推自救。
|
||||
const serverCount = TABLES.reduce((s, tn) => s + ((serverTables[tn] || []).length), 0)
|
||||
const expectedMin = mirrorRows.length - tombstones.length
|
||||
if (!epochRetry && serverCount < expectedMin) {
|
||||
await db.sync_mirror.clear()
|
||||
return doRunSync(config, true)
|
||||
}
|
||||
|
||||
// 3. 用服务器快照全量重建本地缓存(本地不再有映射逻辑,服务器永远是对的)
|
||||
const applyResult = await applySnapshot(serverTables, serverTombstones)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user