@ -336,6 +336,9 @@ class NonBatchedOpsStressTest : public StressTest {
SharedState : : ignore_read_error = false ;
SharedState : : ignore_read_error = false ;
}
}
std : : unique_ptr < MutexLock > lock ( new MutexLock (
thread - > shared - > GetMutexForKey ( rand_column_families [ 0 ] , rand_keys [ 0 ] ) ) ) ;
ReadOptions read_opts_copy = read_opts ;
ReadOptions read_opts_copy = read_opts ;
std : : string read_ts_str ;
std : : string read_ts_str ;
Slice read_ts_slice ;
Slice read_ts_slice ;
@ -656,14 +659,16 @@ class NonBatchedOpsStressTest : public StressTest {
Status TestPut ( ThreadState * thread , WriteOptions & write_opts ,
Status TestPut ( ThreadState * thread , WriteOptions & write_opts ,
const ReadOptions & read_opts ,
const ReadOptions & read_opts ,
const std : : vector < int > & rand_column_families ,
const std : : vector < int > & rand_column_families ,
const std : : vector < int64_t > & rand_keys , char ( & value ) [ 100 ] ,
const std : : vector < int64_t > & rand_keys ,
std : : unique_ptr < MutexLock > & lock ) override {
char ( & value ) [ 100 ] ) override {
auto shared = thread - > shared ;
auto shared = thread - > shared ;
int64_t max_key = shared - > GetMaxKey ( ) ;
int64_t max_key = shared - > GetMaxKey ( ) ;
int64_t rand_key = rand_keys [ 0 ] ;
int64_t rand_key = rand_keys [ 0 ] ;
int rand_column_family = rand_column_families [ 0 ] ;
int rand_column_family = rand_column_families [ 0 ] ;
std : : string write_ts_str ;
std : : string write_ts_str ;
Slice write_ts ;
Slice write_ts ;
std : : unique_ptr < MutexLock > lock (
new MutexLock ( shared - > GetMutexForKey ( rand_column_family , rand_key ) ) ) ;
while ( ! shared - > AllowsOverwrite ( rand_key ) & &
while ( ! shared - > AllowsOverwrite ( rand_key ) & &
( FLAGS_use_merge | | shared - > Exists ( rand_column_family , rand_key ) ) ) {
( FLAGS_use_merge | | shared - > Exists ( rand_column_family , rand_key ) ) ) {
lock . reset ( ) ;
lock . reset ( ) ;
@ -758,12 +763,14 @@ class NonBatchedOpsStressTest : public StressTest {
Status TestDelete ( ThreadState * thread , WriteOptions & write_opts ,
Status TestDelete ( ThreadState * thread , WriteOptions & write_opts ,
const std : : vector < int > & rand_column_families ,
const std : : vector < int > & rand_column_families ,
const std : : vector < int64_t > & rand_keys ,
const std : : vector < int64_t > & rand_keys ) override {
std : : unique_ptr < MutexLock > & /* lock */ ) override {
int64_t rand_key = rand_keys [ 0 ] ;
int64_t rand_key = rand_keys [ 0 ] ;
int rand_column_family = rand_column_families [ 0 ] ;
int rand_column_family = rand_column_families [ 0 ] ;
auto shared = thread - > shared ;
auto shared = thread - > shared ;
std : : unique_ptr < MutexLock > lock (
new MutexLock ( shared - > GetMutexForKey ( rand_column_family , rand_key ) ) ) ;
// OPERATION delete
// OPERATION delete
std : : string write_ts_str = GetNowNanos ( ) ;
std : : string write_ts_str = GetNowNanos ( ) ;
Slice write_ts = write_ts_str ;
Slice write_ts = write_ts_str ;
@ -855,8 +862,7 @@ class NonBatchedOpsStressTest : public StressTest {
Status TestDeleteRange ( ThreadState * thread , WriteOptions & write_opts ,
Status TestDeleteRange ( ThreadState * thread , WriteOptions & write_opts ,
const std : : vector < int > & rand_column_families ,
const std : : vector < int > & rand_column_families ,
const std : : vector < int64_t > & rand_keys ,
const std : : vector < int64_t > & rand_keys ) override {
std : : unique_ptr < MutexLock > & lock ) override {
// OPERATION delete range
// OPERATION delete range
std : : vector < std : : unique_ptr < MutexLock > > range_locks ;
std : : vector < std : : unique_ptr < MutexLock > > range_locks ;
// delete range does not respect disallowed overwrites. the keys for
// delete range does not respect disallowed overwrites. the keys for
@ -868,16 +874,12 @@ class NonBatchedOpsStressTest : public StressTest {
auto shared = thread - > shared ;
auto shared = thread - > shared ;
int64_t max_key = shared - > GetMaxKey ( ) ;
int64_t max_key = shared - > GetMaxKey ( ) ;
if ( rand_key > max_key - FLAGS_range_deletion_width ) {
if ( rand_key > max_key - FLAGS_range_deletion_width ) {
lock . reset ( ) ;
rand_key =
rand_key =
thread - > rand . Next ( ) % ( max_key - FLAGS_range_deletion_width + 1 ) ;
thread - > rand . Next ( ) % ( max_key - FLAGS_range_deletion_width + 1 ) ;
range_locks . emplace_back (
new MutexLock ( shared - > GetMutexForKey ( rand_column_family , rand_key ) ) ) ;
} else {
range_locks . emplace_back ( std : : move ( lock ) ) ;
}
}
for ( int j = 1 ; j < FLAGS_range_deletion_width ; + + j ) {
for ( int j = 0 ; j < FLAGS_range_deletion_width ; + + j ) {
if ( ( ( rand_key + j ) & ( ( 1 < < FLAGS_log2_keys_per_lock ) - 1 ) ) = = 0 ) {
if ( j = = 0 | |
( ( rand_key + j ) & ( ( 1 < < FLAGS_log2_keys_per_lock ) - 1 ) ) = = 0 ) {
range_locks . emplace_back ( new MutexLock (
range_locks . emplace_back ( new MutexLock (
shared - > GetMutexForKey ( rand_column_family , rand_key + j ) ) ) ;
shared - > GetMutexForKey ( rand_column_family , rand_key + j ) ) ) ;
}
}
@ -918,8 +920,7 @@ class NonBatchedOpsStressTest : public StressTest {
void TestIngestExternalFile (
void TestIngestExternalFile (
ThreadState * /* thread */ ,
ThreadState * /* thread */ ,
const std : : vector < int > & /* rand_column_families */ ,
const std : : vector < int > & /* rand_column_families */ ,
const std : : vector < int64_t > & /* rand_keys */ ,
const std : : vector < int64_t > & /* rand_keys */ ) override {
std : : unique_ptr < MutexLock > & /* lock */ ) override {
assert ( false ) ;
assert ( false ) ;
fprintf ( stderr ,
fprintf ( stderr ,
" RocksDB lite does not support "
" RocksDB lite does not support "
@ -929,8 +930,7 @@ class NonBatchedOpsStressTest : public StressTest {
# else
# else
void TestIngestExternalFile ( ThreadState * thread ,
void TestIngestExternalFile ( ThreadState * thread ,
const std : : vector < int > & rand_column_families ,
const std : : vector < int > & rand_column_families ,
const std : : vector < int64_t > & rand_keys ,
const std : : vector < int64_t > & rand_keys ) override {
std : : unique_ptr < MutexLock > & lock ) override {
const std : : string sst_filename =
const std : : string sst_filename =
FLAGS_db + " /. " + std : : to_string ( thread - > tid ) + " .sst " ;
FLAGS_db + " /. " + std : : to_string ( thread - > tid ) + " .sst " ;
Status s ;
Status s ;
@ -960,9 +960,8 @@ class NonBatchedOpsStressTest : public StressTest {
s . ok ( ) & & key < shared - > GetMaxKey ( ) & &
s . ok ( ) & & key < shared - > GetMaxKey ( ) & &
static_cast < int32_t > ( keys . size ( ) ) < FLAGS_ingest_external_file_width ;
static_cast < int32_t > ( keys . size ( ) ) < FLAGS_ingest_external_file_width ;
+ + key ) {
+ + key ) {
if ( key = = key_base ) {
if ( key = = key_base | |
range_locks . emplace_back ( std : : move ( lock ) ) ;
( key & ( ( 1 < < FLAGS_log2_keys_per_lock ) - 1 ) ) = = 0 ) {
} else if ( ( key & ( ( 1 < < FLAGS_log2_keys_per_lock ) - 1 ) ) = = 0 ) {
range_locks . emplace_back (
range_locks . emplace_back (
new MutexLock ( shared - > GetMutexForKey ( column_family , key ) ) ) ;
new MutexLock ( shared - > GetMutexForKey ( column_family , key ) ) ) ;
}
}
@ -1006,8 +1005,7 @@ class NonBatchedOpsStressTest : public StressTest {
Status TestIterateAgainstExpected (
Status TestIterateAgainstExpected (
ThreadState * thread , const ReadOptions & read_opts ,
ThreadState * thread , const ReadOptions & read_opts ,
const std : : vector < int > & rand_column_families ,
const std : : vector < int > & rand_column_families ,
const std : : vector < int64_t > & rand_keys ,
const std : : vector < int64_t > & rand_keys ) override {
std : : unique_ptr < MutexLock > & lock ) override {
// Lock the whole range over which we might iterate to ensure it doesn't
// Lock the whole range over which we might iterate to ensure it doesn't
// change under us.
// change under us.
std : : vector < std : : unique_ptr < MutexLock > > range_locks ;
std : : vector < std : : unique_ptr < MutexLock > > range_locks ;
@ -1016,15 +1014,10 @@ class NonBatchedOpsStressTest : public StressTest {
auto shared = thread - > shared ;
auto shared = thread - > shared ;
int64_t max_key = shared - > GetMaxKey ( ) ;
int64_t max_key = shared - > GetMaxKey ( ) ;
if ( static_cast < uint64_t > ( lb ) > max_key - FLAGS_num_iterations ) {
if ( static_cast < uint64_t > ( lb ) > max_key - FLAGS_num_iterations ) {
lock . reset ( ) ;
lb = thread - > rand . Next ( ) % ( max_key - FLAGS_num_iterations + 1 ) ;
lb = thread - > rand . Next ( ) % ( max_key - FLAGS_num_iterations + 1 ) ;
range_locks . emplace_back (
new MutexLock ( shared - > GetMutexForKey ( rand_column_family , lb ) ) ) ;
} else {
range_locks . emplace_back ( std : : move ( lock ) ) ;
}
}
for ( int j = 1 ; j < static_cast < int > ( FLAGS_num_iterations ) ; + + j ) {
for ( int j = 0 ; j < static_cast < int > ( FLAGS_num_iterations ) ; + + j ) {
if ( ( ( lb + j ) & ( ( 1 < < FLAGS_log2_keys_per_lock ) - 1 ) ) = = 0 ) {
if ( j = = 0 | | ( ( lb + j ) & ( ( 1 < < FLAGS_log2_keys_per_lock ) - 1 ) ) = = 0 ) {
range_locks . emplace_back (
range_locks . emplace_back (
new MutexLock ( shared - > GetMutexForKey ( rand_column_family , lb + j ) ) ) ;
new MutexLock ( shared - > GetMutexForKey ( rand_column_family , lb + j ) ) ) ;
}
}