mirror of
https://github.com/versity/scoutfs.git
synced 2026-02-11 04:51:08 +00:00
This is the first draft of compaction which has the core mechanics. Add segment functions to free a segment's segno and to delete the entry that refers to the given segment. Add manifest functions that lock the manifest and dirty and delete manifest entries. These are used by the compaction thread to atomically modify the manfiest with the result of a compaction. Sort the level 0 entries in the manifest by their sequence. This lets compaction use the first oldest entry and reading can walk them backwards to get them in order and not have to sort. We also more carefully use the sequence field in the manifest search key to differentiate between finding high level entries that overlap and finding specific entries identified by their seq. Add some fields to the per-super compact_info struct which support compaction. We need to know the limit on the number of segments per level and we record keys per level which tell us which segment to use next time that level is compacted. We kick a compaction thread when we add a manifest entry and that brings the level count over the limit. scoutfs_manifest_next_compact() is the first meaty function. The compaction thread uses this to get all the segments involved in a compaction. It does a quick manifest update if the next manifest candidate doesn't overlap with any sgements in the next level. The compaction operation itself is a pretty straight forward read-modify-write operation. It asks the manifest to give it references to the segments it'll need, reads them in, iterates over them to count and copies items in order to output segments, and atomically updates the manifest. Now that the manifest can be dirty without any dirty segments we need to fix the transaction writing function's assumption that everything flows from dirty segments. It also has to now lock and unlock the manifest as it adds the entry for its level 0 segment. Signed-off-by: Zach Brown <zab@versity.com>