@@ -334,19 +334,19 @@ enum RepFactory StringToRepFactory(const char* ctype) {
334
334
return kSkipList ;
335
335
}
336
336
static enum RepFactory FLAGS_rep_factory;
337
- DEFINE_string (memtablerep, " skip_list " , " " );
337
+ DEFINE_string (memtablerep, " prefix_hash " , " " );
338
338
339
339
static bool ValidatePrefixSize (const char * flagname, int32_t value) {
340
- if (value < 0 || value>= 2000000000 ) {
341
- fprintf (stderr, " Invalid value for --%s: %d. 0<= PrefixSize <=2000000000 \n " ,
340
+ if (value < 0 || value > 8 ) {
341
+ fprintf (stderr, " Invalid value for --%s: %d. 0 <= PrefixSize <= 8 \n " ,
342
342
flagname, value);
343
343
return false ;
344
344
}
345
345
return true ;
346
346
}
347
- DEFINE_int32 (prefix_size, 0 , " Control the prefix size for HashSkipListRep" );
348
- static const bool FLAGS_prefix_size_dummy __attribute__ ((unused)) =
349
- google::RegisterFlagValidator(&FLAGS_prefix_size, &ValidatePrefixSize);
347
+ DEFINE_int32 (prefix_size, 7 , " Control the prefix size for HashSkipListRep" );
348
+ static const bool FLAGS_prefix_size_dummy =
349
+ google::RegisterFlagValidator (&FLAGS_prefix_size, &ValidatePrefixSize);
350
350
351
351
DEFINE_bool (use_merge, false , " On true, replaces all writes with a Merge "
352
352
" that behaves like a Put" );
@@ -951,15 +951,15 @@ class StressTest {
951
951
return s;
952
952
}
953
953
954
- // Given a prefix P , this does prefix scans for "0"+P, "1"+P,..."9"+P
955
- // in the same snapshot. Each of these 10 scans returns a series of
956
- // values; each series should be the same length, and it is verified
957
- // for each index i that all the i'th values are of the form "0"+V,
958
- // "1"+V,..."9"+V.
954
+ // Given a key , this does prefix scans for "0"+P, "1"+P,..."9"+P
955
+ // in the same snapshot where P is the first FLAGS_prefix_size - 1 bytes
956
+ // of the key. Each of these 10 scans returns a series of values;
957
+ // each series should be the same length, and it is verified for each
958
+ // index i that all the i'th values are of the form "0"+V, "1"+V,..."9"+V.
959
959
// ASSUMES that MultiPut was used to put (K, V)
960
960
Status MultiPrefixScan (ThreadState* thread, const ReadOptions& readoptions,
961
961
ColumnFamilyHandle* column_family,
962
- const Slice& prefix ) {
962
+ const Slice& key ) {
963
963
std::string prefixes[10 ] = {" 0" , " 1" , " 2" , " 3" , " 4" ,
964
964
" 5" , " 6" , " 7" , " 8" , " 9" };
965
965
Slice prefix_slices[10 ];
@@ -968,8 +968,9 @@ class StressTest {
968
968
Iterator* iters[10 ];
969
969
Status s = Status::OK ();
970
970
for (int i = 0 ; i < 10 ; i++) {
971
- prefixes[i] += prefix.ToString ();
972
- prefix_slices[i] = prefixes[i];
971
+ prefixes[i] += key.ToString ();
972
+ prefixes[i].resize (FLAGS_prefix_size);
973
+ prefix_slices[i] = Slice (prefixes[i]);
973
974
readoptionscopy[i] = readoptions;
974
975
readoptionscopy[i].prefix = &prefix_slices[i];
975
976
readoptionscopy[i].snapshot = snapshot;
@@ -1000,7 +1001,7 @@ class StressTest {
1000
1001
for (int i = 0 ; i < 10 ; i++) {
1001
1002
if (values[i] != values[0 ]) {
1002
1003
fprintf (stderr, " error : inconsistent values for prefix %s: %s, %s\n " ,
1003
- prefix. ToString () .c_str (), values[0 ].c_str (),
1004
+ prefixes[i] .c_str (), values[0 ].c_str (),
1004
1005
values[i].c_str ());
1005
1006
// we continue after error rather than exiting so that we can
1006
1007
// find more errors if any
@@ -1035,6 +1036,7 @@ class StressTest {
1035
1036
const Snapshot* snapshot = db_->GetSnapshot ();
1036
1037
ReadOptions readoptionscopy = readoptions;
1037
1038
readoptionscopy.snapshot = snapshot;
1039
+ readoptionscopy.prefix_seek = FLAGS_prefix_size > 0 ;
1038
1040
unique_ptr<Iterator> iter (db_->NewIterator (readoptionscopy, column_family));
1039
1041
1040
1042
iter->Seek (key);
@@ -1149,27 +1151,29 @@ class StressTest {
1149
1151
}
1150
1152
} else if ((int )FLAGS_readpercent <= prob_op && prob_op < prefixBound) {
1151
1153
// OPERATION prefix scan
1152
- // keys are longs (e.g., 8 bytes), so we let prefixes be
1153
- // everything except the last byte. So there will be 2^8=256
1154
- // keys per prefix.
1155
- Slice prefix = Slice (key. data (), key. size () - 1 );
1154
+ // keys are 8 bytes long, prefix size is FLAGS_prefix_size. There are
1155
+ // (8 - FLAGS_prefix_size) bytes besides the prefix. So there will
1156
+ // be 2 ^ ((8 - FLAGS_prefix_size) * 8) possible keys with the same
1157
+ // prefix
1156
1158
if (!FLAGS_test_batches_snapshots) {
1159
+ Slice prefix = Slice (key.data (), FLAGS_prefix_size);
1157
1160
read_opts.prefix = &prefix;
1158
1161
Iterator* iter = db_->NewIterator (read_opts, column_family);
1159
- int count = 0 ;
1162
+ int64_t count = 0 ;
1160
1163
for (iter->SeekToFirst (); iter->Valid (); iter->Next ()) {
1161
1164
assert (iter->key ().starts_with (prefix));
1162
- count++ ;
1165
+ ++count ;
1163
1166
}
1164
- assert (count <= 256 );
1167
+ assert (count <=
1168
+ (static_cast <int64_t >(1 ) << ((8 - FLAGS_prefix_size) * 8 )));
1165
1169
if (iter->status ().ok ()) {
1166
1170
thread->stats .AddPrefixes (1 , count);
1167
1171
} else {
1168
1172
thread->stats .AddErrors (1 );
1169
1173
}
1170
1174
delete iter;
1171
1175
} else {
1172
- MultiPrefixScan (thread, read_opts, column_family, prefix );
1176
+ MultiPrefixScan (thread, read_opts, column_family, key );
1173
1177
}
1174
1178
read_opts.prefix = nullptr ;
1175
1179
} else if (prefixBound <= prob_op && prob_op < writeBound) {
@@ -1617,6 +1621,18 @@ int main(int argc, char** argv) {
1617
1621
// max number of concurrent compactions.
1618
1622
FLAGS_env->SetBackgroundThreads (FLAGS_max_background_compactions);
1619
1623
1624
+ if (FLAGS_prefixpercent > 0 && FLAGS_prefix_size <= 0 ) {
1625
+ fprintf (stderr,
1626
+ " Error: prefixpercent is non-zero while prefix_size is "
1627
+ " not positive!\n " );
1628
+ exit (1 );
1629
+ }
1630
+ if (FLAGS_test_batches_snapshots && FLAGS_prefix_size <= 0 ) {
1631
+ fprintf (stderr,
1632
+ " Error: please specify prefix_size for "
1633
+ " test_batches_snapshots test!\n " );
1634
+ exit (1 );
1635
+ }
1620
1636
if ((FLAGS_readpercent + FLAGS_prefixpercent +
1621
1637
FLAGS_writepercent + FLAGS_delpercent + FLAGS_iterpercent) != 100 ) {
1622
1638
fprintf (stderr,
0 commit comments