Skip to content

Commit

Permalink
core/region: fix the put sub tree may not consist with root tree
Browse files Browse the repository at this point in the history
Signed-off-by: nolouch <[email protected]>
  • Loading branch information
nolouch committed May 17, 2024
1 parent 644e904 commit 2274c1a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
6 changes: 3 additions & 3 deletions pkg/core/region.go
Original file line number Diff line number Diff line change
Expand Up @@ -1041,10 +1041,10 @@ func (r *RegionsInfo) CheckAndPutRootTree(ctx *MetaProcessContext, region *Regio
// Usually used with CheckAndPutRootTree together.
func (r *RegionsInfo) CheckAndPutSubTree(region *RegionInfo) {
// new region get from root tree again
var newRegion *RegionInfo
newRegion = r.GetRegion(region.GetID())
newRegion := r.GetRegion(region.GetID())
if newRegion == nil {
newRegion = region
// Make sure there is this region in the root tree, so as to ensure the correctness of reference count
return
}
r.UpdateSubTreeOrderInsensitive(newRegion)
}
Expand Down
9 changes: 9 additions & 0 deletions pkg/core/region_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1021,3 +1021,12 @@ func TestUpdateRegionEventualConsistency(t *testing.T) {
re.Equal(int32(2), item.GetRef())
}
}

func TestCheckAndPutSubTree(t *testing.T) {
re := require.New(t)
regions := NewRegionsInfo()
region := NewTestRegionInfo(1, 1, []byte("a"), []byte("b"))
regions.CheckAndPutSubTree(region)
// should failed to put because the root tree is missing
re.Equal(0, regions.tree.length())
}

0 comments on commit 2274c1a

Please sign in to comment.