Skip to content

Commit

Permalink
Apply GCPair to TreeNode
Browse files Browse the repository at this point in the history
  • Loading branch information
hackerwins committed May 17, 2024
1 parent bd46419 commit 80c614c
Show file tree
Hide file tree
Showing 12 changed files with 424 additions and 377 deletions.
3 changes: 2 additions & 1 deletion api/converter/from_pb.go
Original file line number Diff line number Diff line change
Expand Up @@ -658,10 +658,11 @@ func fromTreeNode(pbNode *api.TreeNode) (*crdt.TreeNode, error) {
}
}

node.RemovedAt, err = fromTimeTicket(pbNode.RemovedAt)
removedAt, err := fromTimeTicket(pbNode.RemovedAt)
if err != nil {
return nil, err
}
node.SetRemovedAt(removedAt)

return node, nil
}
Expand Down
4 changes: 2 additions & 2 deletions api/converter/to_bytes.go
Original file line number Diff line number Diff line change
Expand Up @@ -310,10 +310,10 @@ func toTreeNode(treeNode *crdt.TreeNode, depth int) *api.TreeNode {
}

pbNode := &api.TreeNode{
Id: toTreeNodeID(treeNode.ID),
Id: toTreeNodeID(treeNode.ID()),
Type: treeNode.Type(),
Value: treeNode.Value,
RemovedAt: ToTimeTicket(treeNode.RemovedAt),
RemovedAt: ToTimeTicket(treeNode.RemovedAt()),
Depth: int32(depth),
Attributes: attrs,
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/document/crdt/gc.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,6 @@ type GCParent interface {

// GCChild is an interface for the child of the garbage collection target.
type GCChild interface {
ID() string
IDString() string
RemovedAt() *time.Ticket
}
4 changes: 2 additions & 2 deletions pkg/document/crdt/rht.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func newRHTNode(key, val string, updatedAt *time.Ticket, isRemoved bool) *RHTNod
}

// ID returns the ID of this node.

Check failure on line 44 in pkg/document/crdt/rht.go

View workflow job for this annotation

GitHub Actions / build

exported: comment on exported method RHTNode.IDString should be of the form "IDString ..." (revive)
func (n *RHTNode) ID() string {
func (n *RHTNode) IDString() string {
return n.updatedAt.Key() + ":" + n.key
}

Expand Down Expand Up @@ -231,7 +231,7 @@ func (rht *RHT) Marshal() string {

// Purge purges the given child node.
func (rht *RHT) Purge(child *RHTNode) error {
if node, ok := rht.nodeMapByKey[child.key]; !ok || node.ID() != child.ID() {
if node, ok := rht.nodeMapByKey[child.key]; !ok || node.IDString() != child.IDString() {
//return ErrChildNotFound
return nil
}
Expand Down
8 changes: 4 additions & 4 deletions pkg/document/crdt/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ func (r *Root) GarbageCollect(ticket *time.Ticket) (int, error) {
return 0, err
}

delete(r.gcPairMapByID, pair.Child.ID())
delete(r.gcPairMapByID, pair.Child.IDString())
count++
}
}
Expand Down Expand Up @@ -219,10 +219,10 @@ func (r *Root) GarbageLen() int {

// RegisterGCPair registers the given pair to hash table.
func (r *Root) RegisterGCPair(pair GCPair) {
if _, ok := r.gcPairMapByID[pair.Child.ID()]; ok {
delete(r.gcPairMapByID, pair.Child.ID())
if _, ok := r.gcPairMapByID[pair.Child.IDString()]; ok {
delete(r.gcPairMapByID, pair.Child.IDString())
return
}

r.gcPairMapByID[pair.Child.ID()] = pair
r.gcPairMapByID[pair.Child.IDString()] = pair
}
Loading

0 comments on commit 80c614c

Please sign in to comment.