Files
mini_lsm/mini-lsm-starter/src/mvcc/txn.rs
Alex Chi Z. 1d9693c22f feat: bump to Rust edition 2024 (#132)
* feat: bump to Rust edition 2024

Signed-off-by: Alex Chi <iskyzh@gmail.com>

* allow deadcode

Signed-off-by: Alex Chi <iskyzh@gmail.com>

* fix deploy to pages

Signed-off-by: Alex Chi <iskyzh@gmail.com>

* fix fmt

Signed-off-by: Alex Chi <iskyzh@gmail.com>

* update actions

Signed-off-by: Alex Chi <iskyzh@gmail.com>

---------

Signed-off-by: Alex Chi <iskyzh@gmail.com>
2025-03-09 16:11:52 -04:00

146 lines
3.6 KiB
Rust

// Copyright (c) 2022-2025 Alex Chi Z
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#![allow(unused_variables)] // TODO(you): remove this lint after implementing this mod
#![allow(dead_code)] // TODO(you): remove this lint after implementing this mod
use std::{
collections::HashSet,
ops::Bound,
sync::{Arc, atomic::AtomicBool},
};
use anyhow::Result;
use bytes::Bytes;
use crossbeam_skiplist::SkipMap;
use ouroboros::self_referencing;
use parking_lot::Mutex;
use crate::{
iterators::{StorageIterator, two_merge_iterator::TwoMergeIterator},
lsm_iterator::{FusedIterator, LsmIterator},
lsm_storage::LsmStorageInner,
};
pub struct Transaction {
pub(crate) read_ts: u64,
pub(crate) inner: Arc<LsmStorageInner>,
pub(crate) local_storage: Arc<SkipMap<Bytes, Bytes>>,
pub(crate) committed: Arc<AtomicBool>,
/// Write set and read set
pub(crate) key_hashes: Option<Mutex<(HashSet<u32>, HashSet<u32>)>>,
}
impl Transaction {
pub fn get(&self, key: &[u8]) -> Result<Option<Bytes>> {
unimplemented!()
}
pub fn scan(self: &Arc<Self>, lower: Bound<&[u8]>, upper: Bound<&[u8]>) -> Result<TxnIterator> {
unimplemented!()
}
pub fn put(&self, key: &[u8], value: &[u8]) {
unimplemented!()
}
pub fn delete(&self, key: &[u8]) {
unimplemented!()
}
pub fn commit(&self) -> Result<()> {
unimplemented!()
}
}
impl Drop for Transaction {
fn drop(&mut self) {}
}
type SkipMapRangeIter<'a> =
crossbeam_skiplist::map::Range<'a, Bytes, (Bound<Bytes>, Bound<Bytes>), Bytes, Bytes>;
#[self_referencing]
pub struct TxnLocalIterator {
/// Stores a reference to the skipmap.
map: Arc<SkipMap<Bytes, Bytes>>,
/// Stores a skipmap iterator that refers to the lifetime of `TxnLocalIterator` itself.
#[borrows(map)]
#[not_covariant]
iter: SkipMapRangeIter<'this>,
/// Stores the current key-value pair.
item: (Bytes, Bytes),
}
impl StorageIterator for TxnLocalIterator {
type KeyType<'a> = &'a [u8];
fn value(&self) -> &[u8] {
unimplemented!()
}
fn key(&self) -> &[u8] {
unimplemented!()
}
fn is_valid(&self) -> bool {
unimplemented!()
}
fn next(&mut self) -> Result<()> {
unimplemented!()
}
}
pub struct TxnIterator {
_txn: Arc<Transaction>,
iter: TwoMergeIterator<TxnLocalIterator, FusedIterator<LsmIterator>>,
}
impl TxnIterator {
pub fn create(
txn: Arc<Transaction>,
iter: TwoMergeIterator<TxnLocalIterator, FusedIterator<LsmIterator>>,
) -> Result<Self> {
unimplemented!()
}
}
impl StorageIterator for TxnIterator {
type KeyType<'a>
= &'a [u8]
where
Self: 'a;
fn value(&self) -> &[u8] {
self.iter.value()
}
fn key(&self) -> Self::KeyType<'_> {
self.iter.key()
}
fn is_valid(&self) -> bool {
self.iter.is_valid()
}
fn next(&mut self) -> Result<()> {
unimplemented!()
}
fn num_active_iterators(&self) -> usize {
self.iter.num_active_iterators()
}
}