KahaDB index compaction
Maintainer thường phản hồi trong vòng 1 ngày
Đánh giá
Issue này chưa được đánh giá.
Mô tả
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.
- Ngôn ngữ chính
- Java
- Star
- 2.5k
- Fork
- 1.5k
- Merge trung bình
- 21 giờ 38 phút
- Pull request đã merge (30 ngày)
- 81
Chuẩn bị môi trường
Dự án này không cung cấp dev container, Dockerfile hay hướng dẫn đóng góp, nên bạn cần tự thiết lập môi trường: hãy bắt đầu từ README và xem hướng dẫn đóng góp lần đầu của chúng tôi để biết các bước chung.
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của apache/activemq
-
HttpMaxFrameSizeTest.sendOversizedMessageTest() passes silently when maxFrameSize is not enforcedĐang mở
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 90/100
apache/activemq#2706 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Treat socketBufferSize=0 as OS default without logging a warningCó thể đã có người làm @mwashburn2 đã nhận 7 ngày trước. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
Maintainer thường phản hồi trong vòng 1 ngày
-
ServerSessionImpl gets stuck if the WorkManager encounteres a RejectedExecutionExceptionCó thể đã có người làm Có pull request liên kết đang mở hoặc đã được merge. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 67/100
apache/activemq#2647 · 5 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
AmqpMessage.reject() throws "Can't release non-received message." (copy-paste from release())Có thể đã có người làm @dimitribekale đã nhận 6 ngày trước. Đang mở
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 95/100
apache/activemq#2623 · 5 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 74/100
apache/activemq#2558 · 2 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
Tất cả issue của apache/activemq
Issue tương tự
-
[BUG] jackson3 JacksonJsonpMapper(ObjectMapper) fails to deserialize `_source` with "Trailing token" errorCó thể đã có người làm @junyeokk đã nhận hôm nay. Đang mởbug untriaged
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
opensearch-project/opensearch-java#2236 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 67/100
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 62/100
open-learning-exchange/myplanet#18392 ·
Maintainer thường phản hồi trong vòng 2 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
linagora/twake-calendar-side-service#1218 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
[Bug] [Go] Ack returns nil when the server answers with a non-OK statusCó thể đã có người làm @leizhiyuan đã nhận hôm nay. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 84/100
apache/rocketmq-clients#1465 ·
Maintainer thường phản hồi trong vòng 2 ngày