From 3cecf09d591e6cce4757611e47dc7075290fbe65 Mon Sep 17 00:00:00 2001 From: Alex Chi Date: Mon, 29 Jan 2024 21:19:18 +0800 Subject: [PATCH] add interface on watermark Signed-off-by: Alex Chi --- mini-lsm-book/src/week3-04-watermark.md | 4 +++- mini-lsm-book/src/week3-06-serializable.md | 6 +++++- mini-lsm-mvcc/src/mvcc/watermark.rs | 4 ++++ 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/mini-lsm-book/src/week3-04-watermark.md b/mini-lsm-book/src/week3-04-watermark.md index 2d001f7..e7f7579 100644 --- a/mini-lsm-book/src/week3-04-watermark.md +++ b/mini-lsm-book/src/week3-04-watermark.md @@ -2,7 +2,9 @@ ## Task 1: Implement Watermark -## Task 2: Garbage Collection in Compaction +## Task 2: Maintain Watermark in Transactions + +## Task 3: Garbage Collection in Compaction {{#include copyright.md}} diff --git a/mini-lsm-book/src/week3-06-serializable.md b/mini-lsm-book/src/week3-06-serializable.md index 43708ff..975b50f 100644 --- a/mini-lsm-book/src/week3-06-serializable.md +++ b/mini-lsm-book/src/week3-06-serializable.md @@ -8,8 +8,12 @@ ## Test Your Understanding -* If you have some experience with building a relational database, you may think about the following question: assume that we build a database based on Mini-LSM where we store each row in the relation table as a key-value pair and enable serializable verification, does the database system directly get ANSI serializable isolation level capability? Why or why not? +* If you have some experience with building a relational database, you may think about the following question: assume that we build a database based on Mini-LSM where we store each row in the relation table as a key-value pair (key: primary key, value: serialized row) and enable serializable verification, does the database system directly gain ANSI serializable isolation level capability? Why or why not? We do not provide reference answers to the questions, and feel free to discuss about them in the Discord community. +## Bonus Tasks + +* **Read-Only Transactions.** + {{#include copyright.md}} diff --git a/mini-lsm-mvcc/src/mvcc/watermark.rs b/mini-lsm-mvcc/src/mvcc/watermark.rs index dc7fe07..069ed4f 100644 --- a/mini-lsm-mvcc/src/mvcc/watermark.rs +++ b/mini-lsm-mvcc/src/mvcc/watermark.rs @@ -23,6 +23,10 @@ impl Watermark { } } + pub fn num_retained_snapshots(&self) -> usize { + self.readers.len() + } + pub fn watermark(&self) -> Option { self.readers.first_key_value().map(|(ts, _)| *ts) }