mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-27 02:42:25 +08:00
fix(server): deal with unexpected updates (#4064)
This commit is contained in:
@@ -67,8 +67,17 @@ export class DocManager implements OnModuleInit, OnModuleDestroy {
|
|||||||
protected recoverDoc(...updates: Buffer[]): Doc {
|
protected recoverDoc(...updates: Buffer[]): Doc {
|
||||||
const doc = new Doc();
|
const doc = new Doc();
|
||||||
|
|
||||||
updates.forEach(update => {
|
updates.forEach((update, i) => {
|
||||||
applyUpdate(doc, update);
|
try {
|
||||||
|
if (update.length) {
|
||||||
|
applyUpdate(doc, update);
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
this.logger.error(
|
||||||
|
`Failed to apply updates, index: ${i}`,
|
||||||
|
updates.map(u => u.toString('hex'))
|
||||||
|
);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
return doc;
|
return doc;
|
||||||
|
|||||||
@@ -105,6 +105,8 @@ export class RedisDocManager extends DocManager {
|
|||||||
.catch(() => null); // safe;
|
.catch(() => null); // safe;
|
||||||
|
|
||||||
if (!lockResult) {
|
if (!lockResult) {
|
||||||
|
// we failed to acquire the lock, put the pending doc back to queue.
|
||||||
|
await this.redis.sadd(pending, pendingDoc).catch(() => null); // safe
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -141,7 +143,10 @@ export class RedisDocManager extends DocManager {
|
|||||||
this.logger.error('Failed to remove merged updates from Redis', e);
|
this.logger.error('Failed to remove merged updates from Redis', e);
|
||||||
});
|
});
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
this.logger.error('Failed to merge updates with snapshot', e);
|
this.logger.error(
|
||||||
|
`Failed to merge updates with snapshot for ${pendingDoc}`,
|
||||||
|
e
|
||||||
|
);
|
||||||
await this.redis.sadd(pending, `${workspaceId}:${id}`).catch(() => null); // safe
|
await this.redis.sadd(pending, `${workspaceId}:${id}`).catch(() => null); // safe
|
||||||
} finally {
|
} finally {
|
||||||
await this.redis.del(lockKey);
|
await this.redis.del(lockKey);
|
||||||
|
|||||||
@@ -326,13 +326,15 @@ export class WorkspaceResolver {
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
await this.prisma.snapshot.create({
|
if (buffer.length) {
|
||||||
data: {
|
await this.prisma.snapshot.create({
|
||||||
id: workspace.id,
|
data: {
|
||||||
workspaceId: workspace.id,
|
id: workspace.id,
|
||||||
blob: buffer,
|
workspaceId: workspace.id,
|
||||||
},
|
blob: buffer,
|
||||||
});
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
return workspace;
|
return workspace;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user