Skip to main content

Transaction

Struct Transaction 

Source
pub struct Transaction<'a, S: TxState> { /* private fields */ }
Expand description

Typestate Transaction

Active 상태에서만 쿼리/쓰기가 가능하며, commit/rollback 후에는 컴파일 타임에 사용 불가.

Implementations§

Source§

impl<'a> Transaction<'a, Active>

Source

pub fn query<T: FromRow>(&self, sql: impl Into<String>) -> Query<'_, T>

SELECT 쿼리 — 여러 행 반환

Source

pub fn query_one<T: FromRow>(&self, sql: impl Into<String>) -> QueryOne<'_, T>

SELECT 쿼리 — 단일 행 반환 (없으면 에러)

Source

pub fn query_optional<T: FromRow>( &self, sql: impl Into<String>, ) -> QueryOptional<'_, T>

SELECT 쿼리 — 단일 행 반환 (없으면 None)

Source

pub fn query_scalar<T: FromScalar>( &self, sql: impl Into<String>, ) -> QueryScalar<'_, T>

SELECT 쿼리 — 단일 스칼라 값 반환

Source

pub fn execute(&self, sql: impl Into<String>) -> Execute<'_>

INSERT/UPDATE/DELETE — 영향받은 행 수 반환

Source

pub fn insert(&mut self, table: &str, key: &[u8], value: &[u8]) -> DbxResult<()>

트랜잭션 내 INSERT — 로컬 버퍼에 저장 (commit 전까지 미반영)

Source

pub fn insert_batch( &mut self, table: &str, rows: Vec<(Vec<u8>, Vec<u8>)>, ) -> DbxResult<()>

트랜잭션 내 BATCH INSERT — 여러 키-값 쌍을 일괄 삽입 (최적화됨)

Source

pub fn delete(&mut self, table: &str, key: &[u8]) -> DbxResult<bool>

트랜잭션 내 DELETE — 로컬 버퍼에 tombstone 기록

Source

pub fn get(&self, table: &str, key: &[u8]) -> DbxResult<Option<Vec<u8>>>

트랜잭션 내 GET — 로컬 버퍼 우선, 없으면 메인 스토리지 조회

Source

pub fn pending_ops(&self) -> usize

현재 트랜잭션의 보류 중인 연산 개수

Source

pub fn commit(self) -> DbxResult<Transaction<'a, Committed>>

트랜잭션 커밋 — 모든 버퍼링된 쓰기를 메인 스토리지에 원자적으로 반영

§MVCC Dual-Write 전략

이 구현은 MVCC versioned key와 일반 key를 모두 저장하는 dual-write 전략을 사용합니다:

  1. insert_versioned(): MVCC 타임스탬프가 포함된 versioned key로 저장

    • 향후 snapshot isolation, time-travel query 지원
    • 버전 히스토리 추적 가능
  2. insert(): 일반 key로도 저장

    • get() 메서드와의 backward compatibility 보장
    • Fast-path 조회 성능 유지
    • 기존 코드와의 호환성 확보

이 전략은 약간의 저장 공간 오버헤드가 있지만, 다음 이점을 제공합니다:

  • 기존 CRUD API와 완벽한 호환성
  • MVCC 기능을 점진적으로 활성화 가능
  • 성능 저하 없이 transaction isolation 지원
Source

pub fn rollback(self) -> DbxResult<Transaction<'a, RolledBack>>

트랜잭션 롤백 — 모든 버퍼링된 쓰기를 폐기

Source§

impl<'a> Transaction<'a, Committed>

Source

pub fn is_committed(&self) -> bool

커밋된 트랜잭션은 더 이상 사용할 수 없음

Source§

impl<'a> Transaction<'a, RolledBack>

Source

pub fn is_rolled_back(&self) -> bool

롤백된 트랜잭션은 더 이상 사용할 수 없음

Auto Trait Implementations§

§

impl<'a, S> Freeze for Transaction<'a, S>

§

impl<'a, S> !RefUnwindSafe for Transaction<'a, S>

§

impl<'a, S> Send for Transaction<'a, S>
where S: Send,

§

impl<'a, S> Sync for Transaction<'a, S>
where S: Sync,

§

impl<'a, S> Unpin for Transaction<'a, S>
where S: Unpin,

§

impl<'a, S> UnsafeUnpin for Transaction<'a, S>

§

impl<'a, S> !UnwindSafe for Transaction<'a, S>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more