@ -113,14 +113,14 @@ Options SanitizeOptions(const std::string& dbname,
return result ;
}
DBImpl : : DBImpl ( const Options & options , const std : : string & dbname )
: env_ ( options . env ) ,
internal_comparator_ ( options . comparator ) ,
internal_filter_policy_ ( options . filter_policy ) ,
options_ ( SanitizeOptions (
dbname , & internal_comparator_ , & internal_filter_policy_ , options ) ) ,
owns_info_log_ ( options_ . info_log ! = options . info_log ) ,
owns_cache_ ( options_ . block_cache ! = options . block_cache ) ,
DBImpl : : DBImpl ( const Options & raw_ options, const std : : string & dbname )
: env_ ( raw_ options. env ) ,
internal_comparator_ ( raw_ options. comparator ) ,
internal_filter_policy_ ( raw_ options. filter_policy ) ,
options_ ( SanitizeOptions ( dbname , & internal_comparator_ ,
& internal_filter_policy_ , raw_ options) ) ,
owns_info_log_ ( options_ . info_log ! = raw_ options. info_log ) ,
owns_cache_ ( options_ . block_cache ! = raw_ options. block_cache ) ,
dbname_ ( dbname ) ,
db_lock_ ( NULL ) ,
shutting_down_ ( NULL ) ,
@ -130,6 +130,7 @@ DBImpl::DBImpl(const Options& options, const std::string& dbname)
logfile_ ( NULL ) ,
logfile_number_ ( 0 ) ,
log_ ( NULL ) ,
seed_ ( 0 ) ,
tmp_batch_ ( new WriteBatch ) ,
bg_compaction_scheduled_ ( false ) ,
manual_compaction_ ( NULL ) ,
@ -138,7 +139,7 @@ DBImpl::DBImpl(const Options& options, const std::string& dbname)
has_imm_ . Release_Store ( NULL ) ;
// Reserve ten files or so for other uses and give the rest to TableCache.
const int table_cache_size = options . max_open_files - kNumNonTableCacheFiles ;
const int table_cache_size = options_ . max_open_files - kNumNonTableCacheFiles ;
table_cache_ = new TableCache ( dbname_ , & options_ , table_cache_size ) ;
versions_ = new VersionSet ( dbname_ , & options_ , table_cache_ ,
@ -1027,7 +1028,8 @@ static void CleanupIteratorState(void* arg1, void* arg2) {
} // namespace
Iterator * DBImpl : : NewInternalIterator ( const ReadOptions & options ,
SequenceNumber * latest_snapshot ) {
SequenceNumber * latest_snapshot ,
uint32_t * seed ) {
IterState * cleanup = new IterState ;
mutex_ . Lock ( ) ;
* latest_snapshot = versions_ - > LastSequence ( ) ;
@ -1051,13 +1053,15 @@ Iterator* DBImpl::NewInternalIterator(const ReadOptions& options,
cleanup - > version = versions_ - > current ( ) ;
internal_iter - > RegisterCleanup ( CleanupIteratorState , cleanup , NULL ) ;
* seed = + + seed_ ;
mutex_ . Unlock ( ) ;
return internal_iter ;
}
Iterator * DBImpl : : TEST_NewInternalIterator ( ) {
SequenceNumber ignored ;
return NewInternalIterator ( ReadOptions ( ) , & ignored ) ;
uint32_t ignored_seed ;
return NewInternalIterator ( ReadOptions ( ) , & ignored , & ignored_seed ) ;
}
int64_t DBImpl : : TEST_MaxNextLevelOverlappingBytes ( ) {
@ -1114,12 +1118,21 @@ Status DBImpl::Get(const ReadOptions& options,
Iterator * DBImpl : : NewIterator ( const ReadOptions & options ) {
SequenceNumber latest_snapshot ;
Iterator * internal_iter = NewInternalIterator ( options , & latest_snapshot ) ;
uint32_t seed ;
Iterator * iter = NewInternalIterator ( options , & latest_snapshot , & seed ) ;
return NewDBIterator (
& dbname_ , env_ , user_comparator ( ) , internal_ iter,
this , user_comparator ( ) , iter ,
( options . snapshot ! = NULL
? reinterpret_cast < const SnapshotImpl * > ( options . snapshot ) - > number_
: latest_snapshot ) ) ;
: latest_snapshot ) ,
seed ) ;
}
void DBImpl : : RecordReadSample ( Slice key ) {
MutexLock l ( & mutex_ ) ;
if ( versions_ - > current ( ) - > RecordReadSample ( key ) ) {
MaybeScheduleCompaction ( ) ;
}
}
const Snapshot * DBImpl : : GetSnapshot ( ) {