mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-13 04:48:53 +00: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 {
|
||||
const doc = new Doc();
|
||||
|
||||
updates.forEach(update => {
|
||||
applyUpdate(doc, update);
|
||||
updates.forEach((update, i) => {
|
||||
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;
|
||||
|
||||
@@ -105,6 +105,8 @@ export class RedisDocManager extends DocManager {
|
||||
.catch(() => null); // safe;
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -141,7 +143,10 @@ export class RedisDocManager extends DocManager {
|
||||
this.logger.error('Failed to remove merged updates from Redis', 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
|
||||
} finally {
|
||||
await this.redis.del(lockKey);
|
||||
|
||||
@@ -326,13 +326,15 @@ export class WorkspaceResolver {
|
||||
},
|
||||
});
|
||||
|
||||
await this.prisma.snapshot.create({
|
||||
data: {
|
||||
id: workspace.id,
|
||||
workspaceId: workspace.id,
|
||||
blob: buffer,
|
||||
},
|
||||
});
|
||||
if (buffer.length) {
|
||||
await this.prisma.snapshot.create({
|
||||
data: {
|
||||
id: workspace.id,
|
||||
workspaceId: workspace.id,
|
||||
blob: buffer,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
return workspace;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user