Skip to content

Commit

Permalink
feat: update removedAt for deleted nodes during range deletions
Browse files Browse the repository at this point in the history
- Add logic to update `removedAt` for nodes with outdated deletion times
- Ensure that garbage collection accounts for the latest `removedAt` updates
- Maintain existing behavior for local operations while enhancing remote operation consistency
  • Loading branch information
minai621 committed Oct 12, 2024
1 parent 56ba2bb commit b51f82d
Showing 1 changed file with 23 additions and 20 deletions.
43 changes: 23 additions & 20 deletions packages/sdk/src/document/crdt/tree.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,36 +14,36 @@
* limitations under the License.
*/

import { CRDTElement } from '@yorkie-js-sdk/src/document/crdt/element';
import {
TimeTicket,
InitialTimeTicket,
TimeTicketStruct,
MaxTimeTicket,
TimeTicket,
TimeTicketStruct,
} from '@yorkie-js-sdk/src/document/time/ticket';
import { CRDTElement } from '@yorkie-js-sdk/src/document/crdt/element';

import type * as Devtools from '@yorkie-js-sdk/src/devtools/types';
import { GCChild, GCPair, GCParent } from '@yorkie-js-sdk/src/document/crdt/gc';
import { Indexable } from '@yorkie-js-sdk/src/document/document';
import { escapeString } from '@yorkie-js-sdk/src/document/json/strings';
import { Comparator } from '@yorkie-js-sdk/src/util/comparator';
import { Code, YorkieError } from '@yorkie-js-sdk/src/util/error';
import type {
DefaultTextType,
TreeNodeType,
TreeToken,
} from '@yorkie-js-sdk/src/util/index_tree';
import {
IndexTree,
TreePos,
IndexTreeNode,
traverseAll,
TokenType,
TreePos,
traverseAll,
} from '@yorkie-js-sdk/src/util/index_tree';
import { RHT, RHTNode } from './rht';
import { ActorID } from './../time/actor_id';
import { LLRBTree } from '@yorkie-js-sdk/src/util/llrb_tree';
import { Comparator } from '@yorkie-js-sdk/src/util/comparator';
import { parseObjectValues } from '@yorkie-js-sdk/src/util/object';
import type {
DefaultTextType,
TreeNodeType,
TreeToken,
} from '@yorkie-js-sdk/src/util/index_tree';
import { Indexable } from '@yorkie-js-sdk/src/document/document';
import type * as Devtools from '@yorkie-js-sdk/src/devtools/types';
import { escapeString } from '@yorkie-js-sdk/src/document/json/strings';
import { GCChild, GCPair, GCParent } from '@yorkie-js-sdk/src/document/crdt/gc';
import { Code, YorkieError } from '@yorkie-js-sdk/src/util/error';
import { ActorID } from './../time/actor_id';
import { RHT, RHTNode } from './rht';

/**
* `TreeNode` represents a node in the tree.
Expand Down Expand Up @@ -1094,6 +1094,9 @@ export class CRDTTree extends CRDTElement implements GCParent {
nodesToBeRemoved.push(node);
}
tokensToBeRemoved.push([node, tokenType]);
} else if (node.isRemoved && editedAt.after(node.removedAt!)) {
node.removedAt = editedAt;
pairs.push({ parent: this, child: node });
}
},
);
Expand Down Expand Up @@ -1371,8 +1374,8 @@ export class CRDTTree extends CRDTElement implements GCParent {
const treePos = node.isText
? { node, offset: 0 }
: parentNode && leftChildNode
? this.toTreePos(parentNode, leftChildNode)
: null;
? this.toTreePos(parentNode, leftChildNode)
: null;

if (treePos) {
index = this.indexTree.indexOf(treePos);
Expand Down

0 comments on commit b51f82d

Please sign in to comment.