Skip to content

Commit

Permalink
Improve code
Browse files Browse the repository at this point in the history
  • Loading branch information
lewiszlw committed Mar 22, 2024
1 parent 1f13399 commit 2958819
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 11 deletions.
8 changes: 2 additions & 6 deletions bustubx/src/execution/physical_plan/values.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
use std::sync::atomic::AtomicU32;
use std::sync::Arc;
use std::sync::atomic::{AtomicU32, Ordering};

use crate::catalog::SchemaRef;
use crate::common::ScalarValue;
use crate::expression::{Expr, ExprTrait};
use crate::storage::EMPTY_TUPLE;
use crate::{
catalog::Schema,
execution::{ExecutionContext, VolcanoExecutor},
storage::Tuple,
BustubxResult,
Expand All @@ -30,9 +28,7 @@ impl PhysicalValues {
}
impl VolcanoExecutor for PhysicalValues {
fn next(&self, _context: &mut ExecutionContext) -> BustubxResult<Option<Tuple>> {
let cursor = self
.cursor
.fetch_add(1, std::sync::atomic::Ordering::SeqCst) as usize;
let cursor = self.cursor.fetch_add(1, Ordering::SeqCst) as usize;
if cursor < self.rows.len() {
let values = self.rows[cursor]
.iter()
Expand Down
3 changes: 0 additions & 3 deletions bustubx/src/storage/page/index_page.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,9 +125,6 @@ impl BPlusTreeInternalPage {

// TODO 可以通过二分查找来插入
pub fn insert(&mut self, key: Tuple, page_id: PageId) {
// if self.header.current_size == 0 && !key.is_null() {
// panic!("First key must be zero");
// }
self.array.push((key, page_id));
self.header.current_size += 1;
// 跳过第一个空key
Expand Down
2 changes: 0 additions & 2 deletions bustubx/src/transaction/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,4 @@ mod lock_manager;
mod transaction;
mod transaction_manager;

pub type TransactionId = u64;

pub use transaction::*;
32 changes: 32 additions & 0 deletions bustubx/src/transaction/transaction.rs
Original file line number Diff line number Diff line change
@@ -1 +1,33 @@
use crate::Tuple;

pub type TransactionId = u64;
pub const INVALID_TRANSACTION_ID: TransactionId = 0;

pub enum TransactionState {
Running,
Tainted,
Committed,
Aborted,
}

pub struct Transaction {}

/// Represents a link to a previous version of this tuple
pub struct UndoLink {
prev_txn: TransactionId,
prev_log_idx: u32,
}

impl UndoLink {
pub fn is_valid(&self) -> bool {
self.prev_txn != INVALID_TRANSACTION_ID
}
}

pub struct UndoLog {
is_deleted: bool,
modified_fields: Vec<bool>,
tuple: Tuple,
timestamp: u64,
prev_version: UndoLink,
}

0 comments on commit 2958819

Please sign in to comment.