@ -419,7 +419,8 @@ class StressTest {
filter_policy_ ( FLAGS_bloom_bits > = 0
filter_policy_ ( FLAGS_bloom_bits > = 0
? NewBloomFilterPolicy ( FLAGS_bloom_bits )
? NewBloomFilterPolicy ( FLAGS_bloom_bits )
: NULL ) ,
: NULL ) ,
db_ ( NULL ) {
db_ ( NULL ) ,
num_times_reopened_ ( 0 ) {
std : : vector < std : : string > files ;
std : : vector < std : : string > files ;
FLAGS_env - > GetChildren ( FLAGS_db , & files ) ;
FLAGS_env - > GetChildren ( FLAGS_db , & files ) ;
for ( unsigned int i = 0 ; i < files . size ( ) ; i + + ) {
for ( unsigned int i = 0 ; i < files . size ( ) ; i + + ) {
@ -457,7 +458,9 @@ class StressTest {
shared . GetCondVar ( ) - > Wait ( ) ;
shared . GetCondVar ( ) - > Wait ( ) ;
}
}
fprintf ( stdout , " Starting database operations \n " ) ;
double now = FLAGS_env - > NowMicros ( ) ;
fprintf ( stdout , " %s Starting database operations \n " ,
FLAGS_env - > TimeToString ( ( uint64_t ) now / 1000000 ) . c_str ( ) ) ;
shared . SetStart ( ) ;
shared . SetStart ( ) ;
shared . GetCondVar ( ) - > SignalAll ( ) ;
shared . GetCondVar ( ) - > SignalAll ( ) ;
@ -465,7 +468,10 @@ class StressTest {
shared . GetCondVar ( ) - > Wait ( ) ;
shared . GetCondVar ( ) - > Wait ( ) ;
}
}
fprintf ( stdout , " Starting verification \n " ) ;
now = FLAGS_env - > NowMicros ( ) ;
fprintf ( stdout , " %s Starting verification \n " ,
FLAGS_env - > TimeToString ( ( uint64_t ) now / 1000000 ) . c_str ( ) ) ;
shared . SetStartVerify ( ) ;
shared . SetStartVerify ( ) ;
shared . GetCondVar ( ) - > SignalAll ( ) ;
shared . GetCondVar ( ) - > SignalAll ( ) ;
while ( ! shared . AllDone ( ) ) {
while ( ! shared . AllDone ( ) ) {
@ -482,7 +488,10 @@ class StressTest {
delete threads [ i ] ;
delete threads [ i ] ;
threads [ i ] = NULL ;
threads [ i ] = NULL ;
}
}
fprintf ( stdout , " Verification successful \n " ) ;
double now = FLAGS_env - > NowMicros ( ) ;
fprintf ( stdout , " %s Verification successful \n " ,
FLAGS_env - > TimeToString ( ( uint64_t ) now / 1000000 ) . c_str ( ) ) ;
PrintStatistics ( ) ;
PrintStatistics ( ) ;
}
}
@ -542,6 +551,7 @@ class StressTest {
for ( long i = 0 ; i < FLAGS_ops_per_thread ; i + + ) {
for ( long i = 0 ; i < FLAGS_ops_per_thread ; i + + ) {
if ( i ! = 0 & & ( i % ( FLAGS_ops_per_thread / ( FLAGS_reopen + 1 ) ) ) = = 0 ) {
if ( i ! = 0 & & ( i % ( FLAGS_ops_per_thread / ( FLAGS_reopen + 1 ) ) ) = = 0 ) {
{
{
thread - > stats . FinishedSingleOp ( ) ;
MutexLock l ( thread - > shared - > GetMutex ( ) ) ;
MutexLock l ( thread - > shared - > GetMutex ( ) ) ;
thread - > shared - > IncVotedReopen ( ) ;
thread - > shared - > IncVotedReopen ( ) ;
if ( thread - > shared - > AllVotedReopen ( ) ) {
if ( thread - > shared - > AllVotedReopen ( ) ) {
@ -551,6 +561,7 @@ class StressTest {
else {
else {
thread - > shared - > GetCondVar ( ) - > Wait ( ) ;
thread - > shared - > GetCondVar ( ) - > Wait ( ) ;
}
}
thread - > stats . Start ( ) ;
}
}
}
}
long rand_key = thread - > rand . Next ( ) % max_key ;
long rand_key = thread - > rand . Next ( ) % max_key ;
@ -667,7 +678,7 @@ class StressTest {
fprintf ( stdout , " Num keys per lock : %d \n " ,
fprintf ( stdout , " Num keys per lock : %d \n " ,
1 < < FLAGS_log2_keys_per_lock ) ;
1 < < FLAGS_log2_keys_per_lock ) ;
char * compression = " " ;
char * compression = ( char * ) std : : string ( " " ) . c_str ( ) ;
switch ( FLAGS_compression_type ) {
switch ( FLAGS_compression_type ) {
case leveldb : : kNoCompression :
case leveldb : : kNoCompression :
compression = ( char * ) std : : string ( " none " ) . c_str ( ) ;
compression = ( char * ) std : : string ( " none " ) . c_str ( ) ;
@ -722,7 +733,16 @@ class StressTest {
}
}
void Reopen ( ) {
void Reopen ( ) {
delete db_ ;
// do not close the db. Just delete the lock file. This
// simulates a crash-recovery kind of situation.
( ( DBImpl * ) db_ ) - > TEST_Destroy_DBImpl ( ) ;
db_ = NULL ;
num_times_reopened_ + + ;
double now = FLAGS_env - > NowMicros ( ) ;
fprintf ( stdout , " %s Reopening database for the %dth time \n " ,
FLAGS_env - > TimeToString ( ( uint64_t ) now / 1000000 ) . c_str ( ) ,
num_times_reopened_ ) ;
Open ( ) ;
Open ( ) ;
}
}
@ -739,6 +759,7 @@ class StressTest {
Cache * cache_ ;
Cache * cache_ ;
const FilterPolicy * filter_policy_ ;
const FilterPolicy * filter_policy_ ;
DB * db_ ;
DB * db_ ;
int num_times_reopened_ ;
} ;
} ;
} // namespace leveldb
} // namespace leveldb