Skip to content

Commit

Permalink
core/region: fix sub tree may not consist with root tree (#8187)
Browse files Browse the repository at this point in the history
ref #7897

core/region: fix the sub tree may not consist of root tree

Signed-off-by: nolouch <[email protected]>
  • Loading branch information
nolouch authored May 18, 2024
1 parent 36a1fa2 commit 6ded6f8
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 @@ -1044,10 +1044,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 @@ -1072,3 +1072,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 6ded6f8

Please sign in to comment.