Line data Source code
1 : //!
2 : //! Simple on-disk B-tree implementation
3 : //!
4 : //! This is used as the index structure within image and delta layers
5 : //!
6 : //! Features:
7 : //! - Fixed-width keys
8 : //! - Fixed-width values (VALUE_SZ)
9 : //! - The tree is created in a bulk operation. Insert/deletion after creation
10 : //! is not supported
11 : //! - page-oriented
12 : //!
13 : //! TODO:
14 : //! - maybe something like an Adaptive Radix Tree would be more efficient?
15 : //! - the values stored by image and delta layers are offsets into the file,
16 : //! and they are in monotonically increasing order. Prefix compression would
17 : //! be very useful for them, too.
18 : //! - An Iterator interface would be more convenient for the callers than the
19 : //! 'visit' function
20 : //!
21 : use async_stream::try_stream;
22 : use byteorder::{ReadBytesExt, BE};
23 : use bytes::{BufMut, Bytes, BytesMut};
24 : use either::Either;
25 : use futures::{Stream, StreamExt};
26 : use hex;
27 : use std::{
28 : cmp::Ordering,
29 : io,
30 : iter::Rev,
31 : ops::{Range, RangeInclusive},
32 : result,
33 : };
34 : use thiserror::Error;
35 : use tracing::error;
36 :
37 : use crate::{
38 : context::{DownloadBehavior, RequestContext},
39 : task_mgr::TaskKind,
40 : tenant::block_io::{BlockReader, BlockWriter},
41 : };
42 :
43 : // The maximum size of a value stored in the B-tree. 5 bytes is enough currently.
44 : pub const VALUE_SZ: usize = 5;
45 : pub const MAX_VALUE: u64 = 0x007f_ffff_ffff;
46 :
47 : pub const PAGE_SZ: usize = 8192;
48 :
49 : #[derive(Clone, Copy, Debug)]
50 : struct Value([u8; VALUE_SZ]);
51 :
52 : impl Value {
53 7060118 : fn from_slice(slice: &[u8]) -> Value {
54 7060118 : let mut b = [0u8; VALUE_SZ];
55 7060118 : b.copy_from_slice(slice);
56 7060118 : Value(b)
57 7060118 : }
58 :
59 7218701 : fn from_u64(x: u64) -> Value {
60 7218701 : assert!(x <= 0x007f_ffff_ffff);
61 7218701 : Value([
62 7218701 : (x >> 32) as u8,
63 7218701 : (x >> 24) as u8,
64 7218701 : (x >> 16) as u8,
65 7218701 : (x >> 8) as u8,
66 7218701 : x as u8,
67 7218701 : ])
68 7218701 : }
69 :
70 12892 : fn from_blknum(x: u32) -> Value {
71 12892 : Value([
72 12892 : 0x80,
73 12892 : (x >> 24) as u8,
74 12892 : (x >> 16) as u8,
75 12892 : (x >> 8) as u8,
76 12892 : x as u8,
77 12892 : ])
78 12892 : }
79 :
80 : #[allow(dead_code)]
81 0 : fn is_offset(self) -> bool {
82 0 : self.0[0] & 0x80 != 0
83 0 : }
84 :
85 6428520 : fn to_u64(self) -> u64 {
86 6428520 : let b = &self.0;
87 6428520 : (b[0] as u64) << 32
88 6428520 : | (b[1] as u64) << 24
89 6428520 : | (b[2] as u64) << 16
90 6428520 : | (b[3] as u64) << 8
91 6428520 : | b[4] as u64
92 6428520 : }
93 :
94 625574 : fn to_blknum(self) -> u32 {
95 625574 : let b = &self.0;
96 625574 : assert!(b[0] == 0x80);
97 625574 : (b[1] as u32) << 24 | (b[2] as u32) << 16 | (b[3] as u32) << 8 | b[4] as u32
98 625574 : }
99 : }
100 :
101 0 : #[derive(Error, Debug)]
102 : pub enum DiskBtreeError {
103 : #[error("Attempt to append a value that is too large {0} > {}", MAX_VALUE)]
104 : AppendOverflow(u64),
105 :
106 : #[error("Unsorted input: key {key:?} is <= last_key {last_key:?}")]
107 : UnsortedInput { key: Box<[u8]>, last_key: Box<[u8]> },
108 :
109 : #[error("Could not push to new leaf node")]
110 : FailedToPushToNewLeafNode,
111 :
112 : #[error("IoError: {0}")]
113 : Io(#[from] io::Error),
114 : }
115 :
116 : pub type Result<T> = result::Result<T, DiskBtreeError>;
117 :
118 : /// This is the on-disk representation.
119 : struct OnDiskNode<'a, const L: usize> {
120 : // Fixed-width fields
121 : num_children: u16,
122 : level: u8,
123 : prefix_len: u8,
124 : suffix_len: u8,
125 :
126 : // Variable-length fields. These are stored on-disk after the fixed-width
127 : // fields, in this order. In the in-memory representation, these point to
128 : // the right parts in the page buffer.
129 : prefix: &'a [u8],
130 : keys: &'a [u8],
131 : values: &'a [u8],
132 : }
133 :
134 : impl<const L: usize> OnDiskNode<'_, L> {
135 : ///
136 : /// Interpret a PAGE_SZ page as a node.
137 : ///
138 1501869 : fn deparse(buf: &[u8]) -> Result<OnDiskNode<L>> {
139 1501869 : let mut cursor = std::io::Cursor::new(buf);
140 1501869 : let num_children = cursor.read_u16::<BE>()?;
141 1501869 : let level = cursor.read_u8()?;
142 1501869 : let prefix_len = cursor.read_u8()?;
143 1501869 : let suffix_len = cursor.read_u8()?;
144 :
145 1501869 : let mut off = cursor.position();
146 1501869 : let prefix_off = off as usize;
147 1501869 : off += prefix_len as u64;
148 1501869 :
149 1501869 : let keys_off = off as usize;
150 1501869 : let keys_len = num_children as usize * suffix_len as usize;
151 1501869 : off += keys_len as u64;
152 1501869 :
153 1501869 : let values_off = off as usize;
154 1501869 : let values_len = num_children as usize * VALUE_SZ;
155 1501869 : //off += values_len as u64;
156 1501869 :
157 1501869 : let prefix = &buf[prefix_off..prefix_off + prefix_len as usize];
158 1501869 : let keys = &buf[keys_off..keys_off + keys_len];
159 1501869 : let values = &buf[values_off..values_off + values_len];
160 1501869 :
161 1501869 : Ok(OnDiskNode {
162 1501869 : num_children,
163 1501869 : level,
164 1501869 : prefix_len,
165 1501869 : suffix_len,
166 1501869 : prefix,
167 1501869 : keys,
168 1501869 : values,
169 1501869 : })
170 1501869 : }
171 :
172 : ///
173 : /// Read a value at 'idx'
174 : ///
175 7060118 : fn value(&self, idx: usize) -> Value {
176 7060118 : let value_off = idx * VALUE_SZ;
177 7060118 : let value_slice = &self.values[value_off..value_off + VALUE_SZ];
178 7060118 : Value::from_slice(value_slice)
179 7060118 : }
180 :
181 1277872 : fn binary_search(
182 1277872 : &self,
183 1277872 : search_key: &[u8; L],
184 1277872 : keybuf: &mut [u8],
185 1277872 : ) -> result::Result<usize, usize> {
186 1277872 : let mut size = self.num_children as usize;
187 1277872 : let mut low = 0;
188 1277872 : let mut high = size;
189 9570407 : while low < high {
190 8520011 : let mid = low + size / 2;
191 8520011 :
192 8520011 : let key_off = mid * self.suffix_len as usize;
193 8520011 : let suffix = &self.keys[key_off..key_off + self.suffix_len as usize];
194 8520011 : // Does this match?
195 8520011 : keybuf[self.prefix_len as usize..].copy_from_slice(suffix);
196 8520011 :
197 8520011 : let cmp = keybuf[..].cmp(search_key);
198 8520011 :
199 8520011 : if cmp == Ordering::Less {
200 5381189 : low = mid + 1;
201 5381189 : } else if cmp == Ordering::Greater {
202 2911346 : high = mid;
203 2911346 : } else {
204 227476 : return Ok(mid);
205 : }
206 8292535 : size = high - low;
207 : }
208 1050396 : Err(low)
209 1277872 : }
210 : }
211 :
212 : ///
213 : /// Public reader object, to search the tree.
214 : ///
215 : #[derive(Clone)]
216 : pub struct DiskBtreeReader<R, const L: usize>
217 : where
218 : R: BlockReader,
219 : {
220 : start_blk: u32,
221 : root_blk: u32,
222 : reader: R,
223 : }
224 :
225 : #[derive(Clone, Copy, Debug, PartialEq, Eq)]
226 : pub enum VisitDirection {
227 : Forwards,
228 : Backwards,
229 : }
230 :
231 : impl<R, const L: usize> DiskBtreeReader<R, L>
232 : where
233 : R: BlockReader,
234 : {
235 240965 : pub fn new(start_blk: u32, root_blk: u32, reader: R) -> Self {
236 240965 : DiskBtreeReader {
237 240965 : start_blk,
238 240965 : root_blk,
239 240965 : reader,
240 240965 : }
241 240965 : }
242 :
243 : ///
244 : /// Read the value for given key. Returns the value, or None if it doesn't exist.
245 : ///
246 403087 : pub async fn get(&self, search_key: &[u8; L], ctx: &RequestContext) -> Result<Option<u64>> {
247 403087 : let mut result: Option<u64> = None;
248 403087 : self.visit(
249 403087 : search_key,
250 403087 : VisitDirection::Forwards,
251 403087 : |key, value| {
252 203063 : if key == search_key {
253 201057 : result = Some(value);
254 201057 : }
255 203063 : false
256 403087 : },
257 403087 : ctx,
258 403087 : )
259 0 : .await?;
260 403087 : Ok(result)
261 403087 : }
262 :
263 666 : pub fn iter<'a>(self, start_key: &'a [u8; L], ctx: &'a RequestContext) -> DiskBtreeIterator<'a>
264 666 : where
265 666 : R: 'a + Send,
266 666 : {
267 666 : DiskBtreeIterator {
268 666 : stream: Box::pin(self.into_stream(start_key, ctx)),
269 666 : }
270 666 : }
271 :
272 : /// Return a stream which yields all key, value pairs from the index
273 : /// starting from the first key greater or equal to `start_key`.
274 : ///
275 : /// Note 1: that this is a copy of [`Self::visit`].
276 : /// TODO: Once the sequential read path is removed this will become
277 : /// the only index traversal method.
278 : ///
279 : /// Note 2: this function used to take `&self` but it now consumes `self`. This is due to
280 : /// the lifetime constraints of the reader and the stream / iterator it creates. Using `&self`
281 : /// requires the reader to be present when the stream is used, and this creates a lifetime
282 : /// dependency between the reader and the stream. Now if we want to create an iterator that
283 : /// holds the stream, someone will need to keep a reference to the reader, which is inconvenient
284 : /// to use from the image/delta layer APIs.
285 : ///
286 : /// Feel free to add the `&self` variant back if it's necessary.
287 240759 : pub fn into_stream<'a>(
288 240759 : self,
289 240759 : start_key: &'a [u8; L],
290 240759 : ctx: &'a RequestContext,
291 240759 : ) -> impl Stream<Item = std::result::Result<(Vec<u8>, u64), DiskBtreeError>> + 'a
292 240759 : where
293 240759 : R: 'a,
294 240759 : {
295 240759 : try_stream! {
296 240759 : let mut stack = Vec::new();
297 240759 : stack.push((self.root_blk, None));
298 240759 : let block_cursor = self.reader.block_cursor();
299 240759 : let mut node_buf = [0_u8; PAGE_SZ];
300 240759 : while let Some((node_blknum, opt_iter)) = stack.pop() {
301 240759 : // Read the node, through the PS PageCache, into local variable `node_buf`.
302 240759 : // We could keep the page cache read guard alive, but, at the time of writing,
303 240759 : // we run quite small PS PageCache s => can't risk running out of
304 240759 : // PageCache space because this stream isn't consumed fast enough.
305 240759 : let page_read_guard = block_cursor
306 240759 : .read_blk(self.start_blk + node_blknum, ctx)
307 240759 : .await?;
308 240759 : node_buf.copy_from_slice(page_read_guard.as_ref());
309 240759 : drop(page_read_guard); // drop page cache read guard early
310 240759 :
311 240759 : let node = OnDiskNode::deparse(&node_buf)?;
312 240759 : let prefix_len = node.prefix_len as usize;
313 240759 : let suffix_len = node.suffix_len as usize;
314 240759 :
315 240759 : assert!(node.num_children > 0);
316 240759 :
317 240759 : let mut keybuf = Vec::new();
318 240759 : keybuf.extend(node.prefix);
319 240759 : keybuf.resize(prefix_len + suffix_len, 0);
320 240759 :
321 240759 : let mut iter: Either<Range<usize>, Rev<RangeInclusive<usize>>> = if let Some(iter) = opt_iter {
322 240759 : iter
323 240759 : } else {
324 240759 : // Locate the first match
325 240759 : let idx = match node.binary_search(start_key, keybuf.as_mut_slice()) {
326 240759 : Ok(idx) => idx,
327 240759 : Err(idx) => {
328 240759 : if node.level == 0 {
329 240759 : // Imagine that the node contains the following keys:
330 240759 : //
331 240759 : // 1
332 240759 : // 3 <-- idx
333 240759 : // 5
334 240759 : //
335 240759 : // If the search key is '2' and there is exact match,
336 240759 : // the binary search would return the index of key
337 240759 : // '3'. That's cool, '3' is the first key to return.
338 240759 : idx
339 240759 : } else {
340 240759 : // This is an internal page, so each key represents a lower
341 240759 : // bound for what's in the child page. If there is no exact
342 240759 : // match, we have to return the *previous* entry.
343 240759 : //
344 240759 : // 1 <-- return this
345 240759 : // 3 <-- idx
346 240759 : // 5
347 240759 : idx.saturating_sub(1)
348 240759 : }
349 240759 : }
350 240759 : };
351 240759 : Either::Left(idx..node.num_children.into())
352 240759 : };
353 240759 :
354 240759 :
355 240759 : // idx points to the first match now. Keep going from there
356 240759 : while let Some(idx) = iter.next() {
357 240759 : let key_off = idx * suffix_len;
358 240759 : let suffix = &node.keys[key_off..key_off + suffix_len];
359 240759 : keybuf[prefix_len..].copy_from_slice(suffix);
360 240759 : let value = node.value(idx);
361 240759 : #[allow(clippy::collapsible_if)]
362 240759 : if node.level == 0 {
363 240759 : // leaf
364 240759 : yield (keybuf.clone(), value.to_u64());
365 240759 : } else {
366 240759 : stack.push((node_blknum, Some(iter)));
367 240759 : stack.push((value.to_blknum(), None));
368 240759 : break;
369 240759 : }
370 240759 : }
371 240759 : }
372 240759 : }
373 240759 : }
374 :
375 : ///
376 : /// Scan the tree, starting from 'search_key', in the given direction. 'visitor'
377 : /// will be called for every key >= 'search_key' (or <= 'search_key', if scanning
378 : /// backwards)
379 : ///
380 411547 : pub async fn visit<V>(
381 411547 : &self,
382 411547 : search_key: &[u8; L],
383 411547 : dir: VisitDirection,
384 411547 : mut visitor: V,
385 411547 : ctx: &RequestContext,
386 411547 : ) -> Result<bool>
387 411547 : where
388 411547 : V: FnMut(&[u8], u64) -> bool,
389 411547 : {
390 411547 : let mut stack = Vec::new();
391 411547 : stack.push((self.root_blk, None));
392 411547 : let block_cursor = self.reader.block_cursor();
393 1218920 : while let Some((node_blknum, opt_iter)) = stack.pop() {
394 : // Locate the node.
395 1018386 : let node_buf = block_cursor
396 1018386 : .read_blk(self.start_blk + node_blknum, ctx)
397 2124 : .await?;
398 :
399 1018386 : let node = OnDiskNode::deparse(node_buf.as_ref())?;
400 1018386 : let prefix_len = node.prefix_len as usize;
401 1018386 : let suffix_len = node.suffix_len as usize;
402 1018386 :
403 1018386 : assert!(node.num_children > 0);
404 :
405 1018386 : let mut keybuf = Vec::new();
406 1018386 : keybuf.extend(node.prefix);
407 1018386 : keybuf.resize(prefix_len + suffix_len, 0);
408 :
409 1018386 : let mut iter = if let Some(iter) = opt_iter {
410 203898 : iter
411 814488 : } else if dir == VisitDirection::Forwards {
412 : // Locate the first match
413 810462 : let idx = match node.binary_search(search_key, keybuf.as_mut_slice()) {
414 203264 : Ok(idx) => idx,
415 607198 : Err(idx) => {
416 607198 : if node.level == 0 {
417 : // Imagine that the node contains the following keys:
418 : //
419 : // 1
420 : // 3 <-- idx
421 : // 5
422 : //
423 : // If the search key is '2' and there is exact match,
424 : // the binary search would return the index of key
425 : // '3'. That's cool, '3' is the first key to return.
426 208116 : idx
427 : } else {
428 : // This is an internal page, so each key represents a lower
429 : // bound for what's in the child page. If there is no exact
430 : // match, we have to return the *previous* entry.
431 : //
432 : // 1 <-- return this
433 : // 3 <-- idx
434 : // 5
435 399082 : idx.saturating_sub(1)
436 : }
437 : }
438 : };
439 810462 : Either::Left(idx..node.num_children.into())
440 : } else {
441 4026 : let idx = match node.binary_search(search_key, keybuf.as_mut_slice()) {
442 2002 : Ok(idx) => {
443 2002 : // Exact match. That's the first entry to return, and walk
444 2002 : // backwards from there.
445 2002 : idx
446 : }
447 2024 : Err(idx) => {
448 : // No exact match. The binary search returned the index of the
449 : // first key that's > search_key. Back off by one, and walk
450 : // backwards from there.
451 2024 : if let Some(idx) = idx.checked_sub(1) {
452 2020 : idx
453 : } else {
454 4 : return Ok(false);
455 : }
456 : }
457 : };
458 4022 : Either::Right((0..=idx).rev())
459 : };
460 :
461 : // idx points to the first match now. Keep going from there
462 3162336 : while let Some(idx) = iter.next() {
463 2757904 : let key_off = idx * suffix_len;
464 2757904 : let suffix = &node.keys[key_off..key_off + suffix_len];
465 2757904 : keybuf[prefix_len..].copy_from_slice(suffix);
466 2757904 : let value = node.value(idx);
467 2757904 : #[allow(clippy::collapsible_if)]
468 2757904 : if node.level == 0 {
469 : // leaf
470 2354963 : if !visitor(&keybuf, value.to_u64()) {
471 211009 : return Ok(false);
472 2143954 : }
473 : } else {
474 402941 : stack.push((node_blknum, Some(iter)));
475 402941 : stack.push((value.to_blknum(), None));
476 402941 : break;
477 : }
478 : }
479 : }
480 200534 : Ok(true)
481 411547 : }
482 :
483 : #[allow(dead_code)]
484 10 : pub async fn dump(&self) -> Result<()> {
485 10 : let mut stack = Vec::new();
486 10 : let ctx = RequestContext::new(TaskKind::DebugTool, DownloadBehavior::Error);
487 10 :
488 10 : stack.push((self.root_blk, String::new(), 0, 0, 0));
489 10 :
490 10 : let block_cursor = self.reader.block_cursor();
491 :
492 6042 : while let Some((blknum, path, depth, child_idx, key_off)) = stack.pop() {
493 6032 : let blk = block_cursor.read_blk(self.start_blk + blknum, &ctx).await?;
494 6032 : let buf: &[u8] = blk.as_ref();
495 6032 : let node = OnDiskNode::<L>::deparse(buf)?;
496 :
497 6032 : if child_idx == 0 {
498 18 : print!("{:indent$}", "", indent = depth * 2);
499 18 : let path_prefix = stack
500 18 : .iter()
501 18 : .map(|(_blknum, path, ..)| path.as_str())
502 18 : .collect::<String>();
503 18 : println!(
504 18 : "blk #{blknum}: path {path_prefix}{path}: prefix {}, suffix_len {}",
505 18 : hex::encode(node.prefix),
506 18 : node.suffix_len
507 18 : );
508 6014 : }
509 :
510 6032 : if child_idx + 1 < node.num_children {
511 6014 : let key_off = key_off + node.suffix_len as usize;
512 6014 : stack.push((blknum, path.clone(), depth, child_idx + 1, key_off));
513 6014 : }
514 6032 : let key = &node.keys[key_off..key_off + node.suffix_len as usize];
515 6032 : let val = node.value(child_idx as usize);
516 6032 :
517 6032 : print!("{:indent$}", "", indent = depth * 2 + 2);
518 6032 : println!("{}: {}", hex::encode(key), hex::encode(val.0));
519 6032 :
520 6032 : if node.level > 0 {
521 8 : stack.push((val.to_blknum(), hex::encode(node.prefix), depth + 1, 0, 0));
522 6024 : }
523 : }
524 10 : Ok(())
525 10 : }
526 : }
527 :
528 : pub struct DiskBtreeIterator<'a> {
529 : #[allow(clippy::type_complexity)]
530 : stream: std::pin::Pin<
531 : Box<dyn Stream<Item = std::result::Result<(Vec<u8>, u64), DiskBtreeError>> + 'a + Send>,
532 : >,
533 : }
534 :
535 : impl<'a> DiskBtreeIterator<'a> {
536 2323537 : pub async fn next(&mut self) -> Option<std::result::Result<(Vec<u8>, u64), DiskBtreeError>> {
537 2323537 : self.stream.next().await
538 2323537 : }
539 : }
540 :
541 : ///
542 : /// Public builder object, for creating a new tree.
543 : ///
544 : /// Usage: Create a builder object by calling 'new', load all the data into the
545 : /// tree by calling 'append' for each key-value pair, and then call 'finish'
546 : ///
547 : /// 'L' is the key length in bytes
548 : pub struct DiskBtreeBuilder<W, const L: usize>
549 : where
550 : W: BlockWriter,
551 : {
552 : writer: W,
553 :
554 : ///
555 : /// `stack[0]` is the current root page, `stack.last()` is the leaf.
556 : ///
557 : /// We maintain the length of the stack to be always greater than zero.
558 : /// Two exceptions are:
559 : /// 1. `Self::flush_node`. The method will push the new node if it extracted the last one.
560 : /// So because other methods cannot see the intermediate state invariant still holds.
561 : /// 2. `Self::finish`. It consumes self and does not return it back,
562 : /// which means that this is where the structure is destroyed.
563 : /// Thus stack of zero length cannot be observed by other methods.
564 : stack: Vec<BuildNode<L>>,
565 :
566 : /// Last key that was appended to the tree. Used to sanity check that append
567 : /// is called in increasing key order.
568 : last_key: Option<[u8; L]>,
569 : }
570 :
571 : impl<W, const L: usize> DiskBtreeBuilder<W, L>
572 : where
573 : W: BlockWriter,
574 : {
575 1968 : pub fn new(writer: W) -> Self {
576 1968 : DiskBtreeBuilder {
577 1968 : writer,
578 1968 : last_key: None,
579 1968 : stack: vec![BuildNode::new(0)],
580 1968 : }
581 1968 : }
582 :
583 7218703 : pub fn append(&mut self, key: &[u8; L], value: u64) -> Result<()> {
584 7218703 : if value > MAX_VALUE {
585 0 : return Err(DiskBtreeError::AppendOverflow(value));
586 7218703 : }
587 7218703 : if let Some(last_key) = &self.last_key {
588 7216917 : if key <= last_key {
589 2 : return Err(DiskBtreeError::UnsortedInput {
590 2 : key: key.as_slice().into(),
591 2 : last_key: last_key.as_slice().into(),
592 2 : });
593 7216915 : }
594 1786 : }
595 7218701 : self.last_key = Some(*key);
596 7218701 :
597 7218701 : self.append_internal(key, Value::from_u64(value))
598 7218703 : }
599 :
600 7231593 : fn append_internal(&mut self, key: &[u8; L], value: Value) -> Result<()> {
601 7231593 : // Try to append to the current leaf buffer
602 7231593 : let last = self
603 7231593 : .stack
604 7231593 : .last_mut()
605 7231593 : .expect("should always have at least one item");
606 7231593 : let level = last.level;
607 7231593 : if last.push(key, value) {
608 7207073 : return Ok(());
609 24520 : }
610 24520 :
611 24520 : // It did not fit. Try to compress, and if it succeeds to make
612 24520 : // some room on the node, try appending to it again.
613 24520 : #[allow(clippy::collapsible_if)]
614 24520 : if last.compress() {
615 12439 : if last.push(key, value) {
616 12426 : return Ok(());
617 13 : }
618 12081 : }
619 :
620 : // Could not append to the current leaf. Flush it and create a new one.
621 12094 : self.flush_node()?;
622 :
623 : // Replace the node we flushed with an empty one and append the new
624 : // key to it.
625 12094 : let mut last = BuildNode::new(level);
626 12094 : if !last.push(key, value) {
627 0 : return Err(DiskBtreeError::FailedToPushToNewLeafNode);
628 12094 : }
629 12094 :
630 12094 : self.stack.push(last);
631 12094 :
632 12094 : Ok(())
633 7231593 : }
634 :
635 : /// Flush the bottommost node in the stack to disk. Appends a downlink to its parent,
636 : /// and recursively flushes the parent too, if it becomes full. If the root page becomes full,
637 : /// creates a new root page, increasing the height of the tree.
638 12892 : fn flush_node(&mut self) -> Result<()> {
639 12892 : // Get the current bottommost node in the stack and flush it to disk.
640 12892 : let last = self
641 12892 : .stack
642 12892 : .pop()
643 12892 : .expect("should always have at least one item");
644 12892 : let buf = last.pack();
645 12892 : let downlink_key = last.first_key();
646 12892 : let downlink_ptr = self.writer.write_blk(buf)?;
647 :
648 : // Append the downlink to the parent. If there is no parent, ie. this was the root page,
649 : // create a new root page, increasing the height of the tree.
650 12892 : if self.stack.is_empty() {
651 798 : self.stack.push(BuildNode::new(last.level + 1));
652 12094 : }
653 12892 : self.append_internal(&downlink_key, Value::from_blknum(downlink_ptr))
654 12892 : }
655 :
656 : ///
657 : /// Flushes everything to disk, and returns the block number of the root page.
658 : /// The caller must store the root block number "out-of-band", and pass it
659 : /// to the DiskBtreeReader::new() when you want to read the tree again.
660 : /// (In the image and delta layers, it is stored in the beginning of the file,
661 : /// in the summary header)
662 : ///
663 1740 : pub fn finish(mut self) -> Result<(u32, W)> {
664 : // flush all levels, except the root.
665 2538 : while self.stack.len() > 1 {
666 798 : self.flush_node()?;
667 : }
668 :
669 1740 : let root = self
670 1740 : .stack
671 1740 : .first()
672 1740 : .expect("by the check above we left one item there");
673 1740 : let buf = root.pack();
674 1740 : let root_blknum = self.writer.write_blk(buf)?;
675 :
676 1740 : Ok((root_blknum, self.writer))
677 1740 : }
678 :
679 2047536 : pub fn borrow_writer(&self) -> &W {
680 2047536 : &self.writer
681 2047536 : }
682 : }
683 :
684 : ///
685 : /// BuildNode represesnts an incomplete page that we are appending to.
686 : ///
687 : #[derive(Clone, Debug)]
688 : struct BuildNode<const L: usize> {
689 : num_children: u16,
690 : level: u8,
691 : prefix: Vec<u8>,
692 : suffix_len: usize,
693 :
694 : keys: Vec<u8>,
695 : values: Vec<u8>,
696 :
697 : size: usize, // physical size of this node, if it was written to disk like this
698 : }
699 :
700 : const NODE_SIZE: usize = PAGE_SZ;
701 :
702 : const NODE_HDR_SIZE: usize = 2 + 1 + 1 + 1;
703 :
704 : impl<const L: usize> BuildNode<L> {
705 14860 : fn new(level: u8) -> Self {
706 14860 : BuildNode {
707 14860 : num_children: 0,
708 14860 : level,
709 14860 : prefix: Vec::new(),
710 14860 : suffix_len: 0,
711 14860 : keys: Vec::new(),
712 14860 : values: Vec::new(),
713 14860 : size: NODE_HDR_SIZE,
714 14860 : }
715 14860 : }
716 :
717 : /// Try to append a key-value pair to this node. Returns 'true' on
718 : /// success, 'false' if the page was full or the key was
719 : /// incompatible with the prefix of the existing keys.
720 7256126 : fn push(&mut self, key: &[u8; L], value: Value) -> bool {
721 7256126 : // If we have already performed prefix-compression on the page,
722 7256126 : // check that the incoming key has the same prefix.
723 7256126 : if self.num_children > 0 {
724 : // does the prefix allow it?
725 7241448 : if !key.starts_with(&self.prefix) {
726 231 : return false;
727 7241217 : }
728 14678 : } else {
729 14678 : self.suffix_len = key.len();
730 14678 : }
731 :
732 : // Is the node too full?
733 7255895 : if self.size + self.suffix_len + VALUE_SZ >= NODE_SIZE {
734 24302 : return false;
735 7231593 : }
736 7231593 :
737 7231593 : // All clear
738 7231593 : self.num_children += 1;
739 7231593 : self.keys.extend(&key[self.prefix.len()..]);
740 7231593 : self.values.extend(value.0);
741 7231593 :
742 7231593 : assert!(self.keys.len() == self.num_children as usize * self.suffix_len);
743 7231593 : assert!(self.values.len() == self.num_children as usize * VALUE_SZ);
744 :
745 7231593 : self.size += self.suffix_len + VALUE_SZ;
746 7231593 :
747 7231593 : true
748 7256126 : }
749 :
750 : ///
751 : /// Perform prefix-compression.
752 : ///
753 : /// Returns 'true' on success, 'false' if no compression was possible.
754 : ///
755 24520 : fn compress(&mut self) -> bool {
756 24520 : let first_suffix = self.first_suffix();
757 24520 : let last_suffix = self.last_suffix();
758 24520 :
759 24520 : // Find the common prefix among all keys
760 24520 : let mut prefix_len = 0;
761 222933 : while prefix_len < self.suffix_len {
762 222933 : if first_suffix[prefix_len] != last_suffix[prefix_len] {
763 24520 : break;
764 198413 : }
765 198413 : prefix_len += 1;
766 : }
767 24520 : if prefix_len == 0 {
768 12081 : return false;
769 12439 : }
770 12439 :
771 12439 : // Can compress. Rewrite the keys without the common prefix.
772 12439 : self.prefix.extend(&self.keys[..prefix_len]);
773 12439 :
774 12439 : let mut new_keys = Vec::new();
775 12439 : let mut key_off = 0;
776 3364938 : while key_off < self.keys.len() {
777 3352499 : let next_key_off = key_off + self.suffix_len;
778 3352499 : new_keys.extend(&self.keys[key_off + prefix_len..next_key_off]);
779 3352499 : key_off = next_key_off;
780 3352499 : }
781 12439 : self.keys = new_keys;
782 12439 : self.suffix_len -= prefix_len;
783 12439 :
784 12439 : self.size -= prefix_len * self.num_children as usize;
785 12439 : self.size += prefix_len;
786 12439 :
787 12439 : assert!(self.keys.len() == self.num_children as usize * self.suffix_len);
788 12439 : assert!(self.values.len() == self.num_children as usize * VALUE_SZ);
789 :
790 12439 : true
791 24520 : }
792 :
793 : ///
794 : /// Serialize the node to on-disk format.
795 : ///
796 14632 : fn pack(&self) -> Bytes {
797 14632 : assert!(self.keys.len() == self.num_children as usize * self.suffix_len);
798 14632 : assert!(self.values.len() == self.num_children as usize * VALUE_SZ);
799 14632 : assert!(self.num_children > 0);
800 :
801 14632 : let mut buf = BytesMut::new();
802 14632 :
803 14632 : buf.put_u16(self.num_children);
804 14632 : buf.put_u8(self.level);
805 14632 : buf.put_u8(self.prefix.len() as u8);
806 14632 : buf.put_u8(self.suffix_len as u8);
807 14632 : buf.put(&self.prefix[..]);
808 14632 : buf.put(&self.keys[..]);
809 14632 : buf.put(&self.values[..]);
810 14632 :
811 14632 : assert!(buf.len() == self.size);
812 :
813 14632 : assert!(buf.len() <= PAGE_SZ);
814 14632 : buf.resize(PAGE_SZ, 0);
815 14632 : buf.freeze()
816 14632 : }
817 :
818 37412 : fn first_suffix(&self) -> &[u8] {
819 37412 : &self.keys[..self.suffix_len]
820 37412 : }
821 24520 : fn last_suffix(&self) -> &[u8] {
822 24520 : &self.keys[self.keys.len() - self.suffix_len..]
823 24520 : }
824 :
825 : /// Return the full first key of the page, including the prefix
826 12892 : fn first_key(&self) -> [u8; L] {
827 12892 : let mut key = [0u8; L];
828 12892 : key[..self.prefix.len()].copy_from_slice(&self.prefix);
829 12892 : key[self.prefix.len()..].copy_from_slice(self.first_suffix());
830 12892 : key
831 12892 : }
832 : }
833 :
834 : #[cfg(test)]
835 : pub(crate) mod tests {
836 : use super::*;
837 : use crate::tenant::block_io::{BlockCursor, BlockLease, BlockReaderRef};
838 : use rand::Rng;
839 : use std::collections::BTreeMap;
840 : use std::sync::atomic::{AtomicUsize, Ordering};
841 :
842 : #[derive(Clone, Default)]
843 : pub(crate) struct TestDisk {
844 : blocks: Vec<Bytes>,
845 : }
846 : impl TestDisk {
847 10 : fn new() -> Self {
848 10 : Self::default()
849 10 : }
850 1016628 : pub(crate) fn read_blk(&self, blknum: u32) -> io::Result<BlockLease> {
851 1016628 : let mut buf = [0u8; PAGE_SZ];
852 1016628 : buf.copy_from_slice(&self.blocks[blknum as usize]);
853 1016628 : Ok(std::sync::Arc::new(buf).into())
854 1016628 : }
855 : }
856 : impl BlockReader for TestDisk {
857 411153 : fn block_cursor(&self) -> BlockCursor<'_> {
858 411153 : BlockCursor::new(BlockReaderRef::TestDisk(self))
859 411153 : }
860 : }
861 : impl BlockWriter for &mut TestDisk {
862 215 : fn write_blk(&mut self, buf: Bytes) -> io::Result<u32> {
863 215 : let blknum = self.blocks.len();
864 215 : self.blocks.push(buf);
865 215 : Ok(blknum as u32)
866 215 : }
867 : }
868 :
869 : #[tokio::test]
870 2 : async fn basic() -> Result<()> {
871 2 : let mut disk = TestDisk::new();
872 2 : let mut writer = DiskBtreeBuilder::<_, 6>::new(&mut disk);
873 2 :
874 2 : let ctx = RequestContext::new(TaskKind::UnitTest, DownloadBehavior::Error);
875 2 :
876 2 : let all_keys: Vec<&[u8; 6]> = vec![
877 2 : b"xaaaaa", b"xaaaba", b"xaaaca", b"xabaaa", b"xababa", b"xabaca", b"xabada", b"xabadb",
878 2 : ];
879 2 : let all_data: Vec<(&[u8; 6], u64)> = all_keys
880 2 : .iter()
881 2 : .enumerate()
882 16 : .map(|(idx, key)| (*key, idx as u64))
883 2 : .collect();
884 16 : for (key, val) in all_data.iter() {
885 16 : writer.append(key, *val)?;
886 2 : }
887 2 :
888 2 : let (root_offset, _writer) = writer.finish()?;
889 2 :
890 2 : let reader = DiskBtreeReader::new(0, root_offset, disk);
891 2 :
892 2 : reader.dump().await?;
893 2 :
894 2 : // Test the `get` function on all the keys.
895 16 : for (key, val) in all_data.iter() {
896 16 : assert_eq!(reader.get(key, &ctx).await?, Some(*val));
897 2 : }
898 2 : // And on some keys that don't exist
899 2 : assert_eq!(reader.get(b"aaaaaa", &ctx).await?, None);
900 2 : assert_eq!(reader.get(b"zzzzzz", &ctx).await?, None);
901 2 : assert_eq!(reader.get(b"xaaabx", &ctx).await?, None);
902 2 :
903 2 : // Test search with `visit` function
904 2 : let search_key = b"xabaaa";
905 2 : let expected: Vec<(Vec<u8>, u64)> = all_data
906 2 : .iter()
907 16 : .filter(|(key, _value)| key[..] >= search_key[..])
908 10 : .map(|(key, value)| (key.to_vec(), *value))
909 2 : .collect();
910 2 :
911 2 : let mut data = Vec::new();
912 2 : reader
913 2 : .visit(
914 2 : search_key,
915 2 : VisitDirection::Forwards,
916 10 : |key, value| {
917 10 : data.push((key.to_vec(), value));
918 10 : true
919 10 : },
920 2 : &ctx,
921 2 : )
922 2 : .await?;
923 2 : assert_eq!(data, expected);
924 2 :
925 2 : // Test a backwards scan
926 2 : let mut expected: Vec<(Vec<u8>, u64)> = all_data
927 2 : .iter()
928 16 : .filter(|(key, _value)| key[..] <= search_key[..])
929 8 : .map(|(key, value)| (key.to_vec(), *value))
930 2 : .collect();
931 2 : expected.reverse();
932 2 : let mut data = Vec::new();
933 2 : reader
934 2 : .visit(
935 2 : search_key,
936 2 : VisitDirection::Backwards,
937 8 : |key, value| {
938 8 : data.push((key.to_vec(), value));
939 8 : true
940 8 : },
941 2 : &ctx,
942 2 : )
943 2 : .await?;
944 2 : assert_eq!(data, expected);
945 2 :
946 2 : // Backward scan where nothing matches
947 2 : reader
948 2 : .visit(
949 2 : b"aaaaaa",
950 2 : VisitDirection::Backwards,
951 2 : |key, value| {
952 0 : panic!("found unexpected key {}: {}", hex::encode(key), value);
953 2 : },
954 2 : &ctx,
955 2 : )
956 2 : .await?;
957 2 :
958 2 : // Full scan
959 2 : let expected: Vec<(Vec<u8>, u64)> = all_data
960 2 : .iter()
961 16 : .map(|(key, value)| (key.to_vec(), *value))
962 2 : .collect();
963 2 : let mut data = Vec::new();
964 2 : reader
965 2 : .visit(
966 2 : &[0u8; 6],
967 2 : VisitDirection::Forwards,
968 16 : |key, value| {
969 16 : data.push((key.to_vec(), value));
970 16 : true
971 16 : },
972 2 : &ctx,
973 2 : )
974 2 : .await?;
975 2 : assert_eq!(data, expected);
976 2 :
977 2 : Ok(())
978 2 : }
979 :
980 : #[tokio::test]
981 2 : async fn lots_of_keys() -> Result<()> {
982 2 : let mut disk = TestDisk::new();
983 2 : let mut writer = DiskBtreeBuilder::<_, 8>::new(&mut disk);
984 2 : let ctx = RequestContext::new(TaskKind::UnitTest, DownloadBehavior::Error);
985 2 :
986 2 : const NUM_KEYS: u64 = 1000;
987 2 :
988 2 : let mut all_data: BTreeMap<u64, u64> = BTreeMap::new();
989 2 :
990 2002 : for idx in 0..NUM_KEYS {
991 2000 : let key_int: u64 = 1 + idx * 2;
992 2000 : let key = u64::to_be_bytes(key_int);
993 2000 : writer.append(&key, idx)?;
994 2 :
995 2000 : all_data.insert(key_int, idx);
996 2 : }
997 2 :
998 2 : let (root_offset, _writer) = writer.finish()?;
999 2 :
1000 2 : let reader = DiskBtreeReader::new(0, root_offset, disk);
1001 2 :
1002 2 : reader.dump().await?;
1003 2 :
1004 2 : use std::sync::Mutex;
1005 2 :
1006 2 : let result = Mutex::new(Vec::new());
1007 2 : let limit: AtomicUsize = AtomicUsize::new(10);
1008 83820 : let take_ten = |key: &[u8], value: u64| {
1009 83820 : let mut keybuf = [0u8; 8];
1010 83820 : keybuf.copy_from_slice(key);
1011 83820 : let key_int = u64::from_be_bytes(keybuf);
1012 83820 :
1013 83820 : let mut result = result.lock().unwrap();
1014 83820 : result.push((key_int, value));
1015 83820 :
1016 83820 : // keep going until we have 10 matches
1017 83820 : result.len() < limit.load(Ordering::Relaxed)
1018 83820 : };
1019 2 :
1020 4020 : for search_key_int in 0..(NUM_KEYS * 2 + 10) {
1021 4020 : let search_key = u64::to_be_bytes(search_key_int);
1022 4020 : assert_eq!(
1023 4020 : reader.get(&search_key, &ctx).await?,
1024 4020 : all_data.get(&search_key_int).cloned()
1025 2 : );
1026 2 :
1027 2 : // Test a forward scan starting with this key
1028 4020 : result.lock().unwrap().clear();
1029 4020 : reader
1030 4020 : .visit(&search_key, VisitDirection::Forwards, take_ten, &ctx)
1031 2 : .await?;
1032 4020 : let expected = all_data
1033 4020 : .range(search_key_int..)
1034 4020 : .take(10)
1035 39820 : .map(|(&key, &val)| (key, val))
1036 4020 : .collect::<Vec<(u64, u64)>>();
1037 4020 : assert_eq!(*result.lock().unwrap(), expected);
1038 2 :
1039 2 : // And a backwards scan
1040 4020 : result.lock().unwrap().clear();
1041 4020 : reader
1042 4020 : .visit(&search_key, VisitDirection::Backwards, take_ten, &ctx)
1043 2 : .await?;
1044 4020 : let expected = all_data
1045 4020 : .range(..=search_key_int)
1046 4020 : .rev()
1047 4020 : .take(10)
1048 40000 : .map(|(&key, &val)| (key, val))
1049 4020 : .collect::<Vec<(u64, u64)>>();
1050 4020 : assert_eq!(*result.lock().unwrap(), expected);
1051 2 : }
1052 2 :
1053 2 : // full scan
1054 2 : let search_key = u64::to_be_bytes(0);
1055 2 : limit.store(usize::MAX, Ordering::Relaxed);
1056 2 : result.lock().unwrap().clear();
1057 2 : reader
1058 2 : .visit(&search_key, VisitDirection::Forwards, take_ten, &ctx)
1059 2 : .await?;
1060 2 : let expected = all_data
1061 2 : .iter()
1062 2000 : .map(|(&key, &val)| (key, val))
1063 2 : .collect::<Vec<(u64, u64)>>();
1064 2 : assert_eq!(*result.lock().unwrap(), expected);
1065 2 :
1066 2 : // full scan
1067 2 : let search_key = u64::to_be_bytes(u64::MAX);
1068 2 : limit.store(usize::MAX, Ordering::Relaxed);
1069 2 : result.lock().unwrap().clear();
1070 2 : reader
1071 2 : .visit(&search_key, VisitDirection::Backwards, take_ten, &ctx)
1072 2 : .await?;
1073 2 : let expected = all_data
1074 2 : .iter()
1075 2 : .rev()
1076 2000 : .map(|(&key, &val)| (key, val))
1077 2 : .collect::<Vec<(u64, u64)>>();
1078 2 : assert_eq!(*result.lock().unwrap(), expected);
1079 2 :
1080 2 : Ok(())
1081 2 : }
1082 :
1083 : #[tokio::test]
1084 2 : async fn random_data() -> Result<()> {
1085 2 : let ctx = RequestContext::new(TaskKind::UnitTest, DownloadBehavior::Error);
1086 2 :
1087 2 : // Generate random keys with exponential distribution, to
1088 2 : // exercise the prefix compression
1089 2 : const NUM_KEYS: usize = 100000;
1090 2 : let mut all_data: BTreeMap<u128, u64> = BTreeMap::new();
1091 200002 : for idx in 0..NUM_KEYS {
1092 200000 : let u: f64 = rand::thread_rng().gen_range(0.0..1.0);
1093 200000 : let t = -(f64::ln(u));
1094 200000 : let key_int = (t * 1000000.0) as u128;
1095 200000 :
1096 200000 : all_data.insert(key_int, idx as u64);
1097 200000 : }
1098 2 :
1099 2 : // Build a tree from it
1100 2 : let mut disk = TestDisk::new();
1101 2 : let mut writer = DiskBtreeBuilder::<_, 16>::new(&mut disk);
1102 2 :
1103 195041 : for (&key, &val) in all_data.iter() {
1104 195041 : writer.append(&u128::to_be_bytes(key), val)?;
1105 2 : }
1106 2 : let (root_offset, _writer) = writer.finish()?;
1107 2 :
1108 2 : let reader = DiskBtreeReader::new(0, root_offset, disk);
1109 2 :
1110 2 : // Test get() operation on all the keys
1111 195041 : for (&key, &val) in all_data.iter() {
1112 195041 : let search_key = u128::to_be_bytes(key);
1113 195041 : assert_eq!(reader.get(&search_key, &ctx).await?, Some(val));
1114 2 : }
1115 2 :
1116 2 : // Test get() operations on random keys, most of which will not exist
1117 200002 : for _ in 0..100000 {
1118 200000 : let key_int = rand::thread_rng().gen::<u128>();
1119 200000 : let search_key = u128::to_be_bytes(key_int);
1120 200000 : assert!(reader.get(&search_key, &ctx).await? == all_data.get(&key_int).cloned());
1121 2 : }
1122 2 :
1123 2 : // Test boundary cases
1124 2 : assert!(
1125 2 : reader.get(&u128::to_be_bytes(u128::MIN), &ctx).await?
1126 2 : == all_data.get(&u128::MIN).cloned()
1127 2 : );
1128 2 : assert!(
1129 2 : reader.get(&u128::to_be_bytes(u128::MAX), &ctx).await?
1130 2 : == all_data.get(&u128::MAX).cloned()
1131 2 : );
1132 2 :
1133 2 : // Test iterator and get_stream API
1134 2 : let mut iter = reader.iter(&[0; 16], &ctx);
1135 2 : let mut cnt = 0;
1136 195043 : while let Some(res) = iter.next().await {
1137 195041 : let (key, val) = res?;
1138 195041 : let key = u128::from_be_bytes(key.as_slice().try_into().unwrap());
1139 195041 : assert_eq!(val, *all_data.get(&key).unwrap());
1140 195041 : cnt += 1;
1141 2 : }
1142 2 : assert_eq!(cnt, all_data.len());
1143 2 :
1144 2 : Ok(())
1145 2 : }
1146 :
1147 : #[test]
1148 2 : fn unsorted_input() {
1149 2 : let mut disk = TestDisk::new();
1150 2 : let mut writer = DiskBtreeBuilder::<_, 2>::new(&mut disk);
1151 2 :
1152 2 : let _ = writer.append(b"ba", 1);
1153 2 : let _ = writer.append(b"bb", 2);
1154 2 : let err = writer.append(b"aa", 3).expect_err("should've failed");
1155 2 : match err {
1156 2 : DiskBtreeError::UnsortedInput { key, last_key } => {
1157 2 : assert_eq!(key.as_ref(), b"aa".as_slice());
1158 2 : assert_eq!(last_key.as_ref(), b"bb".as_slice());
1159 : }
1160 0 : _ => panic!("unexpected error variant, expected DiskBtreeError::UnsortedInput"),
1161 : }
1162 2 : }
1163 :
1164 : ///
1165 : /// This test contains a particular data set, see disk_btree_test_data.rs
1166 : ///
1167 : #[tokio::test]
1168 2 : async fn particular_data() -> Result<()> {
1169 2 : // Build a tree from it
1170 2 : let mut disk = TestDisk::new();
1171 2 : let mut writer = DiskBtreeBuilder::<_, 26>::new(&mut disk);
1172 2 : let ctx = RequestContext::new(TaskKind::UnitTest, DownloadBehavior::Error);
1173 2 :
1174 4002 : for (key, val) in disk_btree_test_data::TEST_DATA {
1175 4000 : writer.append(&key, val)?;
1176 2 : }
1177 2 : let (root_offset, writer) = writer.finish()?;
1178 2 :
1179 2 : println!("SIZE: {} blocks", writer.blocks.len());
1180 2 :
1181 2 : let reader = DiskBtreeReader::new(0, root_offset, disk);
1182 2 :
1183 2 : // Test get() operation on all the keys
1184 4002 : for (key, val) in disk_btree_test_data::TEST_DATA {
1185 4000 : assert_eq!(reader.get(&key, &ctx).await?, Some(val));
1186 2 : }
1187 2 :
1188 2 : // Test full scan
1189 2 : let mut count = 0;
1190 2 : reader
1191 2 : .visit(
1192 2 : &[0u8; 26],
1193 2 : VisitDirection::Forwards,
1194 4000 : |_key, _value| {
1195 4000 : count += 1;
1196 4000 : true
1197 4000 : },
1198 2 : &ctx,
1199 2 : )
1200 2 : .await?;
1201 2 : assert_eq!(count, disk_btree_test_data::TEST_DATA.len());
1202 2 :
1203 2 : reader.dump().await?;
1204 2 :
1205 2 : Ok(())
1206 2 : }
1207 : }
1208 :
1209 : #[cfg(test)]
1210 : #[path = "disk_btree_test_data.rs"]
1211 : mod disk_btree_test_data;
|