File tree Expand file tree Collapse file tree 7 files changed +45
-2
lines changed
Expand file tree Collapse file tree 7 files changed +45
-2
lines changed Original file line number Diff line number Diff line change @@ -148,6 +148,11 @@ impl TryFrom<pb::AtomicWrite> for AtomicWrite {
148148 . ok_or ( ConvertError :: DecodeError ) ?;
149149 MutationKind :: Max ( value)
150150 }
151+ ( pb:: MutationType :: MSetSuffixVersionstampedKey , Some ( value) ) => {
152+ let value = decode_value ( value. data , value. encoding as i64 )
153+ . ok_or ( ConvertError :: DecodeError ) ?;
154+ MutationKind :: SetSuffixVersionstampedKey ( value)
155+ }
151156 _ => return Err ( ConvertError :: InvalidMutationKind ) ,
152157 } ;
153158 let expire_at = match mutation. expire_at_ms {
Original file line number Diff line number Diff line change @@ -323,6 +323,7 @@ pub enum MutationKind {
323323 Sum ( KvValue ) ,
324324 Min ( KvValue ) ,
325325 Max ( KvValue ) ,
326+ SetSuffixVersionstampedKey ( KvValue ) ,
326327}
327328
328329impl MutationKind {
@@ -332,6 +333,7 @@ impl MutationKind {
332333 MutationKind :: Sum ( value) => Some ( value) ,
333334 MutationKind :: Min ( value) => Some ( value) ,
334335 MutationKind :: Max ( value) => Some ( value) ,
336+ MutationKind :: SetSuffixVersionstampedKey ( value) => Some ( value) ,
335337 MutationKind :: Delete => None ,
336338 }
337339 }
Original file line number Diff line number Diff line change @@ -135,6 +135,8 @@ enum MutationType {
135135 M_MAX = 4 ;
136136 // Max the stored value with the new value. Both values must be LE64 encoded.
137137 M_MIN = 5 ;
138+ // Set the value, with the versionstamp appended to the end of the key as a string.
139+ M_SET_SUFFIX_VERSIONSTAMPED_KEY = 9 ;
138140}
139141
140142// The encoding of a value.
Original file line number Diff line number Diff line change @@ -614,6 +614,14 @@ impl<P: RemotePermissions> Database for Remote<P> {
614614 expire_at_ms,
615615 } ) ;
616616 }
617+ denokv_proto:: MutationKind :: SetSuffixVersionstampedKey ( value) => {
618+ mutations. push ( pb:: Mutation {
619+ key : mutation. key ,
620+ value : Some ( encode_value_to_pb ( value) ) ,
621+ mutation_type : pb:: MutationType :: MSetSuffixVersionstampedKey as _ ,
622+ expire_at_ms,
623+ } ) ;
624+ }
617625 }
618626 }
619627
Original file line number Diff line number Diff line change @@ -21,6 +21,7 @@ async-trait.workspace = true
2121chrono.workspace = true
2222denokv_proto.workspace = true
2323futures.workspace = true
24+ hex.workspace = true
2425log.workspace = true
2526num-bigint.workspace = true
2627rand.workspace = true
Original file line number Diff line number Diff line change @@ -287,6 +287,7 @@ impl SqliteBackend {
287287 let version: i64 = tx
288288 . prepare_cached ( STATEMENT_INC_AND_GET_DATA_VERSION ) ?
289289 . query_row ( [ incrementer_count] , |row| row. get ( 0 ) ) ?;
290+ let new_versionstamp = version_to_versionstamp ( version) ;
290291
291292 for mutation in & write. mutations {
292293 match & mutation. kind {
@@ -326,6 +327,31 @@ impl SqliteBackend {
326327 a. max ( b)
327328 } ) ?;
328329 }
330+ MutationKind :: SetSuffixVersionstampedKey ( value) => {
331+ let mut versionstamp_suffix = [ 0u8 ; 22 ] ;
332+ versionstamp_suffix[ 0 ] = 0x02 ;
333+ hex:: encode_to_slice (
334+ new_versionstamp,
335+ & mut versionstamp_suffix[ 1 ..21 ] ,
336+ )
337+ . unwrap ( ) ;
338+
339+ let key = [ & mutation. key [ ..] , & versionstamp_suffix[ ..] ] . concat ( ) ;
340+
341+ let ( value, encoding) = encode_value ( value) ;
342+ let changed =
343+ tx. prepare_cached ( STATEMENT_KV_POINT_SET ) ?. execute ( params ! [
344+ key,
345+ value,
346+ & encoding,
347+ & version,
348+ mutation
349+ . expire_at
350+ . map( |time| time. timestamp_millis( ) )
351+ . unwrap_or( -1i64 )
352+ ] ) ?;
353+ assert_eq ! ( changed, 1 )
354+ }
329355 }
330356 }
331357
@@ -355,8 +381,6 @@ impl SqliteBackend {
355381 assert_eq ! ( changed, 1 )
356382 }
357383
358- let new_versionstamp = version_to_versionstamp ( version) ;
359-
360384 Ok ( (
361385 has_enqueues,
362386 Some ( CommitResult {
You can’t perform that action at this time.
0 commit comments