KahaDB index compaction
维护者通常 1 天内回复
评估
这个 Issue 还没有评估数据。
描述
KahaDB contains two components, he journal and the index. The journal stores all of the data (mesages, acks, metadata, etc) as commands in the journal and the index is used to keep track of where certain things are for quick look up (such as being able to iterate over messages by order or by id). The goal of this issue is to address compacting the index (stored as page files) when large. Journal compaction is a separate issue that will be addressed separately. Inded compaction will be done in two phases, truncation and defrag.
Index usage in KahaDB
The KahaDB index is stored using a PageFile, which is just a contiguous block of pages in a single file. The page file is essentially a big linked list on disk, and writes will be written to as many pages as needed and flushed to disk. Pages can also be cached in memory for fast access.
When updates are written to the index and there isn't enough space, new pages are allocated as necessary which grows the file. When deletes happen pages are just marked as free and reclaimed into a list of free pages. Writing updates to the index first looks to re-use pages that are marked as free and will only allocate new space if needed. Under normal use cases this leads to a pretty stable PageFile size as the amount of pages necessary get allocated.
The need for compaction
Sometimes the PageFile can grow quite large. The most common scenario for this is a large backlog on a destination. A large backlog will cause a lot of extra writes to the index to track all the messages which causes the page file to grow quite large. Once the backlog is gone the pages will be marked as free and reclaimed to be re-used, but the page file itself will never shrink. This can lead to a huge PageFile with a lot of empty space that just isn't necessary.
Compaction via truncation (#2233)
A simple way to help solve this problem is using a truncation compaction strategy. Truncation helps in this scenario by simply truncating the file and removing the excess free pages. This works well because all we need to do is remove the free pages from the tracking and then set the length of the file to the new size which is nearly instant time, so there is no noticeable performance impact.
While this strategy is very fast and easy to implement, the major and obvious limitation to this strategy is it only works if the free pages are at the end of the file. If the free pages are in the middle of the file his won't work so we can't shrink the file. This could happen, for example, if a new destination was created while there was a big backlog and it was written to the index. This means all the eventual free pages that would be reclaimed after the backlog is gone would be in the middle of the file so we could not truncate.
Compaction via defragmentation (Future plans)
The goal here is to address the shortcomings of truncation and there are a few ideas to explore. One way to reclaim space is to just re-write the entire page file and drop free pages but this would be pretty slow. Another idea is to implement defragmentation to move pages and reduce the empty space in the middle of the file so that truncation could work and there are a few ideas to try:
- One option to explore is we re-write/move pages at the end of the file to early free pages. Eventually we will end up with enough free pages at the end of the file and we can truncate again. This is more complex because the page file forms lots of separate linked lists within the page file. We could convert the linked lists to a doubly linked lists so that when we move pages we can update the metadata of the page that points to the page so we don't break the list. This also means it would not be backwards compatible (you'd need to start with a fresh page file) because existing page files don't contain markers for the previous page in the list.
- Another option would be to still move pages to earlier in the file, but add another index that's a virtual page file and a look up table that would likely be stored in a second small page file. It would just be a map that we could use to find the real location of a page based off the stored pageId if it was moved.
- A third option worth exploring is to just rewrite stored destination metadata to earlier in the file and over time truncation would naturally work as backlogs are gone. The main cause of big files (if truncation is enabled) would be data that is permanent like destination data so moving it earlier int he page file could allow cleanup. Stored destination metadata just contains the "first" pages of each of its indexes in the linked list so you don't need to store previous pages (so no doubly linked list). One flaw is that this may not necessarily work as intended though if a destination has a lot of durable subscriptions and they get added later after a big backlog as that would add pages to the index that were not moved.
It's TBD which would work best.
- 主要语言
- Java
- 星标
- 2.5k
- 派生
- 1.5k
- 平均合并
- 23 小时 10 分钟
- 30 天内合并 PR
- 81
环境准备
这个项目没有提供开发容器、Dockerfile 或贡献指南,环境需要你自己搭建:先看它的 README,通用步骤见我们的新手贡献指南。
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
apache/activemq 的其他 Issue
-
Docker entrypoint exits right after forwarding SIGTERM, so the broker is killed before it finishes shutting down可能已有人在做 @tjololo 今天认领。 未关闭
难度 2/5 1-3 小时 新手友好度 78/100
维护者通常 1 天内回复
-
HttpMaxFrameSizeTest.sendOversizedMessageTest() passes silently when maxFrameSize is not enforced可能已有人在做 关联的 PR 仍在进行中或已合并。 未关闭
难度 1/5 1 小时以内 新手友好度 90/100
apache/activemq#2706 · 1 条评论 ·
维护者通常 1 天内回复
-
Treat socketBufferSize=0 as OS default without logging a warning可能已有人在做 @mwashburn2 于 11 天前认领。 未关闭
难度 2/5 1-3 小时 新手友好度 72/100
维护者通常 1 天内回复
-
ServerSessionImpl gets stuck if the WorkManager encounteres a RejectedExecutionException可能已有人在做 关联的 PR 仍在进行中或已合并。 未关闭
难度 2/5 1-3 小时 新手友好度 67/100
apache/activemq#2647 · 5 条评论 ·
维护者通常 1 天内回复
-
AmqpMessage.reject() throws "Can't release non-received message." (copy-paste from release())可能已有人在做 @dimitribekale 于 10 天前认领。 未关闭
难度 1/5 1 小时以内 新手友好度 95/100
apache/activemq#2623 · 5 条评论 ·
维护者通常 1 天内回复
相似的 Issue
-
pending:code-area pending:issue-category to-triage
难度 2/5 1-3 小时 新手友好度 76/100
维护者通常 1 天内回复
-
area:core bug priority:p2
难度 2/5 1-3 小时 新手友好度 82/100
aomarai/minecraft-mcp#247 ·
维护者通常 1 天内回复
-
help wanted
难度 2/5 1-3 小时 新手友好度 68/100
antonyrag/ragleap-core#1062 ·
-
难度 2/5 1-3 小时 新手友好度 76/100
projectnessie/nessie#13256 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 66/100
Vakore/ZappierGames#232 ·