Skip to content
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

Improve GC for deactivated client's nodes #926

Merged
merged 11 commits into from
Nov 20, 2024
19 changes: 18 additions & 1 deletion packages/sdk/src/document/time/version_vector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,21 @@ export class VersionVector {
return max;
}

/**
* `minLamport` returns min lamport value from vector
*/
public minLamport(): bigint {
// 2^63 -1 (in64 max)
let min = 9223372036854775807n;

for (const [, lamport] of this) {
if (lamport < min) {
min = lamport;
}
}
return min;
}

/**
* `max` returns new version vector which consists of max value of each vector
*/
Expand Down Expand Up @@ -96,7 +111,9 @@ export class VersionVector {
const lamport = this.vector.get(other.getActorID());

if (lamport === undefined) {
return false;
const minLamport = this.minLamport();

return !!minLamport && minLamport > other.getLamport();
hackerwins marked this conversation as resolved.
Show resolved Hide resolved
}

return lamport >= other.getLamport();
Expand Down
Loading
Loading