@ -57,7 +57,7 @@ class DBIter: public Iterator {
direction_ ( kForward ) ,
direction_ ( kForward ) ,
valid_ ( false ) ,
valid_ ( false ) ,
rnd_ ( seed ) ,
rnd_ ( seed ) ,
bytes_counter _ ( RandomPeriod ( ) ) {
bytes_until_read_sampling _ ( RandomCompaction Period ( ) ) {
}
}
virtual ~ DBIter ( ) {
virtual ~ DBIter ( ) {
delete iter_ ;
delete iter_ ;
@ -103,8 +103,8 @@ class DBIter: public Iterator {
}
}
}
}
// Pick next gap with average value of config::kReadBytesPerio d.
ss ize_t RandomPeriod ( ) {
// Picks the number of bytes that can be read until a compaction is schedule d.
size_t RandomCompaction Period ( ) {
return rnd_ . Uniform ( 2 * config : : kReadBytesPeriod ) ;
return rnd_ . Uniform ( 2 * config : : kReadBytesPeriod ) ;
}
}
@ -120,7 +120,7 @@ class DBIter: public Iterator {
bool valid_ ;
bool valid_ ;
Random rnd_ ;
Random rnd_ ;
ssize_t bytes_counter _ ;
size_t bytes_until_read_sampling _ ;
// No copying allowed
// No copying allowed
DBIter ( const DBIter & ) ;
DBIter ( const DBIter & ) ;
@ -129,12 +129,15 @@ class DBIter: public Iterator {
inline bool DBIter : : ParseKey ( ParsedInternalKey * ikey ) {
inline bool DBIter : : ParseKey ( ParsedInternalKey * ikey ) {
Slice k = iter_ - > key ( ) ;
Slice k = iter_ - > key ( ) ;
ssize_t n = k . size ( ) + iter_ - > value ( ) . size ( ) ;
bytes_counter_ - = n ;
while ( bytes_counter_ < 0 ) {
bytes_counter _ + = RandomPeriod ( ) ;
size_t bytes_read = k . size ( ) + iter_ - > value ( ) . size ( ) ;
while ( bytes_until_read_sampling_ < bytes_read ) {
bytes_until_read_sampling _ + = RandomCompaction Period ( ) ;
db_ - > RecordReadSample ( k ) ;
db_ - > RecordReadSample ( k ) ;
}
}
assert ( bytes_until_read_sampling_ > = bytes_read ) ;
bytes_until_read_sampling_ - = bytes_read ;
if ( ! ParseInternalKey ( k , ikey ) ) {
if ( ! ParseInternalKey ( k , ikey ) ) {
status_ = Status : : Corruption ( " corrupted internal key in DBIter " ) ;
status_ = Status : : Corruption ( " corrupted internal key in DBIter " ) ;
return false ;
return false ;