Skip to content

Commit

Permalink
Improve GC for deactivated client's nodes (#926)
Browse files Browse the repository at this point in the history
This change enhances garbage collection logic to handle nodes created by deactivated
clients by introducing a minLamport comparison method. When actor information
is missing from the min version vector, the minimum value is used to determine
node removal.

---------

Co-authored-by: Youngteac Hong <[email protected]>
  • Loading branch information
JOOHOJANG and hackerwins authored Nov 20, 2024
1 parent 966ca89 commit bc21a84
Show file tree
Hide file tree
Showing 3 changed files with 453 additions and 2 deletions.
22 changes: 21 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,26 @@ export class VersionVector {
return max;
}

/**
* `minLamport` returns min lamport value from vector
*/
public minLamport(): bigint {
// TODO(hackerwins): If the version vector is empty, minLamport could be the
// max value of int64. This is because if the last client leaves the
// document, the min version vector becomes empty.
// This is a temporary solution and needs to be fixed later.

// 2^63-1 (int64 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 +116,7 @@ export class VersionVector {
const lamport = this.vector.get(other.getActorID());

if (lamport === undefined) {
return false;
return this.minLamport() > other.getLamport();
}

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

0 comments on commit bc21a84

Please sign in to comment.