yorkie-team/yorkie

When generate NewRoot from snapshot, GC doesn't work properly on tree and text.

highcloud100 opened this issue · 1 comments

What happened:

When generate NewRoot from pulled snapshot, GC doesn't work properly on tree and text.

What you expected to happen:

When NewRoot conducting, it doesn't register the removed
tree and text elements to elementHasRemovedNodesSetByCreatedAt.
So GrabageCollect misses removing trees and text elements.

Moreover need to check the root pulled from snapshot has right removedNodeMap in rgaTreeSplit.

How to reproduce it (as minimally and precisely as possible):

t.Run("garbage collection for text with snapshot", func(t *testing.T) {
		ctx := context.Background()
		d1 := document.New(helper.TestDocKey(t))
		err := c1.Attach(ctx, d1)
		assert.NoError(t, err)

		d2 := document.New(helper.TestDocKey(t))
		err = c2.Attach(ctx, d2)
		assert.NoError(t, err)

		err = d1.Update(func(root *json.Object, p *presence.Presence) error {
			root.SetNewText("text").
				Edit(0, 0, "Hello world")
			root.GetText("text").Edit(0, 3, "kkk")
			return nil
		}, "sets test text")
		assert.NoError(t, err)

		for i := 0; i <= int(helper.SnapshotThreshold)-2; i++ {
			err := d1.Update(func(root *json.Object, p *presence.Presence) error {
				root.SetInteger(fmt.Sprintf("Padding %d", i), i)
				return nil
			})
			assert.NoError(t, err)
		}

		err = c1.Sync(ctx)
		assert.NoError(t, err)
		err = c2.Sync(ctx)
		assert.NoError(t, err)
                
                //[{"val":"kkk"},{"val":"lo world"}]
		assert.Equal(t, 1, d1.GarbageLen()) // {"val" : "Hel"}
		assert.Equal(t, 1, d1.GarbageCollect(time.MaxTicket))

		assert.Equal(t, 1, d2.GarbageLen()) // GarbageLen return 0 for the present
		assert.Equal(t, 1, d2.GarbageCollect(time.MaxTicket)) // GarbageCollect return 0 for the present
	})

image

After GC for d2, d2 still has a 'hel'

Anything else we need to know?:

Environment:

  • Operating system: window10
  • Browser and version:
  • Yorkie version (use yorkie version): 0.4.12
  • Yorkie JS SDK version: