@@ -31,6 +31,16 @@ pub struct Transaction {
3131
3232impl Transaction {
3333 pub fn get ( & self , key : & [ u8 ] ) -> Result < Option < Bytes > > {
34+ if self . committed . load ( Ordering :: SeqCst ) {
35+ panic ! ( "cannot operate on committed txn!" ) ;
36+ }
37+
38+ if self . key_hashes . is_some ( ) {
39+ let mut guard = self . key_hashes . as_ref ( ) . unwrap ( ) . lock ( ) ;
40+ let ( _, read_set) = & mut * guard;
41+ read_set. insert ( crc32fast:: hash ( key) ) ;
42+ }
43+
3444 // first probe the local_sotrage
3545 if let Some ( entry) = self . local_storage . get ( key) {
3646 if entry. value ( ) . is_empty ( ) {
@@ -42,6 +52,10 @@ impl Transaction {
4252 }
4353
4454 pub fn scan ( self : & Arc < Self > , lower : Bound < & [ u8 ] > , upper : Bound < & [ u8 ] > ) -> Result < TxnIterator > {
55+ if self . committed . load ( Ordering :: SeqCst ) {
56+ panic ! ( "cannot operate on committed txn!" ) ;
57+ }
58+
4559 let mut local_iter = TxnLocalIteratorBuilder {
4660 map : self . local_storage . clone ( ) ,
4761 iter_builder : |map| map. range ( ( map_bound ( lower) , map_bound ( upper) ) ) ,
@@ -60,11 +74,17 @@ impl Transaction {
6074 }
6175
6276 pub fn put ( & self , key : & [ u8 ] , value : & [ u8 ] ) {
77+ if self . committed . load ( Ordering :: SeqCst ) {
78+ panic ! ( "cannot operate on committed txn!" ) ;
79+ }
6380 self . local_storage
6481 . insert ( Bytes :: copy_from_slice ( key) , Bytes :: copy_from_slice ( value) ) ;
6582 }
6683
6784 pub fn delete ( & self , key : & [ u8 ] ) {
85+ if self . committed . load ( Ordering :: SeqCst ) {
86+ panic ! ( "cannot operate on committed txn!" ) ;
87+ }
6888 self . local_storage
6989 . insert ( Bytes :: copy_from_slice ( key) , Bytes :: new ( ) ) ;
7090 }
0 commit comments