pub struct Transaction<'a, S: TxState> { /* private fields */ }Expand description
Typestate Transaction
Active 상태에서만 쿼리/쓰기가 가능하며, commit/rollback 후에는 컴파일 타임에 사용 불가.
Implementations§
Source§impl<'a> Transaction<'a, Active>
impl<'a> Transaction<'a, Active>
Sourcepub fn query_one<T: FromRow>(&self, sql: impl Into<String>) -> QueryOne<'_, T>
pub fn query_one<T: FromRow>(&self, sql: impl Into<String>) -> QueryOne<'_, T>
SELECT 쿼리 — 단일 행 반환 (없으면 에러)
Sourcepub fn query_optional<T: FromRow>(
&self,
sql: impl Into<String>,
) -> QueryOptional<'_, T>
pub fn query_optional<T: FromRow>( &self, sql: impl Into<String>, ) -> QueryOptional<'_, T>
SELECT 쿼리 — 단일 행 반환 (없으면 None)
Sourcepub fn query_scalar<T: FromScalar>(
&self,
sql: impl Into<String>,
) -> QueryScalar<'_, T>
pub fn query_scalar<T: FromScalar>( &self, sql: impl Into<String>, ) -> QueryScalar<'_, T>
SELECT 쿼리 — 단일 스칼라 값 반환
Sourcepub fn execute(&self, sql: impl Into<String>) -> Execute<'_>
pub fn execute(&self, sql: impl Into<String>) -> Execute<'_>
INSERT/UPDATE/DELETE — 영향받은 행 수 반환
Sourcepub fn insert(&mut self, table: &str, key: &[u8], value: &[u8]) -> DbxResult<()>
pub fn insert(&mut self, table: &str, key: &[u8], value: &[u8]) -> DbxResult<()>
트랜잭션 내 INSERT — 로컬 버퍼에 저장 (commit 전까지 미반영)
Sourcepub fn insert_batch(
&mut self,
table: &str,
rows: Vec<(Vec<u8>, Vec<u8>)>,
) -> DbxResult<()>
pub fn insert_batch( &mut self, table: &str, rows: Vec<(Vec<u8>, Vec<u8>)>, ) -> DbxResult<()>
트랜잭션 내 BATCH INSERT — 여러 키-값 쌍을 일괄 삽입 (최적화됨)
Sourcepub fn delete(&mut self, table: &str, key: &[u8]) -> DbxResult<bool>
pub fn delete(&mut self, table: &str, key: &[u8]) -> DbxResult<bool>
트랜잭션 내 DELETE — 로컬 버퍼에 tombstone 기록
Sourcepub fn get(&self, table: &str, key: &[u8]) -> DbxResult<Option<Vec<u8>>>
pub fn get(&self, table: &str, key: &[u8]) -> DbxResult<Option<Vec<u8>>>
트랜잭션 내 GET — 로컬 버퍼 우선, 없으면 메인 스토리지 조회
Sourcepub fn pending_ops(&self) -> usize
pub fn pending_ops(&self) -> usize
현재 트랜잭션의 보류 중인 연산 개수
Sourcepub fn commit(self) -> DbxResult<Transaction<'a, Committed>>
pub fn commit(self) -> DbxResult<Transaction<'a, Committed>>
트랜잭션 커밋 — 모든 버퍼링된 쓰기를 메인 스토리지에 원자적으로 반영
§MVCC Dual-Write 전략
이 구현은 MVCC versioned key와 일반 key를 모두 저장하는 dual-write 전략을 사용합니다:
-
insert_versioned(): MVCC 타임스탬프가 포함된 versioned key로 저장
- 향후 snapshot isolation, time-travel query 지원
- 버전 히스토리 추적 가능
-
insert(): 일반 key로도 저장
- get() 메서드와의 backward compatibility 보장
- Fast-path 조회 성능 유지
- 기존 코드와의 호환성 확보
이 전략은 약간의 저장 공간 오버헤드가 있지만, 다음 이점을 제공합니다:
- 기존 CRUD API와 완벽한 호환성
- MVCC 기능을 점진적으로 활성화 가능
- 성능 저하 없이 transaction isolation 지원
Sourcepub fn rollback(self) -> DbxResult<Transaction<'a, RolledBack>>
pub fn rollback(self) -> DbxResult<Transaction<'a, RolledBack>>
트랜잭션 롤백 — 모든 버퍼링된 쓰기를 폐기
Source§impl<'a> Transaction<'a, Committed>
impl<'a> Transaction<'a, Committed>
Sourcepub fn is_committed(&self) -> bool
pub fn is_committed(&self) -> bool
커밋된 트랜잭션은 더 이상 사용할 수 없음
Source§impl<'a> Transaction<'a, RolledBack>
impl<'a> Transaction<'a, RolledBack>
Sourcepub fn is_rolled_back(&self) -> bool
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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