pub struct MultiWriteTransaction { /* private fields */ }Implementations§
Source§impl MultiWriteTransaction
impl MultiWriteTransaction
pub fn new(engine: MultiTransaction) -> Result<Self>
Source§impl MultiWriteTransaction
impl MultiWriteTransaction
pub fn id(&self) -> TransactionId
pub fn version(&self) -> CommitVersion
pub fn base_version(&self) -> CommitVersion
pub fn stamp_source(&mut self, source: SourceVersion)
pub fn read_as_of_version_exclusive(&mut self, version: CommitVersion)
pub fn read_as_of_version_inclusive( &mut self, version: CommitVersion, ) -> Result<()>
pub fn pending_writes(&self) -> &PendingWrites
pub fn conflicts(&self) -> &ConflictManager
pub fn mark_preexisting<K: Into<TaggedKey> + Clone>(&mut self, key: &K)
pub fn preexisting_keys(&self) -> &BTreeSet<TaggedKey>
Source§impl MultiWriteTransaction
impl MultiWriteTransaction
pub fn savepoint(&self) -> WriteSavepoint
pub fn restore_savepoint(&mut self, sp: WriteSavepoint)
Source§impl MultiWriteTransaction
impl MultiWriteTransaction
pub fn marker(&mut self) -> Marker<'_>
pub fn marker_with_pending_writes(&mut self) -> (Marker<'_>, &PendingWrites)
pub fn mark_read(&mut self, k: &TaggedKey)
pub fn mark_write(&mut self, k: &TaggedKey)
pub fn reserve_writes(&mut self, additional: usize)
Source§impl MultiWriteTransaction
impl MultiWriteTransaction
Sourcepub fn set<K: Into<TaggedKey> + Clone>(
&mut self,
key: &K,
bytes: impl Into<EncodedBytes>,
) -> Result<()>
pub fn set<K: Into<TaggedKey> + Clone>( &mut self, key: &K, bytes: impl Into<EncodedBytes>, ) -> Result<()>
Examples found in repository?
examples/oracle_performance.rs (line 57)
39pub fn oracle_performance_benchmark() {
40 println!("=== Oracle Performance Benchmark ===\n");
41
42 let test_sizes = vec![1000, 5000, 10000, 25000];
43
44 for &num_txns in &test_sizes {
45 println!("Testing with {} transactions...", num_txns);
46
47 let engine = MultiTransaction::testing();
48
49 let start = Instant::now();
50
51 for i in 0..num_txns {
52 let mut tx = engine.begin_command().unwrap();
53
54 let key = as_key!(format!("key_{}", i));
55 let value = as_values!(format!("value_{}", i));
56
57 tx.set(&key, value).unwrap();
58 tx.commit(vec![]).unwrap();
59 }
60
61 let duration = start.elapsed();
62 let tps = num_txns as f64 / duration.as_secs_f64();
63
64 println!(" {} transactions in {:?}", num_txns, duration);
65 println!(" {:.0} TPS (transactions per second)", tps);
66 println!(" {:.2} μs per transaction\n", duration.as_micros() as f64 / num_txns as f64);
67 }
68}
69
70pub fn concurrent_oracle_benchmark() {
71 println!("=== Concurrent Oracle Performance Benchmark ===\n");
72
73 let test_configs = vec![(10, 1000), (50, 500), (100, 250), (1000, 50)];
74
75 for &(num_threads, txns_per_thread) in &test_configs {
76 let total_txns = num_threads * txns_per_thread;
77 println!(
78 "Testing {} threads × {} transactions = {} total...",
79 num_threads, txns_per_thread, total_txns
80 );
81
82 let engine = Arc::new(MultiTransaction::testing());
83 let start = Instant::now();
84
85 let mut handles = vec![];
86
87 for thread_id in 0..num_threads {
88 let engine_clone = engine.clone();
89 let handle = spawn(move || {
90 let base_key = thread_id * txns_per_thread;
91 for i in 0..txns_per_thread {
92 let mut tx = engine_clone.begin_command().unwrap();
93
94 let key = as_key!(base_key + i);
95 let value = as_values!(i);
96
97 tx.set(&key, value).unwrap();
98 tx.commit(vec![]).unwrap();
99 }
100 });
101 handles.push(handle);
102 }
103
104 for handle in handles {
105 handle.join().expect("Task panicked");
106 }
107
108 let duration = start.elapsed();
109 let tps = total_txns as f64 / duration.as_secs_f64();
110
111 println!(" {} total transactions in {:?}", total_txns, duration);
112 println!(" {:.0} TPS (transactions per second)", tps);
113 println!(" {:.2} μs per transaction\n", duration.as_micros() as f64 / total_txns as f64);
114 }
115}
116
117pub fn conflict_detection_benchmark() {
118 println!("=== Conflict Detection Performance Benchmark ===\n");
119
120 let engine = MultiTransaction::testing();
121
122 for i in 0..1000 {
123 let mut tx = engine.begin_command().unwrap();
124 let key = as_key!(format!("shared_key_{}", i % 100));
125 let value = as_values!(i);
126 tx.set(&key, value).unwrap();
127 tx.commit(vec![]).unwrap();
128 }
129
130 println!("Pre-populated with 1000 transactions across 100 keys");
131
132 let num_conflict_txns = 10000;
133 let start = Instant::now();
134 let mut conflicts = 0;
135
136 for i in 0..num_conflict_txns {
137 let mut tx = engine.begin_command().unwrap();
138
139 let key = as_key!(format!("shared_key_{}", i % 100));
140 let value = as_values!(i + 1000);
141
142 tx.set(&key, value).unwrap();
143
144 match tx.commit(vec![]) {
145 Ok(_) => {}
146 Err(e) if e.code == "TXN_001" => {
147 conflicts += 1;
148 }
149 Err(e) => panic!("Unexpected error: {:?}", e),
150 };
151 }
152
153 let duration = start.elapsed();
154 let tps = num_conflict_txns as f64 / duration.as_secs_f64();
155
156 println!(" {} transactions with potential conflicts in {:?}", num_conflict_txns, duration);
157 println!(
158 " {} actual conflicts detected ({:.1}%)",
159 conflicts,
160 conflicts as f64 / num_conflict_txns as f64 * 100.0
161 );
162 println!(" {:.0} TPS (transactions per second)", tps);
163 println!(" {:.2} μs per transaction", duration.as_micros() as f64 / num_conflict_txns as f64);
164}pub fn remove_with_pre<K: Into<TaggedKey> + Clone>( &mut self, key: &K, pre: EncodedBytes, ) -> Result<()>
pub fn remove<K: Into<TaggedKey> + Clone>(&mut self, key: &K) -> Result<()>
pub fn remove_unobserved<K: Into<TaggedKey> + Clone>( &mut self, key: &K, ) -> Result<()>
pub fn remove_unobserved_with_pre<K: Into<TaggedKey> + Clone>( &mut self, key: &K, pre: EncodedBytes, ) -> Result<()>
pub fn remove_silent<K: Into<TaggedKey> + Clone>( &mut self, key: &K, ) -> Result<()>
pub fn rollback(&mut self) -> Result<()>
pub fn contains<K: Into<TaggedKey> + Clone>(&mut self, key: &K) -> Result<bool>
pub fn get<K: Into<TaggedKey> + Clone>( &mut self, key: &K, ) -> Result<Option<TransactionValue>>
pub fn get_committed<K: Into<TaggedKey> + Clone>( &mut self, key: &K, ) -> Result<Option<TransactionValue>>
Source§impl MultiWriteTransaction
impl MultiWriteTransaction
Sourcepub fn commit(&mut self, flow_changes: Vec<Change>) -> Result<CommitVersion>
pub fn commit(&mut self, flow_changes: Vec<Change>) -> Result<CommitVersion>
Examples found in repository?
examples/oracle_performance.rs (line 58)
39pub fn oracle_performance_benchmark() {
40 println!("=== Oracle Performance Benchmark ===\n");
41
42 let test_sizes = vec![1000, 5000, 10000, 25000];
43
44 for &num_txns in &test_sizes {
45 println!("Testing with {} transactions...", num_txns);
46
47 let engine = MultiTransaction::testing();
48
49 let start = Instant::now();
50
51 for i in 0..num_txns {
52 let mut tx = engine.begin_command().unwrap();
53
54 let key = as_key!(format!("key_{}", i));
55 let value = as_values!(format!("value_{}", i));
56
57 tx.set(&key, value).unwrap();
58 tx.commit(vec![]).unwrap();
59 }
60
61 let duration = start.elapsed();
62 let tps = num_txns as f64 / duration.as_secs_f64();
63
64 println!(" {} transactions in {:?}", num_txns, duration);
65 println!(" {:.0} TPS (transactions per second)", tps);
66 println!(" {:.2} μs per transaction\n", duration.as_micros() as f64 / num_txns as f64);
67 }
68}
69
70pub fn concurrent_oracle_benchmark() {
71 println!("=== Concurrent Oracle Performance Benchmark ===\n");
72
73 let test_configs = vec![(10, 1000), (50, 500), (100, 250), (1000, 50)];
74
75 for &(num_threads, txns_per_thread) in &test_configs {
76 let total_txns = num_threads * txns_per_thread;
77 println!(
78 "Testing {} threads × {} transactions = {} total...",
79 num_threads, txns_per_thread, total_txns
80 );
81
82 let engine = Arc::new(MultiTransaction::testing());
83 let start = Instant::now();
84
85 let mut handles = vec![];
86
87 for thread_id in 0..num_threads {
88 let engine_clone = engine.clone();
89 let handle = spawn(move || {
90 let base_key = thread_id * txns_per_thread;
91 for i in 0..txns_per_thread {
92 let mut tx = engine_clone.begin_command().unwrap();
93
94 let key = as_key!(base_key + i);
95 let value = as_values!(i);
96
97 tx.set(&key, value).unwrap();
98 tx.commit(vec![]).unwrap();
99 }
100 });
101 handles.push(handle);
102 }
103
104 for handle in handles {
105 handle.join().expect("Task panicked");
106 }
107
108 let duration = start.elapsed();
109 let tps = total_txns as f64 / duration.as_secs_f64();
110
111 println!(" {} total transactions in {:?}", total_txns, duration);
112 println!(" {:.0} TPS (transactions per second)", tps);
113 println!(" {:.2} μs per transaction\n", duration.as_micros() as f64 / total_txns as f64);
114 }
115}
116
117pub fn conflict_detection_benchmark() {
118 println!("=== Conflict Detection Performance Benchmark ===\n");
119
120 let engine = MultiTransaction::testing();
121
122 for i in 0..1000 {
123 let mut tx = engine.begin_command().unwrap();
124 let key = as_key!(format!("shared_key_{}", i % 100));
125 let value = as_values!(i);
126 tx.set(&key, value).unwrap();
127 tx.commit(vec![]).unwrap();
128 }
129
130 println!("Pre-populated with 1000 transactions across 100 keys");
131
132 let num_conflict_txns = 10000;
133 let start = Instant::now();
134 let mut conflicts = 0;
135
136 for i in 0..num_conflict_txns {
137 let mut tx = engine.begin_command().unwrap();
138
139 let key = as_key!(format!("shared_key_{}", i % 100));
140 let value = as_values!(i + 1000);
141
142 tx.set(&key, value).unwrap();
143
144 match tx.commit(vec![]) {
145 Ok(_) => {}
146 Err(e) if e.code == "TXN_001" => {
147 conflicts += 1;
148 }
149 Err(e) => panic!("Unexpected error: {:?}", e),
150 };
151 }
152
153 let duration = start.elapsed();
154 let tps = num_conflict_txns as f64 / duration.as_secs_f64();
155
156 println!(" {} transactions with potential conflicts in {:?}", num_conflict_txns, duration);
157 println!(
158 " {} actual conflicts detected ({:.1}%)",
159 conflicts,
160 conflicts as f64 / num_conflict_txns as f64 * 100.0
161 );
162 println!(" {:.0} TPS (transactions per second)", tps);
163 println!(" {:.2} μs per transaction", duration.as_micros() as f64 / num_conflict_txns as f64);
164}Source§impl MultiWriteTransaction
impl MultiWriteTransaction
pub fn discard(&mut self)
pub fn is_discard(&self) -> bool
Source§impl MultiWriteTransaction
impl MultiWriteTransaction
pub fn prefix( &mut self, prefix: &EncodedKey, ) -> Result<MultiVersionBatch<TaggedKey>>
pub fn prefix_rev( &mut self, prefix: &EncodedKey, ) -> Result<MultiVersionBatch<TaggedKey>>
pub fn range( &mut self, range: TaggedKeyBoundRange, scope: RangeScope, batch_size: usize, ) -> Box<dyn Iterator<Item = Result<MultiVersionRow<TaggedKey>>> + Send + '_>
pub fn range_row( &mut self, storage: StorageId, start: Bound<StorageRowKey>, end: Bound<StorageRowKey>, scope: RangeScope, batch_size: usize, ) -> Box<dyn Iterator<Item = Result<MultiVersionRow<StorageRowKey>>> + Send + '_>
pub fn range_partitioned_row( &mut self, storage: StorageId, start: Bound<StoragePartitionedRowKey>, end: Bound<StoragePartitionedRowKey>, scope: RangeScope, batch_size: usize, ) -> Box<dyn Iterator<Item = Result<MultiVersionRow<StoragePartitionedRowKey>>> + Send + '_>
pub fn range_persistence( &mut self, range: TaggedKeyBoundRange, scope: RangeScope, batch_size: usize, ) -> Box<dyn Iterator<Item = Result<MultiVersionRow<TaggedKey>>> + Send + '_>
pub fn range_rev( &mut self, range: TaggedKeyBoundRange, scope: RangeScope, batch_size: usize, ) -> Box<dyn Iterator<Item = Result<MultiVersionRow<TaggedKey>>> + Send + '_>
pub fn range_rev_persistence( &mut self, range: TaggedKeyBoundRange, scope: RangeScope, batch_size: usize, ) -> Box<dyn Iterator<Item = Result<MultiVersionRow<TaggedKey>>> + Send + '_>
Trait Implementations§
Source§impl Drop for MultiWriteTransaction
impl Drop for MultiWriteTransaction
Auto Trait Implementations§
impl !RefUnwindSafe for MultiWriteTransaction
impl !UnwindSafe for MultiWriteTransaction
impl Freeze for MultiWriteTransaction
impl Send for MultiWriteTransaction
impl Sync for MultiWriteTransaction
impl Unpin for MultiWriteTransaction
impl UnsafeUnpin for MultiWriteTransaction
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