-
-
Notifications
You must be signed in to change notification settings - Fork 145
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
getGarbageLen()
does not match the actual number of elements for garbage collection
#688
Comments
@devleejb Yes. The For instance, you can also consider the following test case: it.only('gc-test', async function ({ task }) {
type TestDoc = { point?: { x?: number; y?: number } };
const docKey = toDocKey(`${task.name}-${new Date().getTime()}`);
const doc1 = new yorkie.Document<TestDoc>(docKey);
const doc2 = new yorkie.Document<TestDoc>(docKey);
const client1 = new yorkie.Client(testRPCAddr);
const client2 = new yorkie.Client(testRPCAddr);
await client1.activate();
await client2.activate();
// 1. initial state
await client1.attach(doc1, { isRealtimeSync: false });
doc1.update((root) => (root.point = { x: 0, y: 0 }));
await client1.sync();
await client2.attach(doc2, { isRealtimeSync: false });
// 2. client1 updates doc
doc1.update((root) => {
delete root.point;
});
assert.equal(doc1.getGarbageLen(), 3); // point, x, y
// 3. client2 updates doc
doc2.update((root) => {
delete root.point?.x;
});
assert.equal(doc2.getGarbageLen(), 1); // x
await client1.sync();
await client2.sync();
await client1.sync();
// 4. getGarbageLen() should be 3.
assert.equal(doc1.getGarbageLen(), 4); // point, x, y, x
assert.equal(doc2.getGarbageLen(), 4); // x, point, x, y
// Actual garbage-collected nodes
assert.equal(doc1.garbageCollect(MaxTimeTicket), 3); // point, x, y
assert.equal(doc2.garbageCollect(MaxTimeTicket), 3); // point, x, y
await client1.deactivate();
await client2.deactivate();
}); |
@chacha912 I will make the modification in the direction of eliminating duplicate counting when calling Additionally, I considered not adding duplicates to |
@devleejb, I agree that avoiding adding duplicates to the |
@chacha912 |
What happened:
The
getGarbageLen()
function iterates through elements inroot.removedElementSetByCreatedAt
, counting the descendants' numbers. This causes elements to be counted multiple times, leading to a difference between the count provided bygetGarbageLen()
and the actual number of elements being garbage collected.What you expected to happen:
The counts by
getGarbageLen()
and the actual number of elements being garbage collected should match.How to reproduce it (as minimally and precisely as possible):
Execute the following test code in the yorkie-js-sdk:
Anything else we need to know?:
Environment:
yorkie version
): v0.4.8The text was updated successfully, but these errors were encountered: