@@ -1316,7 +1316,7 @@ int DBImpl::FindMinimumEmptyLevelFitting(int level) {
1316
1316
int minimum_level = level;
1317
1317
for (int i = level - 1 ; i > 0 ; --i) {
1318
1318
// stop if level i is not empty
1319
- if (versions_->NumLevelFiles (i) > 0 ) break ;
1319
+ if (versions_->current ()-> NumLevelFiles (i) > 0 ) break ;
1320
1320
1321
1321
// stop if level i is too small (cannot fit the level files)
1322
1322
if (versions_->MaxBytesForLevel (i) < versions_->NumLevelBytes (level)) break ;
@@ -2233,7 +2233,7 @@ Status DBImpl::DoCompactionWork(CompactionState* compact,
2233
2233
compact->compaction ->Summary (scratch, sizeof (scratch));
2234
2234
Log (options_.info_log , " Compaction start summary: %s\n " , scratch);
2235
2235
2236
- assert (versions_->NumLevelFiles (compact->compaction ->level ()) > 0 );
2236
+ assert (versions_->current ()-> NumLevelFiles (compact->compaction ->level ()) > 0 );
2237
2237
assert (compact->builder == nullptr );
2238
2238
assert (!compact->outfile );
2239
2239
@@ -3207,7 +3207,7 @@ Status DBImpl::MakeRoomForWrite(bool force,
3207
3207
{
3208
3208
StopWatch sw (env_, options_.statistics .get (), STALL_L0_SLOWDOWN_COUNT);
3209
3209
env_->SleepForMicroseconds (
3210
- SlowdownAmount (versions_->NumLevelFiles (0 ),
3210
+ SlowdownAmount (versions_->current ()-> NumLevelFiles (0 ),
3211
3211
options_.level0_slowdown_writes_trigger ,
3212
3212
options_.level0_stop_writes_trigger )
3213
3213
);
@@ -3242,7 +3242,7 @@ Status DBImpl::MakeRoomForWrite(bool force,
3242
3242
STALL_MEMTABLE_COMPACTION_MICROS, stall);
3243
3243
stall_memtable_compaction_ += stall;
3244
3244
stall_memtable_compaction_count_++;
3245
- } else if (versions_->NumLevelFiles (0 ) >=
3245
+ } else if (versions_->current ()-> NumLevelFiles (0 ) >=
3246
3246
options_.level0_stop_writes_trigger ) {
3247
3247
// There are too many level-0 files.
3248
3248
DelayLoggingAndReset ();
@@ -3372,6 +3372,7 @@ bool DBImpl::GetProperty(const Slice& property, std::string* value) {
3372
3372
value->clear ();
3373
3373
3374
3374
MutexLock l (&mutex_);
3375
+ Version* current = versions_->current ();
3375
3376
Slice in = property;
3376
3377
Slice prefix (" rocksdb." );
3377
3378
if (!in.starts_with (prefix)) return false ;
@@ -3386,7 +3387,7 @@ bool DBImpl::GetProperty(const Slice& property, std::string* value) {
3386
3387
} else {
3387
3388
char buf[100 ];
3388
3389
snprintf (buf, sizeof (buf), " %d" ,
3389
- versions_ ->NumLevelFiles (static_cast <int >(level)));
3390
+ current ->NumLevelFiles (static_cast <int >(level)));
3390
3391
*value = buf;
3391
3392
return true ;
3392
3393
}
@@ -3401,7 +3402,7 @@ bool DBImpl::GetProperty(const Slice& property, std::string* value) {
3401
3402
snprintf (buf, sizeof (buf),
3402
3403
" %3d %8d %8.0f\n " ,
3403
3404
level,
3404
- versions_ ->NumLevelFiles (level),
3405
+ current ->NumLevelFiles (level),
3405
3406
versions_->NumLevelBytes (level) / 1048576.0 );
3406
3407
value->append (buf);
3407
3408
}
@@ -3446,7 +3447,7 @@ bool DBImpl::GetProperty(const Slice& property, std::string* value) {
3446
3447
);
3447
3448
value->append (buf);
3448
3449
for (int level = 0 ; level < NumberLevels (); level++) {
3449
- int files = versions_ ->NumLevelFiles (level);
3450
+ int files = current ->NumLevelFiles (level);
3450
3451
if (stats_[level].micros > 0 || files > 0 ) {
3451
3452
int64_t bytes_read = stats_[level].bytes_readn +
3452
3453
stats_[level].bytes_readnp1 ;
@@ -3728,7 +3729,7 @@ Status DBImpl::DeleteFile(std::string name) {
3728
3729
// This is to make sure that any deletion tombstones are not
3729
3730
// lost. Check that the level passed is the last level.
3730
3731
for (int i = level + 1 ; i < maxlevel; i++) {
3731
- if (versions_->NumLevelFiles (i) != 0 ) {
3732
+ if (versions_->current ()-> NumLevelFiles (i) != 0 ) {
3732
3733
Log (options_.info_log ,
3733
3734
" DeleteFile %s FAILED. File not in last level\n " , name.c_str ());
3734
3735
return Status::InvalidArgument (" File not in last level" );
@@ -3853,12 +3854,11 @@ Status DB::Open(const Options& options, const std::string& dbname, DB** dbptr) {
3853
3854
impl->MaybeScheduleLogDBDeployStats ();
3854
3855
}
3855
3856
}
3856
- impl->mutex_ .Unlock ();
3857
3857
3858
- if (impl->options_ .compaction_style == kCompactionStyleUniversal ) {
3859
- int num_files ;
3858
+ if (s. ok () && impl->options_ .compaction_style == kCompactionStyleUniversal ) {
3859
+ Version* current = impl-> versions_ -> current () ;
3860
3860
for (int i = 1 ; i < impl->NumberLevels (); i++) {
3861
- num_files = impl-> versions_ ->NumLevelFiles (i);
3861
+ int num_files = current ->NumLevelFiles (i);
3862
3862
if (num_files > 0 ) {
3863
3863
s = Status::InvalidArgument (" Not all files are at level 0. Cannot "
3864
3864
" open with universal compaction style." );
@@ -3867,6 +3867,8 @@ Status DB::Open(const Options& options, const std::string& dbname, DB** dbptr) {
3867
3867
}
3868
3868
}
3869
3869
3870
+ impl->mutex_ .Unlock ();
3871
+
3870
3872
if (s.ok ()) {
3871
3873
*dbptr = impl;
3872
3874
} else {
0 commit comments