This repository was archived by the owner on Oct 18, 2023. It is now read-only.
Draft
Conversation
b40a14b to
8bececd
Compare
**!!! early draft, full of debug prints, barely works !!!** This draft contains experiments around deduplicating our own `wallog` format with libSQL WAL. The potential win here is reducing write and space amplification from 2x to around 1.08x. The main idea is as follows: `wallog` is only used to store frame metadata, and frame data is only stored either in the main database file, or in WAL. That's very simple to implement in a single-node system, but it gets complicated with replicas, because a replica is allowed to ask the primary for any arbitrary wallog frame. The rough idea for dealing with replicas is to: 1. Make sure that we control checkpoints. autocheckpoint is off, and we only issue a checkpoint operation on the primary ourselves, explicitly, and periodically. 2. All streaming of frames to replicas must finish before we issue a checkpoint operation. 3. We only checkpoint in TRUNCATE mode, i.e. a write lock is taken and the whole WAL log is rewritten to the main db file. That simplifies lots of edge (sic!) cases. 4. Once we checkpoint, we drop the previous `wallog`, and instead only store the following information. Let's assume that the main db file has N pages. Pages 1..N are now available as frames X..X+N in the `wallog`, and X is the oldest frame a replica should ever ask for -> anything before X is out-of-date anyway. If any replica asks for an earlier page, it gets an error message saying "please drop whatever you're doing and start asking for frames X or greater instead.
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 subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.
!!! early draft, full of debug prints, barely works !!!
This draft contains experiments around deduplicating our own
wallogformat with libSQL WAL. The potential win here is reducing write and space amplification from 2x to around 1.08x.The main idea is as follows:
wallogis only used to store frame metadata, and frame data is only stored either in the main database file, or in WAL. That's very simple to implement in a single-node system, but it gets complicated with replicas, because a replica is allowed to ask the primary for any arbitrary wallog frame.The rough idea for dealing with replicas is to:
wallog, and instead only store the following information. Let's assume that the main db file has N pages. Pages 1..N are now available as frames X..X+N in thewallog, and X is the oldest frame a replica should ever ask for -> anything before X is out-of-date anyway. If any replica asks for an earlier page, it gets an error message saying "please drop whatever you're doing and start asking for frames X or greater instead.