Repository navigation
Conversation
|
Workflow [PR], commit [caa4f39] Summary: ✅
AI ReviewSummaryThis PR adds a standalone LSM-style Keeper storage implementation: serialized node blocks, memtables, sorted runs, background flush/merge workers, and white-box unit tests. The main design looks coherent, but I do not think it is ready to merge yet because one new failure-path issue still turns semantic validation errors into Missing context / blind spots
Findings
Tests
Final VerdictNot ready. The abort-on-exception path in |
|
Interesting! Just out of curiosity, what's the motivation and design for the new storage? If it's an LSM tree it sounds maybe similar to RocksDB? How does it compare? |
|
(EDIT: Old comment, read PR summary instead.) Why does everyone monitor draft PRs lol. The main idea is: serialized znode can be much more compact than fixed-size in-memory structs, especially if a group of znodes is serialized together. Paths can be delta-compressed, stats (zxids, times, versions, etc) can be delta-compressed + group-varinted. E.g. znode version is usually 0; it takes 4 bytes in fixed-size struct, but can take 0.25 bytes in group varint; and paths have very long common prefixes (on average only ~1/5 of a path is the last component, see tool output in #106270 summary). The deltas can be relative to block header, so that we can deserialize any one node on demand if we have a pointer to the block and the node's offset inside the block. We can have a hash map of all the nodes, but values would point to block+offset instead of a fixed-size struct. Reading a node is just one hashmap lookup and ~4 group varint decodes. So performance can be on par with current in-memory storage, with much less memory usage. But if nodes can only be appended to blocks, we need some kind of background cleanup. Iterate over nodes in all blocks, skip obsolete ones, produce new blocks, delete old blocks; somehow synchronize all that with readers and don't block readers too much. I couldn't come up with such cleanup scheme that's good and much simpler than a full blown LSM tree. And a full blown LSM tree has benefits: can store blocks on disk, paths compress better because of sorting, memory usage mostly independent of dataset size (except for the big hashmap with pointers to all nodes; but we can later turn that map into a cache, falling back to rocksdb-like lookup in all memtables and files). Background flushes and merges should be almost free because keeper server only uses a few cpu cores, there are lots of free cores to do background work (though they would eat into memory bandwidth). So I think it makes sense to do a full-blown LSM tree. Seems easy enough. I don't think rocksdb can get close to this performance, at least without heroic customizations and tuning. Its lookup checks all memtables, then all files (I'm guessing in keeper we often read znodes that weren't recently written, so would miss memtables? idk). Memtable is a skiplist by default, with pretty slow lookup; but a custom memtable type can be plugged in, we could implement a memtable with hashmap + children sets. In a file, lookup is binary search in the list of blocks, then lookup of the block in block cache, then binary search inside the block. We wouldn't be able to delta-compress stats relative to block header (but paths would be delta compressed sequentially, rocksdb does that for keys). (And we'd generally have less control, it would be harder to change things, there'd be much more code to dig through.) |
dcdb90a to
168eb6f
Compare
antonio2368
left a comment
There was a problem hiding this comment.
Interesting but complex. I understood the changes, but I will probably understand things better once I see how everything will be integrated.
LLVM Coverage Report
Changed lines: Changed C/C++ lines covered: 1357/1594 (85.13%) · Uncovered code |
Changelog category (leave one):
LSM tree, a little similar to rocksdb but specialized and more efficient.
In this PR it's just some dead code in a separate directory, not integrated with keeper. But I have integration implemented and working, it's coming in a separate PR (#108583 , then another smaller one). Early benchmarks say this is 10% faster than the current memory storage.
Explanation (half copied from a github comment in this PR):
The main idea is: serialized znode can be much more compact than fixed-size in-memory structs, especially if a group of znodes is serialized together. Paths can be delta-compressed, stats (zxids, times, versions, etc) can be delta-compressed + group-varinted. E.g. znode version is usually 0; it takes 4 bytes in fixed-size struct, but can take 0.25 bytes in group varint; and paths have very long common prefixes (on average only ~1/5 of a path is the last component, see tool output in #106270 summary). The deltas can be relative to block header, so that we can deserialize any one node on demand if we have a pointer to the block and the node's offset inside the block. See
Node.h/Node.cppfor full serialization.We can have a hash map that maps node path hash (16 bytes) to block+offset where the serialized node lives. Then we can efficiently (~4 group varint decodes) deserialize the node on demand when executing requests. So performance should be on par with current in-memory storage, with much (?) less memory usage.
But if nodes can only be appended to blocks and can't be overwritten or removed, we need some kind of background cleanup. Maybe periodically iterate over nodes in all blocks, skip obsolete ones, write survivors to new blocks, then delete old blocks? Somehow synchronize all that with readers and don't block readers too much? I couldn't come up with such cleanup scheme that's good and much simpler than a full blown LSM tree. So I was tempted to just do a full blown LSM tree. It has its benefits: can store blocks on disk, paths compress better because of sorting, memory usage mostly independent of dataset size (except for the big hashmap with pointers to all nodes; but we can later turn that map into a cache, falling back to rocksdb-like lookup in all memtables and files). Background flushes and merges should be almost free because keeper server only uses a few cpu cores, there are lots of free cores to do background work (though they would eat into memory bandwidth). So I think it makes sense to do a full-blown LSM tree. Seems easy enough.
(I don't think rocksdb can get close to this performance, at least without heroic customizations and tuning. Its lookup checks all memtables, then all files (I'm guessing in keeper we often read znodes that weren't recently written, so would miss memtables? idk). Memtable is a skiplist by default, with pretty slow lookup; but a custom memtable type can be plugged in, we could implement a memtable with hashmap + children sets. In a file, lookup is binary search in the list of blocks, then lookup of the block in block cache, then binary search inside the block. We wouldn't be able to delta-compress stats relative to block header (but paths would be delta compressed sequentially, rocksdb does that for keys). And we'd generally have less control, it would be harder to change things, there'd be much more code to dig through.)
This PR has all the things needed to work: block format, memtables, sorted runs, background flushes (writing memtable to files) and merges, node hashmap, block cache (currently unused). But only has memory-only mode, doesn't write to files. The hope is that even in memory-only mode it'll use less memory than the current memory storage. (But early tests showed higher memory usage, I haven't investigated yet. Maybe this is all wrong, and this writeup will look stupid in hindsight :) )
Implemented a weird but probably important merge feature I haven't seen before: the merge deallocates consumed input blocks on the fly. So a big merge shouldn't cause a 2x spike in memory usage when it already wrote most of the output but didn't delete the inputs yet. It publishes the partial output and truncates the inputs as it goes. For that, each sorted run is stored in a series of files (with disjoint key ranges) instead of one file; merge publishes finished output files and evicts fully consumed input files from memory (probably won't need to delete them from disk until the merge is finished, space usage is not so important). I always wondered why LSM implementations don't do that. (Yes, the standard approach is level-based/tier-based compaction, but it has bad write amplification, IIUC. Which probably wouldn't matter much here. But I wanted to try this other approach anyway, hope it's ok.)
Version info
26.8.1.571(included in26.8and later)