feat: 增强index clear()方法 #2
Open
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
本次提交对 Index 接口及其主要实现类进行了功能扩展,旨在提供更灵活的索引条目管理与访问能力。
主要变更:
接口增强 (Index.java)
新增 forEach(EntryConsumer action) 方法:支持遍历索引中的所有条目。
新增 clear(EntryConsumer action) 方法:支持在清空索引时,对每一个被移除的条目执行回调操作(如释放对应的堆外内存)。
实现类适配
更新了以下实现类以支持新接口方法,并确保了并发场景下的线程安全(主要涉及读写锁的使用):
目的
此次修改允许上层调用者在索引清理或统计时直接访问底层的 Entry 信息(如内存地址 address 和大小 size)。这对于需要精细化管理堆外内存(Off-Heap Memory)的场景尤为重要,可以确保在索引条目被移除时,关联的资源能被正确释放。