@@ -52,7 +52,8 @@ class BlockBasedTableReaderBaseTest : public testing::Test {
52
52
// user defined timestamps and different sequence number to differentiate them
53
53
static std::vector<std::pair<std::string, std::string>> GenerateKVMap (
54
54
int num_block = 2 , bool mixed_with_human_readable_string_value = false ,
55
- size_t ts_sz = 0 , bool same_key_diff_ts = false ) {
55
+ size_t ts_sz = 0 , bool same_key_diff_ts = false ,
56
+ const Comparator* comparator = BytewiseComparator()) {
56
57
std::vector<std::pair<std::string, std::string>> kv;
57
58
58
59
SequenceNumber seq_no = 0 ;
@@ -100,6 +101,10 @@ class BlockBasedTableReaderBaseTest : public testing::Test {
100
101
}
101
102
}
102
103
}
104
+ auto comparator_name = std::string (comparator->Name ());
105
+ if (comparator_name.find (" Reverse" ) != std::string::npos) {
106
+ std::reverse (kv.begin (), kv.end ());
107
+ }
103
108
return kv;
104
109
}
105
110
@@ -128,6 +133,7 @@ class BlockBasedTableReaderBaseTest : public testing::Test {
128
133
129
134
InternalKeyComparator comparator (ioptions.user_comparator );
130
135
ColumnFamilyOptions cf_options;
136
+ cf_options.comparator = ioptions.user_comparator ;
131
137
cf_options.prefix_extractor = options_.prefix_extractor ;
132
138
MutableCFOptions moptions (cf_options);
133
139
CompressionOptions compression_opts;
@@ -255,11 +261,13 @@ class BlockBasedTableReaderBaseTest : public testing::Test {
255
261
// generate keys with different user provided key, same user-defined
256
262
// timestamps (if udt enabled), same sequence number. This test mode is
257
263
// used for testing `Get`, `MultiGet`, and `NewIterator`.
264
+ // Param 9: test both the default comparator and a reverse comparator.
258
265
class BlockBasedTableReaderTest
259
266
: public BlockBasedTableReaderBaseTest,
260
- public testing::WithParamInterface<std::tuple<
261
- CompressionType, bool , BlockBasedTableOptions::IndexType, bool ,
262
- test::UserDefinedTimestampTestMode, uint32_t , uint32_t , bool >> {
267
+ public testing::WithParamInterface<
268
+ std::tuple<CompressionType, bool , BlockBasedTableOptions::IndexType,
269
+ bool , test::UserDefinedTimestampTestMode, uint32_t ,
270
+ uint32_t , bool , const Comparator*>> {
263
271
protected:
264
272
void SetUp () override {
265
273
compression_type_ = std::get<0 >(GetParam ());
@@ -270,6 +278,7 @@ class BlockBasedTableReaderTest
270
278
compression_parallel_threads_ = std::get<5 >(GetParam ());
271
279
compression_dict_bytes_ = std::get<6 >(GetParam ());
272
280
same_key_diff_ts_ = std::get<7 >(GetParam ());
281
+ comparator_ = std::get<8 >(GetParam ());
273
282
BlockBasedTableReaderBaseTest::SetUp ();
274
283
}
275
284
@@ -295,6 +304,7 @@ class BlockBasedTableReaderTest
295
304
uint32_t compression_parallel_threads_;
296
305
uint32_t compression_dict_bytes_;
297
306
bool same_key_diff_ts_;
307
+ const Comparator* comparator_{};
298
308
};
299
309
300
310
class BlockBasedTableReaderGetTest : public BlockBasedTableReaderTest {};
@@ -1022,14 +1032,16 @@ TEST_P(BlockBasedTableReaderTest, MultiScanPrepare) {
1022
1032
SCOPED_TRACE (std::string (" use_async_io=" ) + std::to_string (use_async_io));
1023
1033
Options options;
1024
1034
options.statistics = CreateDBStatistics ();
1035
+ options.comparator = comparator_;
1025
1036
std::shared_ptr<FileSystem> fs = options.env ->GetFileSystem ();
1026
1037
ReadOptions read_opts;
1027
1038
read_opts.fill_cache = fill_cache;
1028
1039
size_t ts_sz = options.comparator ->timestamp_size ();
1029
1040
std::vector<std::pair<std::string, std::string>> kv =
1030
1041
BlockBasedTableReaderBaseTest::GenerateKVMap (
1031
1042
100 /* num_block */ ,
1032
- true /* mixed_with_human_readable_string_value */ , ts_sz);
1043
+ true /* mixed_with_human_readable_string_value */ , ts_sz,
1044
+ same_key_diff_ts_, comparator_);
1033
1045
std::string table_name = " BlockBasedTableReaderTest_NewIterator" +
1034
1046
CompressionTypeToString (compression_type_) +
1035
1047
" _async" + std::to_string (use_async_io);
@@ -1052,7 +1064,7 @@ TEST_P(BlockBasedTableReaderTest, MultiScanPrepare) {
1052
1064
read_opts, options_.prefix_extractor .get (), /* arena=*/ nullptr ,
1053
1065
/* skip_filters=*/ false , TableReaderCaller::kUncategorized ));
1054
1066
1055
- MultiScanArgs scan_options (BytewiseComparator () );
1067
+ MultiScanArgs scan_options (comparator_ );
1056
1068
scan_options.use_async_io = use_async_io;
1057
1069
scan_options.insert (ExtractUserKey (kv[0 ].first ),
1058
1070
ExtractUserKey (kv[kEntriesPerBlock ].first ));
@@ -1087,7 +1099,7 @@ TEST_P(BlockBasedTableReaderTest, MultiScanPrepare) {
1087
1099
iter.reset (table->NewIterator (
1088
1100
read_opts, options_.prefix_extractor .get (), /* arena=*/ nullptr ,
1089
1101
/* skip_filters=*/ false , TableReaderCaller::kUncategorized ));
1090
- scan_options = MultiScanArgs (BytewiseComparator () );
1102
+ scan_options = MultiScanArgs (comparator_ );
1091
1103
scan_options.insert (ExtractUserKey (kv[70 * kEntriesPerBlock ].first ),
1092
1104
ExtractUserKey (kv[75 * kEntriesPerBlock ].first ));
1093
1105
scan_options.insert (ExtractUserKey (kv[90 * kEntriesPerBlock ].first ),
@@ -1125,7 +1137,7 @@ TEST_P(BlockBasedTableReaderTest, MultiScanPrepare) {
1125
1137
// From reads above, blocks 70-75 and 90-95 already in cache
1126
1138
// So we should read 50-70 76-89 96-99 in three I/Os.
1127
1139
// If fill_cache is false, then we'll do one giant I/O.
1128
- scan_options = MultiScanArgs (BytewiseComparator () );
1140
+ scan_options = MultiScanArgs (comparator_ );
1129
1141
scan_options.use_async_io = use_async_io;
1130
1142
scan_options.insert (ExtractUserKey (kv[50 * kEntriesPerBlock ].first ));
1131
1143
read_count_before =
@@ -1165,7 +1177,7 @@ TEST_P(BlockBasedTableReaderTest, MultiScanPrepare) {
1165
1177
iter.reset (table->NewIterator (
1166
1178
read_opts, options_.prefix_extractor .get (), /* arena=*/ nullptr ,
1167
1179
/* skip_filters=*/ false , TableReaderCaller::kUncategorized ));
1168
- scan_options = MultiScanArgs (BytewiseComparator () );
1180
+ scan_options = MultiScanArgs (comparator_ );
1169
1181
scan_options.use_async_io = use_async_io;
1170
1182
scan_options.insert (ExtractUserKey (kv[10 * kEntriesPerBlock ].first ),
1171
1183
ExtractUserKey (kv[20 * kEntriesPerBlock ].first ));
@@ -1195,7 +1207,7 @@ TEST_P(BlockBasedTableReaderTest, MultiScanPrepare) {
1195
1207
iter.reset (table->NewIterator (
1196
1208
read_opts, options_.prefix_extractor .get (), /* arena=*/ nullptr ,
1197
1209
/* skip_filters=*/ false , TableReaderCaller::kUncategorized ));
1198
- scan_options = MultiScanArgs (BytewiseComparator () );
1210
+ scan_options = MultiScanArgs (comparator_ );
1199
1211
scan_options.use_async_io = use_async_io;
1200
1212
scan_options.insert (ExtractUserKey (kv[10 * kEntriesPerBlock ].first ));
1201
1213
scan_options.insert (ExtractUserKey (kv[11 * kEntriesPerBlock ].first ));
@@ -1226,14 +1238,15 @@ TEST_P(BlockBasedTableReaderTest, MultiScanPrefetchSizeLimit) {
1226
1238
return ;
1227
1239
}
1228
1240
Options options;
1241
+ options.comparator = comparator_;
1229
1242
ReadOptions read_opts;
1230
1243
size_t ts_sz = options.comparator ->timestamp_size ();
1231
1244
1232
1245
// Generate data that spans multiple blocks
1233
1246
std::vector<std::pair<std::string, std::string>> kv =
1234
1247
BlockBasedTableReaderBaseTest::GenerateKVMap (
1235
1248
20 /* num_block */ , true /* mixed_with_human_readable_string_value */ ,
1236
- ts_sz);
1249
+ ts_sz, same_key_diff_ts_, comparator_ );
1237
1250
1238
1251
std::string table_name = " BlockBasedTableReaderTest_PrefetchSizeLimit" +
1239
1252
CompressionTypeToString (compression_type_);
@@ -1259,7 +1272,7 @@ TEST_P(BlockBasedTableReaderTest, MultiScanPrefetchSizeLimit) {
1259
1272
read_opts, options_.prefix_extractor .get (), /* arena=*/ nullptr ,
1260
1273
/* skip_filters=*/ false , TableReaderCaller::kUncategorized ));
1261
1274
1262
- MultiScanArgs scan_options (BytewiseComparator () );
1275
+ MultiScanArgs scan_options (comparator_ );
1263
1276
scan_options.max_prefetch_size = 1024 ; // less than block size
1264
1277
scan_options.insert (ExtractUserKey (kv[0 ].first ),
1265
1278
ExtractUserKey (kv[5 ].first ));
@@ -1279,7 +1292,7 @@ TEST_P(BlockBasedTableReaderTest, MultiScanPrefetchSizeLimit) {
1279
1292
read_opts, options_.prefix_extractor .get (), /* arena=*/ nullptr ,
1280
1293
/* skip_filters=*/ false , TableReaderCaller::kUncategorized ));
1281
1294
1282
- MultiScanArgs scan_options (BytewiseComparator () );
1295
+ MultiScanArgs scan_options (comparator_ );
1283
1296
scan_options.max_prefetch_size = 9 * 1024 ; // 9KB - 2 blocks with buffer
1284
1297
scan_options.insert (ExtractUserKey (kv[1 * kEntriesPerBlock ].first ),
1285
1298
ExtractUserKey (kv[8 * kEntriesPerBlock ].first ));
@@ -1310,7 +1323,7 @@ TEST_P(BlockBasedTableReaderTest, MultiScanPrefetchSizeLimit) {
1310
1323
read_opts, options_.prefix_extractor .get (), /* arena=*/ nullptr ,
1311
1324
/* skip_filters=*/ false , TableReaderCaller::kUncategorized ));
1312
1325
1313
- MultiScanArgs scan_options (BytewiseComparator () );
1326
+ MultiScanArgs scan_options (comparator_ );
1314
1327
scan_options.max_prefetch_size = 3 * 4 * 1024 + 1024 ; // 3 blocks + 1KB
1315
1328
scan_options.insert (ExtractUserKey (kv[0 ].first ),
1316
1329
ExtractUserKey (kv[5 * kEntriesPerBlock ].first ));
@@ -1336,7 +1349,7 @@ TEST_P(BlockBasedTableReaderTest, MultiScanPrefetchSizeLimit) {
1336
1349
read_opts, options_.prefix_extractor .get (), /* arena=*/ nullptr ,
1337
1350
/* skip_filters=*/ false , TableReaderCaller::kUncategorized ));
1338
1351
1339
- MultiScanArgs scan_options (BytewiseComparator () );
1352
+ MultiScanArgs scan_options (comparator_ );
1340
1353
scan_options.max_prefetch_size = 5 * 4 * 1024 + 1024 ; // 5 blocks + 1KB
1341
1354
// Will read 5 entries from first scan range, and 4 blocks from the second
1342
1355
// scan range
@@ -1373,7 +1386,7 @@ TEST_P(BlockBasedTableReaderTest, MultiScanPrefetchSizeLimit) {
1373
1386
read_opts, options_.prefix_extractor .get (), /* arena=*/ nullptr ,
1374
1387
/* skip_filters=*/ false , TableReaderCaller::kUncategorized ));
1375
1388
1376
- MultiScanArgs scan_options (BytewiseComparator () );
1389
+ MultiScanArgs scan_options (comparator_ );
1377
1390
scan_options.max_prefetch_size = 10 * 1024 * 1024 ; // 10MB
1378
1391
scan_options.insert (ExtractUserKey (kv[0 ].first ),
1379
1392
ExtractUserKey (kv[5 ].first ));
@@ -1440,7 +1453,8 @@ INSTANTIATE_TEST_CASE_P(
1440
1453
BlockBasedTableOptions::IndexType::kBinarySearchWithFirstKey ),
1441
1454
::testing::Values(false ), ::testing::ValuesIn(test::GetUDTTestModes()),
1442
1455
::testing::Values(1 , 2 ), ::testing::Values(0 , 4096 ),
1443
- ::testing::Values(false )));
1456
+ ::testing::Values(false ),
1457
+ ::testing::Values(BytewiseComparator(), ReverseBytewiseComparator())));
1444
1458
INSTANTIATE_TEST_CASE_P (
1445
1459
BlockBasedTableReaderGetTest, BlockBasedTableReaderGetTest,
1446
1460
::testing::Combine (
@@ -1452,7 +1466,8 @@ INSTANTIATE_TEST_CASE_P(
1452
1466
BlockBasedTableOptions::IndexType::kBinarySearchWithFirstKey ),
1453
1467
::testing::Values(false ), ::testing::ValuesIn(test::GetUDTTestModes()),
1454
1468
::testing::Values(1 , 2 ), ::testing::Values(0 , 4096 ),
1455
- ::testing::Values(false , true )));
1469
+ ::testing::Values(false , true ),
1470
+ ::testing::Values(BytewiseComparator(), ReverseBytewiseComparator())));
1456
1471
INSTANTIATE_TEST_CASE_P (
1457
1472
StrictCapacityLimitReaderTest, StrictCapacityLimitReaderTest,
1458
1473
::testing::Combine (
@@ -1461,7 +1476,8 @@ INSTANTIATE_TEST_CASE_P(
1461
1476
BlockBasedTableOptions::IndexType::kTwoLevelIndexSearch ),
1462
1477
::testing::Values(false ), ::testing::ValuesIn(test::GetUDTTestModes()),
1463
1478
::testing::Values(1 , 2 ), ::testing::Values(0 ),
1464
- ::testing::Values(false , true )));
1479
+ ::testing::Values(false , true ),
1480
+ ::testing::Values(BytewiseComparator(), ReverseBytewiseComparator())));
1465
1481
INSTANTIATE_TEST_CASE_P (
1466
1482
VerifyChecksum, BlockBasedTableReaderTestVerifyChecksum,
1467
1483
::testing::Combine (
@@ -1470,8 +1486,8 @@ INSTANTIATE_TEST_CASE_P(
1470
1486
::testing::Values(
1471
1487
BlockBasedTableOptions::IndexType::kTwoLevelIndexSearch ),
1472
1488
::testing::Values(true ), ::testing::ValuesIn(test::GetUDTTestModes()),
1473
- ::testing::Values(1 , 2 ), ::testing::Values(0 ),
1474
- ::testing::Values(false )));
1489
+ ::testing::Values(1 , 2 ), ::testing::Values(0 ), ::testing::Values( false ),
1490
+ ::testing::Values(BytewiseComparator(), ReverseBytewiseComparator() )));
1475
1491
1476
1492
} // namespace ROCKSDB_NAMESPACE
1477
1493
0 commit comments