mirror of
https://github.com/facebook/rocksdb.git
synced 2026-07-07 14:47:40 +08:00
Blog post for range tombstone conversion (#14862)
Summary: Pull Request resolved: https://github.com/facebook/rocksdb/pull/14862 Add blog post for range tombstone conversion. Reviewed By: xingbowang Differential Revision: D108946953 fbshipit-source-id: f2ded24a5452d2f56a12928b979a8f44930dde03
This commit is contained in:
committed by
meta-codesync[bot]
parent
5b324a2160
commit
6ccfbd4a86
@@ -0,0 +1,131 @@
|
||||
---
|
||||
title: "Range Tombstone Conversion: Faster Scans Over Long Runs of Deletes"
|
||||
layout: post
|
||||
author: joshkang97
|
||||
category: blog
|
||||
---
|
||||
|
||||
RocksDB has historically been known for poor performance when tombstones accumulate. This has become a common problem within Meta, and the community has raised it as well. Here, we introduce an optimization that attempts to convert contiguous tombstones into a range tombstone during scans. As a result, instead of skipping through N tombstones, we only need to skip through a single range tombstone.
|
||||
|
||||
## Background: point tombstones and range tombstones
|
||||
|
||||
RocksDB is an LSM-tree, so a delete does not erase data in place. It writes a *tombstone*: a marker that shadows older values. A **point tombstone** (from `Delete` or `SingleDelete`) shadows exactly one key, while a **range tombstone** (from `DeleteRange`) shadows an entire half-open key range `[start, end)` with a single entry. Because newer data (usually) sits above older data in the tree, a read merges from the top down and takes the first entry it finds for a key, so a tombstone at an upper level hides any value for that key, or for any key in a range tombstone's span, at the levels below.
|
||||
|
||||

|
||||
{: style="display: block; margin-left: auto; margin-right: auto; width: 85%"}
|
||||
|
||||
*Point and range tombstones hide the values below them. The scan steps over each point tombstone but skips the range tombstone in one hop, and only the live keys (a, e, j) are returned to the user.*
|
||||
{: style="text-align: center"}
|
||||
|
||||
In both cases the space is reclaimed only later, during compaction, and only once the tombstone reaches the bottommost level with no live snapshot still needing it. Until then the tombstones sit in the way of reads. A scan never returns a deleted key, but to work out which keys are live it still has to step through every entry in key order. A point tombstone is just an ordinary entry, so the scan walks each one individually, and a run of N point tombstones costs N steps. A range tombstone is different: it is a single entry that covers the whole span, so when a scan reaches it, it can skip straight to the end of the range in one step instead of walking every key inside.
|
||||
|
||||
## Existing solutions
|
||||
|
||||
A bulk delete leaves a region of the key space full of tombstones, and until compaction removes them, every scan across that region pays for them. The iterator steps over each point tombstone in turn to reach the live keys, because a run of point tombstones is just ordinary consecutive keys with no shortcut. That is O(N) in the number of dead entries, paid on every scan, and N grows with the size of the deleted region. The natural question is whether we can simply get rid of the tombstones faster, and RocksDB already gives you a few tools for that.
|
||||
|
||||
**Deletion-triggered compaction.** `NewCompactOnDeletionCollectorFactory` marks an SST file for compaction once it holds a high density of tombstones (at least `D` deletions within any `N` consecutive entries, or a whole-file tombstone ratio above a threshold), so RocksDB schedules those files for compaction sooner than the normal LSM compaction schedule would.
|
||||
|
||||
**Scan-triggered memtable flush.** `memtable_op_scan_flush_trigger` (and its averaged sibling `memtable_avg_op_scan_flush_trigger`) flush the active memtable once a single iterator operation scans through too many invisible entries (tombstones or shadowed values), moving them into an SST where deletion-triggered compaction can then clean them up. The two are designed to be used together.
|
||||
|
||||
These all help, but they share the same limitations, because they all work by *removing* tombstones through flush and compaction:
|
||||
|
||||
* **They are reactive and asynchronous.** Compaction runs in the background; a scan happening right now, before compaction catches up, still pays the full cost.
|
||||
* **They add write amplification.** Every extra flush and compaction is more I/O and CPU spent rewriting data.
|
||||
* **They are defeated by a long-lived snapshot.** Compaction can only drop a tombstone when no snapshot still needs the data it shadows, so a backup, a long analytics query, or replication holding a snapshot forces RocksDB to keep every tombstone created during that snapshot's lifetime, no matter how aggressively you schedule compaction. This is both the case where tombstones pile up the most and the case these tools cannot fix.
|
||||
|
||||
## The naive fix
|
||||
|
||||
The tempting fix is to notice a long run of contiguous point tombstones (say, during a flush or a compaction) and simply replace it with a single range tombstone. One entry instead of N, and reads skip it. Done.
|
||||
|
||||
The catch is *visibility*. A flush sees a single memtable; a compaction sees only the levels it happens to be merging. From that partial vantage, a run of tombstones can look perfectly contiguous even though live keys sit between them at other levels. Remember that a point tombstone shadows only its own key, while a range tombstone shadows everything in its span. So collapsing a locally-contiguous run into a range tombstone can delete live data that the original point tombstones never touched.
|
||||
|
||||

|
||||
{: style="display: block; margin-left: auto; margin-right: auto; width: 90%"}
|
||||
|
||||
*On the LSM the L0 tombstones look contiguous, but live keys sit one level below; collapsing them into a range tombstone would delete that live data.*
|
||||
{: style="text-align: center"}
|
||||
|
||||
In the figure, L0 holds tombstones for 10, 20, and 30 that look contiguous, with 40 the next live key just past them, but 15, 25, and 35 are live one level down in L1. A naive range tombstone over `[10, 40)` would also erase 15, 25, and 35. Only something that can see the entire LSM at once can tell whether a run of deletes is *truly* contiguous.
|
||||
|
||||
## Application iterators
|
||||
|
||||
A read iterator merges every source (the mutable and immutable memtables and every SST level) into one ordered, snapshot-consistent stream of the keys actually visible at the read's sequence number. As long as the scan can observe every interior live key, this gives a global view of the database, so the iterator can safely decide whether a run of point tombstones can be converted into a range tombstone (at the same snapshot sequence number, of course). That full-visibility requirement is also why the feature disables itself for `table_filter`, partial-timestamp reads, and prefix iterators that are neither total-order nor bounded by `prefix_same_as_start`.
|
||||
|
||||
As the iterator moves forward (or backward) across contiguous point tombstones with no live key in between, it synthesizes a single range tombstone `[first_tombstone_key, next_live_key)` and inserts it into the mutable memtable using the same sequence number as the iterator is using to read the LSM.
|
||||
|
||||

|
||||
{: style="display: block; margin-left: auto; margin-right: auto; width: 95%"}
|
||||
|
||||
*Before: the run's point tombstones are spread across levels. After: the scan adds one range tombstone to the memtable that summarizes them. The point tombstones remain, but later scans hit the range tombstone first and skip the run.*
|
||||
{: style="text-align: center"}
|
||||
|
||||
The inserted tombstone is *logically redundant*: those keys were already deleted, so it changes no query's result and is purely a performance optimization. A conversion is not always guaranteed to succeed: there are numerous guards that discard one to avoid corrupting the database. See the comments on `min_tombstones_for_range_conversion` for details.
|
||||
|
||||
Because the tombstone lives in the memtable, it follows the normal lifecycle from there: it flushes to an SST and is eventually compacted away together with the point tombstones it summarizes, once no snapshot needs them. The cost is one redundant entry; the benefit is repaid across every scan in between.
|
||||
|
||||
## Enabling it
|
||||
|
||||
Range tombstone conversion is controlled by the column-family option `min_tombstones_for_range_conversion`: the minimum length of a contiguous point-tombstone run that triggers a conversion. The default is `0`, which disables the feature. Set it to a positive value to turn it on; the option is dynamically changeable through `SetOptions`, so you can enable or tune it without reopening the database.
|
||||
|
||||
```cpp
|
||||
Options options;
|
||||
// Convert a run into a range tombstone once 100 contiguous
|
||||
// point tombstones are seen with no live key between them.
|
||||
options.min_tombstones_for_range_conversion = 100;
|
||||
|
||||
// Or change it dynamically on a running DB:
|
||||
db->SetOptions({{"min_tombstones_for_range_conversion", "100"}});
|
||||
```
|
||||
|
||||
Pick the threshold to match your workload: a higher value restricts conversions to genuinely long runs, where the payoff is largest, and avoids adding redundant tombstones for short gaps.
|
||||
|
||||
Two statistics tickers let you see the feature at work:
|
||||
|
||||
* `rocksdb.read.path.range.tombstones.inserted` counts the range tombstones synthesized by conversion.
|
||||
* `rocksdb.read.path.range.tombstones.discarded` counts the attempts that were discarded for safety reasons.
|
||||
|
||||
## Performance
|
||||
|
||||
The optimization targets read workloads over data that has accumulated tombstones. To measure it we use the following `db_bench` setup: fill and compact a database, scatter sets of contiguous point deletes through it, then run a `seekrandom` scan with conversion off versus on.
|
||||
|
||||
```
|
||||
# Fill and compact 1M keys
|
||||
./db_bench --benchmarks=fillseq,compact --compression_type=none --num=1000000 --db=$DB
|
||||
|
||||
# Scatter tombstones: seek to random keys and delete 100 keys after each seek
|
||||
./db_bench --benchmarks=seekrandom,flush --compression_type=none --num=2000 \
|
||||
--seek_nexts=0 --seek_nexts_to_delete=100 --use_existing_db=1 --threads=1 --db=$DB
|
||||
|
||||
# Scan workload: forward or reverse, conversion off (=0) or on (=8)
|
||||
./db_bench --benchmarks=seekrandom --seek_nexts=100 --threads=8 --reverse_iterator=<true|false> \
|
||||
--use_existing_db=1 --compression_type=none --num=1000000 --duration=10 \
|
||||
--disable_auto_compactions --min_tombstones_for_range_conversion=<0|8> --db=$DB
|
||||
```
|
||||
|
||||
`seekrandom` over the delete-heavy database, throughput in ops/s:
|
||||
|
||||
|Workload |Conversion off |Conversion on |Speedup |
|
||||
|--- |--- |--- |--- |
|
||||
|Forward scan |2,685 |266,733 |~99x |
|
||||
|Reverse scan |519 |191,119 |~368x |
|
||||
|
||||
### Regression check
|
||||
|
||||
Enabling the feature adds a little per-scan bookkeeping (it tracks runs of contiguous tombstones) even on scans that never convert anything, so it is worth confirming there is no slowdown when there are no tombstones to collapse. Here we fill and compact without scattering any deletes, then run the same scan with conversion off versus on:
|
||||
|
||||
```
|
||||
# Fill and compact 1M keys, no deletes
|
||||
./db_bench --benchmarks=fillseq,compact --compression_type=none --num=1000000 --db=$DB
|
||||
|
||||
# Same scan workload: forward or reverse, conversion off (=0) or on (=8)
|
||||
./db_bench --benchmarks=seekrandom --seek_nexts=100 --threads=8 --reverse_iterator=<true|false> \
|
||||
--use_existing_db=1 --compression_type=none --num=1000000 --duration=10 \
|
||||
--disable_auto_compactions --min_tombstones_for_range_conversion=<0|8> --db=$DB
|
||||
```
|
||||
|
||||
|Workload |Conversion off |Conversion on |Speedup |
|
||||
|--- |--- |--- |--- |
|
||||
|Forward scan, no deletes |310,052 |311,185 |no change (within noise) |
|
||||
|Reverse scan, no deletes |237,484 |236,541 |no change (within noise) |
|
||||
|
||||
Throughput is unchanged, so the bookkeeping is cheap and the feature is safe to leave enabled for mixed workloads.
|
||||
@@ -0,0 +1,87 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="760" height="196" viewBox="0 30 760 196" font-family="Helvetica, Arial, sans-serif">
|
||||
<defs>
|
||||
<marker id="arrow-cba" markerWidth="11" markerHeight="11" refX="8" refY="3.2" orient="auto" markerUnits="strokeWidth">
|
||||
<path d="M0,0 L8,3.2 L0,6.4 z" fill="#1565c0"/>
|
||||
</marker>
|
||||
</defs>
|
||||
|
||||
<rect x="0" y="0" width="760" height="262" fill="#ffffff"/>
|
||||
|
||||
<text x="190" y="46" text-anchor="middle" font-size="14" font-weight="bold" fill="#37474f">Before</text>
|
||||
<text x="582" y="46" text-anchor="middle" font-size="14" font-weight="bold" fill="#0d47a1">After</text>
|
||||
|
||||
<!-- conversion arrow between the panels -->
|
||||
<line x1="360" y1="120" x2="414" y2="120" stroke="#1565c0" stroke-width="2.5" marker-end="url(#arrow-cba)"/>
|
||||
<text x="387" y="110" text-anchor="middle" font-size="10" fill="#1565c0">convert</text>
|
||||
<text x="387" y="135" text-anchor="middle" font-size="9" fill="#1565c0">(scan)</text>
|
||||
|
||||
<!-- ===== LEFT (Before) ===== -->
|
||||
<text x="8" y="76" font-size="9" fill="#37474f">memtable</text>
|
||||
<text x="8" y="111" font-size="11" font-weight="bold" fill="#37474f">L0</text>
|
||||
<text x="8" y="145" font-size="11" font-weight="bold" fill="#37474f">L1</text>
|
||||
<text x="8" y="179" font-size="11" font-weight="bold" fill="#37474f">L2</text>
|
||||
|
||||
<rect x="56" y="58" width="296" height="30" rx="4" fill="#fafafa" stroke="#e0e0e0" stroke-width="1.1"/>
|
||||
<rect x="56" y="92" width="296" height="30" rx="4" fill="#fafafa" stroke="#e0e0e0" stroke-width="1.1"/>
|
||||
<rect x="56" y="126" width="296" height="30" rx="4" fill="#fafafa" stroke="#e0e0e0" stroke-width="1.1"/>
|
||||
<rect x="56" y="160" width="296" height="30" rx="4" fill="#fafafa" stroke="#e0e0e0" stroke-width="1.1"/>
|
||||
|
||||
<!-- L0: point tombstones k1, k3 -->
|
||||
<rect x="67" y="95" width="58" height="24" rx="4" fill="#ffcdd2" stroke="#c62828" stroke-width="1.4"/>
|
||||
<text x="96" y="111" text-anchor="middle" font-size="11" font-weight="bold" fill="#b71c1c">k1</text>
|
||||
<rect x="211" y="95" width="58" height="24" rx="4" fill="#ffcdd2" stroke="#c62828" stroke-width="1.4"/>
|
||||
<text x="240" y="111" text-anchor="middle" font-size="11" font-weight="bold" fill="#b71c1c">k3</text>
|
||||
<!-- L1: point tombstone k2 -->
|
||||
<rect x="139" y="129" width="58" height="24" rx="4" fill="#ffcdd2" stroke="#c62828" stroke-width="1.4"/>
|
||||
<text x="168" y="145" text-anchor="middle" font-size="11" font-weight="bold" fill="#b71c1c">k2</text>
|
||||
<!-- L2: hidden values k1,k2,k3 + live k4 -->
|
||||
<rect x="67" y="163" width="58" height="24" rx="4" fill="#ffe3e3" stroke="#ef9a9a" stroke-width="1.4"/>
|
||||
<text x="96" y="179" text-anchor="middle" font-size="11" font-weight="bold" fill="#b71c1c">k1</text>
|
||||
<rect x="139" y="163" width="58" height="24" rx="4" fill="#ffe3e3" stroke="#ef9a9a" stroke-width="1.4"/>
|
||||
<text x="168" y="179" text-anchor="middle" font-size="11" font-weight="bold" fill="#b71c1c">k2</text>
|
||||
<rect x="211" y="163" width="58" height="24" rx="4" fill="#ffe3e3" stroke="#ef9a9a" stroke-width="1.4"/>
|
||||
<text x="240" y="179" text-anchor="middle" font-size="11" font-weight="bold" fill="#b71c1c">k3</text>
|
||||
<rect x="283" y="163" width="58" height="24" rx="4" fill="#c8e6c9" stroke="#2e7d32" stroke-width="1.4"/>
|
||||
<text x="312" y="179" text-anchor="middle" font-size="11" font-weight="bold" fill="#1b5e20">k4</text>
|
||||
|
||||
<!-- ===== RIGHT (After) ===== -->
|
||||
<text x="420" y="76" font-size="9" fill="#37474f">memtable</text>
|
||||
<text x="420" y="111" font-size="11" font-weight="bold" fill="#37474f">L0</text>
|
||||
<text x="420" y="145" font-size="11" font-weight="bold" fill="#37474f">L1</text>
|
||||
<text x="420" y="179" font-size="11" font-weight="bold" fill="#37474f">L2</text>
|
||||
|
||||
<rect x="466" y="58" width="288" height="30" rx="4" fill="#fafafa" stroke="#e0e0e0" stroke-width="1.1"/>
|
||||
<rect x="466" y="92" width="288" height="30" rx="4" fill="#fafafa" stroke="#e0e0e0" stroke-width="1.1"/>
|
||||
<rect x="466" y="126" width="288" height="30" rx="4" fill="#fafafa" stroke="#e0e0e0" stroke-width="1.1"/>
|
||||
<rect x="466" y="160" width="288" height="30" rx="4" fill="#fafafa" stroke="#e0e0e0" stroke-width="1.1"/>
|
||||
|
||||
<!-- memtable: NEW range tombstone [k1, k4) -->
|
||||
<rect x="473" y="61" width="216" height="24" rx="4" fill="#bbdefb" stroke="#1565c0" stroke-width="2"/>
|
||||
<text x="581" y="77" text-anchor="middle" font-size="9" font-weight="bold" fill="#0d47a1">range tombstone [k1, k4)</text>
|
||||
<!-- L0: unchanged -->
|
||||
<rect x="473" y="95" width="58" height="24" rx="4" fill="#ffcdd2" stroke="#c62828" stroke-width="1.4"/>
|
||||
<text x="502" y="111" text-anchor="middle" font-size="11" font-weight="bold" fill="#b71c1c">k1</text>
|
||||
<rect x="617" y="95" width="58" height="24" rx="4" fill="#ffcdd2" stroke="#c62828" stroke-width="1.4"/>
|
||||
<text x="646" y="111" text-anchor="middle" font-size="11" font-weight="bold" fill="#b71c1c">k3</text>
|
||||
<rect x="545" y="129" width="58" height="24" rx="4" fill="#ffcdd2" stroke="#c62828" stroke-width="1.4"/>
|
||||
<text x="574" y="145" text-anchor="middle" font-size="11" font-weight="bold" fill="#b71c1c">k2</text>
|
||||
<rect x="473" y="163" width="58" height="24" rx="4" fill="#ffe3e3" stroke="#ef9a9a" stroke-width="1.4"/>
|
||||
<text x="502" y="179" text-anchor="middle" font-size="11" font-weight="bold" fill="#b71c1c">k1</text>
|
||||
<rect x="545" y="163" width="58" height="24" rx="4" fill="#ffe3e3" stroke="#ef9a9a" stroke-width="1.4"/>
|
||||
<text x="574" y="179" text-anchor="middle" font-size="11" font-weight="bold" fill="#b71c1c">k2</text>
|
||||
<rect x="617" y="163" width="58" height="24" rx="4" fill="#ffe3e3" stroke="#ef9a9a" stroke-width="1.4"/>
|
||||
<text x="646" y="179" text-anchor="middle" font-size="11" font-weight="bold" fill="#b71c1c">k3</text>
|
||||
<rect x="689" y="163" width="58" height="24" rx="4" fill="#c8e6c9" stroke="#2e7d32" stroke-width="1.4"/>
|
||||
<text x="718" y="179" text-anchor="middle" font-size="11" font-weight="bold" fill="#1b5e20">k4</text>
|
||||
|
||||
<!-- legend -->
|
||||
<rect x="60" y="206" width="14" height="10" rx="2" fill="#ffcdd2" stroke="#c62828" stroke-width="1.1"/>
|
||||
<text x="78" y="215" font-size="10" fill="#616161">point tombstone</text>
|
||||
<rect x="190" y="206" width="14" height="10" rx="2" fill="#ffe3e3" stroke="#ef9a9a" stroke-width="1.1"/>
|
||||
<text x="208" y="215" font-size="10" fill="#616161">shadowed value</text>
|
||||
<rect x="306" y="206" width="14" height="10" rx="2" fill="#c8e6c9" stroke="#2e7d32" stroke-width="1.1"/>
|
||||
<text x="324" y="215" font-size="10" fill="#616161">live</text>
|
||||
<rect x="368" y="206" width="14" height="10" rx="2" fill="#bbdefb" stroke="#1565c0" stroke-width="1.1"/>
|
||||
<text x="386" y="215" font-size="10" fill="#616161">range tombstone</text>
|
||||
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 6.5 KiB |
@@ -0,0 +1,60 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="760" height="230" viewBox="0 32 760 230" font-family="Helvetica, Arial, sans-serif">
|
||||
<defs>
|
||||
<marker id="arrow-red" markerWidth="9" markerHeight="9" refX="7" refY="3" orient="auto" markerUnits="strokeWidth">
|
||||
<path d="M0,0 L7,3 L0,6 z" fill="#c62828"/>
|
||||
</marker>
|
||||
</defs>
|
||||
|
||||
<rect x="0" y="0" width="760" height="262" fill="#ffffff"/>
|
||||
|
||||
<!-- key column labels -->
|
||||
<text x="175" y="50" text-anchor="middle" font-size="12" fill="#9e9e9e">10</text>
|
||||
<text x="255" y="50" text-anchor="middle" font-size="12" fill="#9e9e9e">15</text>
|
||||
<text x="335" y="50" text-anchor="middle" font-size="12" fill="#9e9e9e">20</text>
|
||||
<text x="415" y="50" text-anchor="middle" font-size="12" fill="#9e9e9e">25</text>
|
||||
<text x="495" y="50" text-anchor="middle" font-size="12" fill="#9e9e9e">30</text>
|
||||
<text x="575" y="50" text-anchor="middle" font-size="12" fill="#9e9e9e">35</text>
|
||||
<text x="655" y="50" text-anchor="middle" font-size="12" fill="#9e9e9e">40</text>
|
||||
|
||||
<!-- L0 row: point tombstones, "contiguous" at this level -->
|
||||
<rect x="130" y="62" width="580" height="44" rx="5" fill="#fafafa" stroke="#e0e0e0" stroke-width="1.2"/>
|
||||
<text x="14" y="80" font-size="13" font-weight="bold" fill="#37474f">L0</text>
|
||||
<text x="14" y="95" font-size="10" fill="#9e9e9e">newer</text>
|
||||
|
||||
<rect x="147" y="66" width="56" height="36" rx="5" fill="#ffcdd2" stroke="#c62828" stroke-width="1.5"/>
|
||||
<text x="175" y="81" text-anchor="middle" font-size="12" font-weight="bold" fill="#b71c1c">10</text>
|
||||
<text x="175" y="95" text-anchor="middle" font-size="9" fill="#b71c1c">DEL</text>
|
||||
<rect x="307" y="66" width="56" height="36" rx="5" fill="#ffcdd2" stroke="#c62828" stroke-width="1.5"/>
|
||||
<text x="335" y="81" text-anchor="middle" font-size="12" font-weight="bold" fill="#b71c1c">20</text>
|
||||
<text x="335" y="95" text-anchor="middle" font-size="9" fill="#b71c1c">DEL</text>
|
||||
<rect x="467" y="66" width="56" height="36" rx="5" fill="#ffcdd2" stroke="#c62828" stroke-width="1.5"/>
|
||||
<text x="495" y="81" text-anchor="middle" font-size="12" font-weight="bold" fill="#b71c1c">30</text>
|
||||
<text x="495" y="95" text-anchor="middle" font-size="9" fill="#b71c1c">DEL</text>
|
||||
<rect x="627" y="66" width="56" height="36" rx="5" fill="#c8e6c9" stroke="#2e7d32" stroke-width="1.5"/>
|
||||
<text x="655" y="89" text-anchor="middle" font-size="13" font-weight="bold" fill="#1b5e20">40</text>
|
||||
|
||||
<!-- naive range tombstone spanning the run -->
|
||||
<rect x="147" y="116" width="480" height="24" rx="5" fill="#c62828" fill-opacity="0.18" stroke="#c62828" stroke-width="1.5" stroke-dasharray="5 3"/>
|
||||
<text x="387" y="132" text-anchor="middle" font-size="12" font-weight="bold" fill="#b71c1c">naive: replace the run with one range tombstone [10, 40)</text>
|
||||
|
||||
<!-- L1 row: live keys interleaved one level below (would be wrongly deleted) -->
|
||||
<rect x="130" y="150" width="580" height="44" rx="5" fill="#fafafa" stroke="#e0e0e0" stroke-width="1.2"/>
|
||||
<text x="14" y="168" font-size="13" font-weight="bold" fill="#37474f">L1</text>
|
||||
<text x="14" y="183" font-size="10" fill="#9e9e9e">older</text>
|
||||
|
||||
<rect x="227" y="154" width="56" height="36" rx="5" fill="#ffe3e3" stroke="#ef9a9a" stroke-width="1.5"/>
|
||||
<text x="255" y="177" text-anchor="middle" font-size="13" font-weight="bold" fill="#b71c1c">15</text>
|
||||
<rect x="387" y="154" width="56" height="36" rx="5" fill="#ffe3e3" stroke="#ef9a9a" stroke-width="1.5"/>
|
||||
<text x="415" y="177" text-anchor="middle" font-size="13" font-weight="bold" fill="#b71c1c">25</text>
|
||||
<rect x="547" y="154" width="56" height="36" rx="5" fill="#ffe3e3" stroke="#ef9a9a" stroke-width="1.5"/>
|
||||
<text x="575" y="177" text-anchor="middle" font-size="13" font-weight="bold" fill="#b71c1c">35</text>
|
||||
|
||||
<!-- arrows: the naive range would now hide the live keys below -->
|
||||
<line x1="255" y1="140" x2="255" y2="153" stroke="#c62828" stroke-width="1.6" marker-end="url(#arrow-red)"/>
|
||||
<line x1="415" y1="140" x2="415" y2="153" stroke="#c62828" stroke-width="1.6" marker-end="url(#arrow-red)"/>
|
||||
<line x1="575" y1="140" x2="575" y2="153" stroke="#c62828" stroke-width="1.6" marker-end="url(#arrow-red)"/>
|
||||
|
||||
<!-- caption -->
|
||||
<text x="380" y="222" text-anchor="middle" font-size="13" fill="#1a1a1a">The point tombstones hid only 10, 20, 30. A range tombstone over [10, 40) would also hide</text>
|
||||
<text x="380" y="244" text-anchor="middle" font-size="13" font-weight="bold" fill="#b71c1c">the live keys 15, 25, 35 one level down. Only a whole-LSM view knows the run is not truly contiguous.</text>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 4.5 KiB |
@@ -0,0 +1,95 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="760" height="312" viewBox="0 0 760 312" font-family="Helvetica, Arial, sans-serif">
|
||||
<defs>
|
||||
<marker id="arrow-tb" markerWidth="10" markerHeight="10" refX="8" refY="3" orient="auto" markerUnits="strokeWidth">
|
||||
<path d="M0,0 L8,3 L0,6 z" fill="#37474f"/>
|
||||
</marker>
|
||||
</defs>
|
||||
|
||||
<rect x="0" y="0" width="760" height="312" fill="#ffffff"/>
|
||||
|
||||
<!-- key column labels -->
|
||||
<text x="150" y="18" text-anchor="middle" font-size="10" fill="#9e9e9e">a</text>
|
||||
<text x="210" y="18" text-anchor="middle" font-size="10" fill="#9e9e9e">b</text>
|
||||
<text x="270" y="18" text-anchor="middle" font-size="10" fill="#9e9e9e">c</text>
|
||||
<text x="330" y="18" text-anchor="middle" font-size="10" fill="#9e9e9e">d</text>
|
||||
<text x="390" y="18" text-anchor="middle" font-size="10" fill="#9e9e9e">e</text>
|
||||
<text x="450" y="18" text-anchor="middle" font-size="10" fill="#9e9e9e">f</text>
|
||||
<text x="510" y="18" text-anchor="middle" font-size="10" fill="#9e9e9e">g</text>
|
||||
<text x="570" y="18" text-anchor="middle" font-size="10" fill="#9e9e9e">h</text>
|
||||
<text x="630" y="18" text-anchor="middle" font-size="10" fill="#9e9e9e">i</text>
|
||||
<text x="690" y="18" text-anchor="middle" font-size="10" fill="#9e9e9e">j</text>
|
||||
|
||||
<!-- L0: a run of point tombstones -->
|
||||
<rect x="118" y="28" width="600" height="38" rx="5" fill="#fafafa" stroke="#e0e0e0" stroke-width="1.2"/>
|
||||
<text x="14" y="44" font-size="13" font-weight="bold" fill="#37474f">L0</text>
|
||||
<text x="10" y="57" font-size="8" fill="#9e9e9e">newest</text>
|
||||
<rect x="185" y="31" width="50" height="32" rx="5" fill="#ffcdd2" stroke="#c62828" stroke-width="1.5"/>
|
||||
<text x="210" y="45" text-anchor="middle" font-size="11" font-weight="bold" fill="#b71c1c">b</text>
|
||||
<text x="210" y="57" text-anchor="middle" font-size="8" fill="#b71c1c">DEL</text>
|
||||
<rect x="245" y="31" width="50" height="32" rx="5" fill="#ffcdd2" stroke="#c62828" stroke-width="1.5"/>
|
||||
<text x="270" y="45" text-anchor="middle" font-size="11" font-weight="bold" fill="#b71c1c">c</text>
|
||||
<text x="270" y="57" text-anchor="middle" font-size="8" fill="#b71c1c">DEL</text>
|
||||
<rect x="305" y="31" width="50" height="32" rx="5" fill="#ffcdd2" stroke="#c62828" stroke-width="1.5"/>
|
||||
<text x="330" y="45" text-anchor="middle" font-size="11" font-weight="bold" fill="#b71c1c">d</text>
|
||||
<text x="330" y="57" text-anchor="middle" font-size="8" fill="#b71c1c">DEL</text>
|
||||
|
||||
<!-- L1: a live key (e) in between, then a wider range tombstone -->
|
||||
<rect x="118" y="78" width="600" height="38" rx="5" fill="#fafafa" stroke="#e0e0e0" stroke-width="1.2"/>
|
||||
<text x="14" y="101" font-size="13" font-weight="bold" fill="#37474f">L1</text>
|
||||
<rect x="365" y="81" width="50" height="32" rx="5" fill="#c8e6c9" stroke="#2e7d32" stroke-width="1.5"/>
|
||||
<text x="390" y="101" text-anchor="middle" font-size="12" font-weight="bold" fill="#1b5e20">e</text>
|
||||
<rect x="425" y="81" width="240" height="32" rx="5" fill="#bbdefb" stroke="#1565c0" stroke-width="1.5"/>
|
||||
<text x="545" y="101" text-anchor="middle" font-size="10" font-weight="bold" fill="#0d47a1">DeleteRange [f, j)</text>
|
||||
|
||||
<!-- L2: live values; those under a deletion are hidden -->
|
||||
<rect x="118" y="128" width="600" height="38" rx="5" fill="#fafafa" stroke="#e0e0e0" stroke-width="1.2"/>
|
||||
<text x="14" y="144" font-size="13" font-weight="bold" fill="#37474f">L2</text>
|
||||
<text x="10" y="157" font-size="8" fill="#9e9e9e">oldest</text>
|
||||
<rect x="125" y="131" width="50" height="32" rx="5" fill="#c8e6c9" stroke="#2e7d32" stroke-width="1.5"/>
|
||||
<text x="150" y="151" text-anchor="middle" font-size="12" font-weight="bold" fill="#1b5e20">a</text>
|
||||
<rect x="185" y="131" width="50" height="32" rx="5" fill="#ffe3e3" stroke="#ef9a9a" stroke-width="1.5"/>
|
||||
<text x="210" y="151" text-anchor="middle" font-size="12" font-weight="bold" fill="#b71c1c">b</text>
|
||||
<rect x="245" y="131" width="50" height="32" rx="5" fill="#ffe3e3" stroke="#ef9a9a" stroke-width="1.5"/>
|
||||
<text x="270" y="151" text-anchor="middle" font-size="12" font-weight="bold" fill="#b71c1c">c</text>
|
||||
<rect x="305" y="131" width="50" height="32" rx="5" fill="#ffe3e3" stroke="#ef9a9a" stroke-width="1.5"/>
|
||||
<text x="330" y="151" text-anchor="middle" font-size="12" font-weight="bold" fill="#b71c1c">d</text>
|
||||
<rect x="425" y="131" width="50" height="32" rx="5" fill="#ffe3e3" stroke="#ef9a9a" stroke-width="1.5"/>
|
||||
<text x="450" y="151" text-anchor="middle" font-size="12" font-weight="bold" fill="#b71c1c">f</text>
|
||||
<rect x="485" y="131" width="50" height="32" rx="5" fill="#ffe3e3" stroke="#ef9a9a" stroke-width="1.5"/>
|
||||
<text x="510" y="151" text-anchor="middle" font-size="12" font-weight="bold" fill="#b71c1c">g</text>
|
||||
<rect x="545" y="131" width="50" height="32" rx="5" fill="#ffe3e3" stroke="#ef9a9a" stroke-width="1.5"/>
|
||||
<text x="570" y="151" text-anchor="middle" font-size="12" font-weight="bold" fill="#b71c1c">h</text>
|
||||
<rect x="605" y="131" width="50" height="32" rx="5" fill="#ffe3e3" stroke="#ef9a9a" stroke-width="1.5"/>
|
||||
<text x="630" y="151" text-anchor="middle" font-size="12" font-weight="bold" fill="#b71c1c">i</text>
|
||||
<rect x="665" y="131" width="50" height="32" rx="5" fill="#c8e6c9" stroke="#2e7d32" stroke-width="1.5"/>
|
||||
<text x="690" y="151" text-anchor="middle" font-size="12" font-weight="bold" fill="#1b5e20">j</text>
|
||||
|
||||
<!-- scan: point tombstones are one step each, the range tombstone is a single skip -->
|
||||
<text x="14" y="196" font-size="12" font-weight="bold" fill="#37474f">scan</text>
|
||||
<line x1="150" y1="192" x2="390" y2="192" stroke="#37474f" stroke-width="2"/>
|
||||
<circle cx="150" cy="192" r="3.2" fill="#2e7d32"/>
|
||||
<circle cx="210" cy="192" r="3.2" fill="#c62828"/>
|
||||
<circle cx="270" cy="192" r="3.2" fill="#c62828"/>
|
||||
<circle cx="330" cy="192" r="3.2" fill="#c62828"/>
|
||||
<circle cx="390" cy="192" r="3.2" fill="#2e7d32"/>
|
||||
<path d="M390,192 C 480,232 600,232 690,192" fill="none" stroke="#37474f" stroke-width="2" marker-end="url(#arrow-tb)"/>
|
||||
<circle cx="690" cy="192" r="3.2" fill="#2e7d32"/>
|
||||
|
||||
<!-- step annotations -->
|
||||
<path d="M185,202 L185,207 L355,207 L355,202" fill="none" stroke="#9e9e9e" stroke-width="1.3"/>
|
||||
<text x="270" y="221" text-anchor="middle" font-size="11" fill="#b71c1c">3 steps: one per point tombstone</text>
|
||||
<text x="545" y="250" text-anchor="middle" font-size="11" font-weight="bold" fill="#0d47a1">1 step: skip the whole range tombstone</text>
|
||||
|
||||
<!-- legend -->
|
||||
<rect x="120" y="266" width="14" height="10" rx="2" fill="#c8e6c9" stroke="#2e7d32" stroke-width="1.1"/>
|
||||
<text x="138" y="275" font-size="10" fill="#616161">live</text>
|
||||
<rect x="186" y="266" width="14" height="10" rx="2" fill="#ffcdd2" stroke="#c62828" stroke-width="1.1"/>
|
||||
<text x="204" y="275" font-size="10" fill="#616161">point tombstone</text>
|
||||
<rect x="320" y="266" width="14" height="10" rx="2" fill="#ffe3e3" stroke="#ef9a9a" stroke-width="1.1"/>
|
||||
<text x="338" y="275" font-size="10" fill="#616161">shadowed value</text>
|
||||
<rect x="452" y="266" width="14" height="10" rx="2" fill="#bbdefb" stroke="#1565c0" stroke-width="1.1"/>
|
||||
<text x="470" y="275" font-size="10" fill="#616161">range tombstone</text>
|
||||
|
||||
<!-- caption -->
|
||||
<text x="380" y="300" text-anchor="middle" font-size="13" font-weight="bold" fill="#1a1a1a">Point tombstones cost one scan step each; a range tombstone is a single step. Only a, e, j are returned.</text>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 7.2 KiB |
Reference in New Issue
Block a user