@@ -1351,4 +1351,76 @@ mod tests {
13511351
13521352 Ok ( ( ) )
13531353 }
1354+
1355+ #[ test]
1356+ fn data_block_point_read_seqno_aware_seek_hash_conflict ( ) -> crate :: Result < ( ) > {
1357+ // Multiple versions of the same key with a hash index enabled.
1358+ // Duplicate user keys hash to the same bucket, producing MARKER_CONFLICT,
1359+ // which forces point_read through the seek_to_key_seqno fallback path.
1360+ let items = [
1361+ InternalValue :: from_components ( b"a" , b"a5" , 5 , Value ) ,
1362+ InternalValue :: from_components ( b"a" , b"a4" , 4 , Value ) ,
1363+ InternalValue :: from_components ( b"a" , b"a3" , 3 , Value ) ,
1364+ InternalValue :: from_components ( b"a" , b"a2" , 2 , Value ) ,
1365+ InternalValue :: from_components ( b"a" , b"a1" , 1 , Value ) ,
1366+ ] ;
1367+
1368+ for restart_interval in 1 ..=4 {
1369+ let bytes = DataBlock :: encode_into_vec ( & items, restart_interval, 1.33 ) ?;
1370+
1371+ let data_block = DataBlock :: new ( Block {
1372+ data : bytes. into ( ) ,
1373+ header : Header {
1374+ block_type : BlockType :: Data ,
1375+ checksum : Checksum :: from_raw ( 0 ) ,
1376+ data_length : 0 ,
1377+ uncompressed_length : 0 ,
1378+ } ,
1379+ } ) ;
1380+
1381+ // Verify hash index is present and the duplicate key triggers conflict
1382+ assert ! (
1383+ data_block
1384+ . hash_bucket_count( )
1385+ . expect( "should have built hash index" )
1386+ > 0 ,
1387+ "restart_interval={restart_interval}: hash index should be built" ,
1388+ ) ;
1389+
1390+ // seqno=4 -> first version with seqno < 4, i.e. seqno=3
1391+ assert_eq ! (
1392+ Some ( items[ 2 ] . clone( ) ) ,
1393+ data_block. point_read( b"a" , 4 ) ,
1394+ "restart_interval={restart_interval}: seqno=4 should return v3 via conflict fallback" ,
1395+ ) ;
1396+
1397+ // seqno=3 -> seqno=2
1398+ assert_eq ! (
1399+ Some ( items[ 3 ] . clone( ) ) ,
1400+ data_block. point_read( b"a" , 3 ) ,
1401+ "restart_interval={restart_interval}: seqno=3 should return v2 via conflict fallback" ,
1402+ ) ;
1403+
1404+ // seqno=6 -> latest (seqno=5)
1405+ assert_eq ! (
1406+ Some ( items[ 0 ] . clone( ) ) ,
1407+ data_block. point_read( b"a" , 6 ) ,
1408+ "restart_interval={restart_interval}: seqno=6 should return v5 via conflict fallback" ,
1409+ ) ;
1410+
1411+ // seqno=1 -> no visible version
1412+ assert ! (
1413+ data_block. point_read( b"a" , 1 ) . is_none( ) ,
1414+ "restart_interval={restart_interval}: seqno=1 should return None via conflict fallback" ,
1415+ ) ;
1416+
1417+ // Non-existent key
1418+ assert ! (
1419+ data_block. point_read( b"z" , SeqNo :: MAX ) . is_none( ) ,
1420+ "restart_interval={restart_interval}: key 'z' should not exist" ,
1421+ ) ;
1422+ }
1423+
1424+ Ok ( ( ) )
1425+ }
13541426}
0 commit comments