@@ -167,12 +167,14 @@ const MAX_BATCH_GET_ITEM_SIZE: usize = 40;
167167/// The second attribute is the actual key value, which is generated by concatenating the
168168/// context prefix. `The Vec<u8>` expression is obtained from `self.derive_key`.
169169fn build_key ( start_key : & [ u8 ] , key : Vec < u8 > ) -> HashMap < String , AttributeValue > {
170+ let mut prefixed_key = vec ! [ 1 ] ;
171+ prefixed_key. extend ( key) ;
170172 [
171173 (
172174 PARTITION_ATTRIBUTE . to_owned ( ) ,
173175 AttributeValue :: B ( Blob :: new ( start_key. to_vec ( ) ) ) ,
174176 ) ,
175- ( KEY_ATTRIBUTE . to_owned ( ) , AttributeValue :: B ( Blob :: new ( key ) ) ) ,
177+ ( KEY_ATTRIBUTE . to_owned ( ) , AttributeValue :: B ( Blob :: new ( prefixed_key ) ) ) ,
176178 ]
177179 . into ( )
178180}
@@ -183,12 +185,14 @@ fn build_key_value(
183185 key : Vec < u8 > ,
184186 value : Vec < u8 > ,
185187) -> HashMap < String , AttributeValue > {
188+ let mut prefixed_key = vec ! [ 1 ] ;
189+ prefixed_key. extend ( key) ;
186190 [
187191 (
188192 PARTITION_ATTRIBUTE . to_owned ( ) ,
189193 AttributeValue :: B ( Blob :: new ( start_key. to_vec ( ) ) ) ,
190194 ) ,
191- ( KEY_ATTRIBUTE . to_owned ( ) , AttributeValue :: B ( Blob :: new ( key ) ) ) ,
195+ ( KEY_ATTRIBUTE . to_owned ( ) , AttributeValue :: B ( Blob :: new ( prefixed_key ) ) ) ,
192196 (
193197 VALUE_ATTRIBUTE . to_owned ( ) ,
194198 AttributeValue :: B ( Blob :: new ( value) ) ,
@@ -216,7 +220,7 @@ fn extract_key(
216220 . get ( KEY_ATTRIBUTE )
217221 . ok_or ( DynamoDbStoreInternalError :: MissingKey ) ?;
218222 match key {
219- AttributeValue :: B ( blob) => Ok ( & blob. as_ref ( ) [ prefix_len..] ) ,
223+ AttributeValue :: B ( blob) => Ok ( & blob. as_ref ( ) [ 1 + prefix_len..] ) ,
220224 key => Err ( DynamoDbStoreInternalError :: wrong_key_type ( key) ) ,
221225 }
222226}
@@ -602,6 +606,8 @@ impl DynamoDbStoreInternal {
602606 ) -> Result < QueryOutput , DynamoDbStoreInternalError > {
603607 let _guard = self . acquire ( ) . await ;
604608 let start_key = start_key. to_vec ( ) ;
609+ let mut prefixed_key_prefix = vec ! [ 1 ] ;
610+ prefixed_key_prefix. extend ( key_prefix) ;
605611 let response = self
606612 . client
607613 . query ( )
@@ -611,7 +617,7 @@ impl DynamoDbStoreInternal {
611617 "{PARTITION_ATTRIBUTE} = :partition and begins_with({KEY_ATTRIBUTE}, :prefix)"
612618 ) )
613619 . expression_attribute_values ( ":partition" , AttributeValue :: B ( Blob :: new ( start_key) ) )
614- . expression_attribute_values ( ":prefix" , AttributeValue :: B ( Blob :: new ( key_prefix ) ) )
620+ . expression_attribute_values ( ":prefix" , AttributeValue :: B ( Blob :: new ( prefixed_key_prefix ) ) )
615621 . set_exclusive_start_key ( start_key_map)
616622 . send ( )
617623 . boxed_sync ( )
@@ -746,7 +752,8 @@ impl DynamoDbStoreInternal {
746752 . ok_or ( DynamoDbStoreInternalError :: MissingKey ) ?;
747753
748754 if let AttributeValue :: B ( blob) = key_attr {
749- let key = blob. as_ref ( ) ;
755+ let prefixed_key = blob. as_ref ( ) ;
756+ let key = & prefixed_key[ 1 ..] ; // Remove the [1] prefix
750757 if let Some ( indices) = key_to_index. get ( key) {
751758 if let Some ( ( & last, rest) ) = indices. split_last ( ) {
752759 let value = extract_value_owned ( & mut item) ?;
0 commit comments