Repository navigation
Rewrite rocksdb backend to meet the kv contract - #2
Merged
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Lane K of task-161. The rocksdb backend now meets the kv contract (§1-4): serializable transactions, real snapshots, typed retryable errors, and lock waits that never stall the event loop.
Depends on rdbpy 0.3.0 (nustackdev/rdbpy#1). The pin is
rdbpython>=0.3,<0.4, which is not on PyPI yet, so rdbpy has to release before this merges.What changed
begin_transactionto commit or abort. It is exposed throughareserve_write_slotandbegin_transaction(write_slot=), the same pair sqlite has, so nustd picks it up with no changes. Write batches take the slot too. The slot module and the nested-transaction error are byte-identical to lane C's commits (caa5110, bc498e0), so the merge is clean.Snapshotis a realdb.snapshot()view. Scans use the new bounded batched iterators.StorageTransactionConflictError. TimedOut and LockLimit map toStorageLockTimeoutError. There is no more message-string matching. A nested transaction or batch raisesStorageNestedTransactionError.process_model = "single". Use from a forked child raises.close()while another thread has a call in flight now raises and leaves state intact; before, it segfaulted. A forked child no longer hangs on close whendisable_wal=True.rocksdb(what nustd presets use) is now the serial variant.RocksDBSerialStorageis exported as an alias. No optimistic variant: it would need its own scanned-range validation.Why
Before this change the backend was read-committed with write locks. Snapshots were ignored, write skew and phantoms were possible, and a contended lock blocked the event loop for the full 1s timeout per retry: 10 concurrent incs on one key took 42s.
Testing
pytest tests/conformance -k rocksdb: 27 passed, 2 skipped (multi-process cases), 1 xfail (dict-delete row, owned by lane B). With lane C's file as is, all 15 rocksdb known-failure ids XPASS(strict), so lane C should delete those 13 rows at merge. Soak run (50 rounds) gives the same.tests/_backends/storages/test_rocksdb_contract.py: 38 tests (write skew, insert race on scan, lost update, repeatable and untorn snapshots, nested error, error classes, event loop not stalled, close paths).nustd_rmw.py rocksdb 10 0.005): 10/10 in 0.09s, was 40.6s. Write skew 0/30.Benchmarks (red, median of 3)
Commits and sets are slower because of the slot per transaction and put validation. The 10-key case is slower because the single slot serializes writers on different keys. Consistency comes first under the contract, and puts stay validated as a safety net for writers that bypass the slot.
Known limits