feat: updates to btree/index/query/sstable/table

This commit is contained in:
2025-10-11 13:19:26 +08:00
parent c8cbe4178f
commit 03ec262ca5
7 changed files with 1229 additions and 54 deletions

View File

@@ -274,6 +274,46 @@ func (idx *SecondaryIndex) GetMetadata() IndexMetadata {
return idx.metadata
}
// ForEach 升序迭代所有索引条目
// callback 返回 false 时停止迭代,支持提前终止
// 注意只能迭代已持久化的数据B+Tree不包括内存中未持久化的数据
func (idx *SecondaryIndex) ForEach(callback IndexEntryCallback) error {
idx.mu.RLock()
defer idx.mu.RUnlock()
if !idx.ready {
return fmt.Errorf("index not ready")
}
// 只支持 B+Tree 格式的索引
if !idx.useBTree || idx.btreeReader == nil {
return fmt.Errorf("ForEach only supports B+Tree format indexes")
}
idx.btreeReader.ForEach(callback)
return nil
}
// ForEachDesc 降序迭代所有索引条目
// callback 返回 false 时停止迭代,支持提前终止
// 注意只能迭代已持久化的数据B+Tree不包括内存中未持久化的数据
func (idx *SecondaryIndex) ForEachDesc(callback IndexEntryCallback) error {
idx.mu.RLock()
defer idx.mu.RUnlock()
if !idx.ready {
return fmt.Errorf("index not ready")
}
// 只支持 B+Tree 格式的索引
if !idx.useBTree || idx.btreeReader == nil {
return fmt.Errorf("ForEachDesc only supports B+Tree format indexes")
}
idx.btreeReader.ForEachDesc(callback)
return nil
}
// NeedsUpdate 检查是否需要更新
func (idx *SecondaryIndex) NeedsUpdate(currentMaxSeq int64) bool {
idx.mu.RLock()