[BugFix][RadixTree]: Fix backup invariant violation in Hi-MambaRadixTree (#22062)

Co-authored-by: 晟海 <huangtingwei.htw@antgroup.com>
Co-authored-by: linjianyu77@foxmail.com
This commit is contained in:
Zhangheng
2026-04-05 23:19:50 +08:00
committed by GitHub
co-authored by 晟海
parent dccb11881f
commit 51b276de74
2 changed files with 10 additions and 0 deletions
@@ -277,6 +277,10 @@ class HiMambaRadixCache(MambaRadixCache):
super().reset()
def write_backup(self, node: TreeNode, write_back=False):
# Backup invariant: parent must be backed up before child.
if node.parent != self.root_node and not node.parent.backuped:
return
# If mamba host slot already exists, refresh its LRU position.
if node.mamba_value is not None and node.mamba_host_value is not None:
if self.mamba_host_lru_list.in_list(node):
@@ -608,6 +608,10 @@ class HiRadixCache(RadixCache):
return False
def write_backup(self, node: TreeNode, write_back=False):
# Backup invariant: parent must be backed up before child.
if node.parent != self.root_node and not node.parent.backuped:
return
host_indices = self.cache_controller.write(
device_indices=node.value,
node_id=node.id,
@@ -836,6 +840,8 @@ class HiRadixCache(RadixCache):
def _evict_regular(self, node: TreeNode):
# evict a node not initiated write to host -- emit BlockRemoved
assert len(node.children) == 0, f"non-leaf, {node.id=}"
self._record_remove_event(node)
self.cache_controller.mem_pool_device_allocator.free(node.value)
num_evicted = len(node.value)