Skip to content

Commit 511b03a

Browse files
committed
LogAndApply to take ColumnFamilyData
Summary: This removes the default implementation of LogAndApply that applied the changed to the default column family by default. It is mostly simple reformatting. Test Plan: make check Reviewers: dhruba, kailiu CC: leveldb Differential Revision: https://reviews.facebook.net/D15465
1 parent eb05560 commit 511b03a

6 files changed

+30
-31
lines changed

db/db_impl.cc

+15-11
Original file line numberDiff line numberDiff line change
@@ -1009,7 +1009,7 @@ Status DBImpl::RecoverLogFile(uint64_t log_number, SequenceNumber* max_sequence,
10091009
// Since we already recovered log_number, we want all logs
10101010
// with numbers `<= log_number` (includes this one) to be ignored
10111011
edit.SetLogNumber(log_number + 1);
1012-
status = versions_->LogAndApply(&edit, &mutex_);
1012+
status = versions_->LogAndApply(default_cfd_, &edit, &mutex_);
10131013
}
10141014

10151015
return status;
@@ -1204,8 +1204,9 @@ Status DBImpl::FlushMemTableToOutputFile(bool* madeProgress,
12041204

12051205
// Replace immutable memtable with the generated Table
12061206
s = default_cfd_->imm.InstallMemtableFlushResults(
1207-
mems, versions_.get(), s, &mutex_, options_.info_log.get(), file_number,
1208-
pending_outputs_, &deletion_state.memtables_to_free, db_directory_.get());
1207+
default_cfd_, mems, versions_.get(), s, &mutex_, options_.info_log.get(),
1208+
file_number, pending_outputs_, &deletion_state.memtables_to_free,
1209+
db_directory_.get());
12091210

12101211
if (s.ok()) {
12111212
InstallSuperVersion(default_cfd_, deletion_state);
@@ -1333,7 +1334,8 @@ Status DBImpl::ReFitLevel(int level, int target_level) {
13331334
Log(options_.info_log, "Apply version edit:\n%s",
13341335
edit.DebugString().data());
13351336

1336-
status = versions_->LogAndApply(&edit, &mutex_, db_directory_.get());
1337+
status = versions_->LogAndApply(default_cfd_, &edit, &mutex_,
1338+
db_directory_.get());
13371339
superversion_to_free = InstallSuperVersion(default_cfd_, new_superversion);
13381340
new_superversion = nullptr;
13391341

@@ -1906,7 +1908,8 @@ Status DBImpl::BackgroundCompaction(bool* madeProgress,
19061908
c->edit()->AddFile(c->level() + 1, f->number, f->file_size,
19071909
f->smallest, f->largest,
19081910
f->smallest_seqno, f->largest_seqno);
1909-
status = versions_->LogAndApply(c->edit(), &mutex_, db_directory_.get());
1911+
status = versions_->LogAndApply(default_cfd_, c->edit(), &mutex_,
1912+
db_directory_.get());
19101913
InstallSuperVersion(default_cfd_, deletion_state);
19111914

19121915
Version::LevelSummaryStorage tmp;
@@ -2155,8 +2158,8 @@ Status DBImpl::InstallCompactionResults(CompactionState* compact) {
21552158
compact->compaction->output_level(), out.number, out.file_size,
21562159
out.smallest, out.largest, out.smallest_seqno, out.largest_seqno);
21572160
}
2158-
return versions_->LogAndApply(compact->compaction->edit(), &mutex_,
2159-
db_directory_.get());
2161+
return versions_->LogAndApply(default_cfd_, compact->compaction->edit(),
2162+
&mutex_, db_directory_.get());
21602163
}
21612164

21622165
//
@@ -2949,7 +2952,7 @@ Status DBImpl::CreateColumnFamily(const ColumnFamilyOptions& options,
29492952
edit.AddColumnFamily(column_family_name);
29502953
handle->id = versions_->GetColumnFamilySet()->GetNextColumnFamilyID();
29512954
edit.SetColumnFamily(handle->id);
2952-
Status s = versions_->LogAndApply(&edit, &mutex_);
2955+
Status s = versions_->LogAndApply(default_cfd_, &edit, &mutex_);
29532956
if (s.ok()) {
29542957
// add to internal data structures
29552958
versions_->CreateColumnFamily(options, &edit);
@@ -2968,7 +2971,7 @@ Status DBImpl::DropColumnFamily(const ColumnFamilyHandle& column_family) {
29682971
VersionEdit edit;
29692972
edit.DropColumnFamily();
29702973
edit.SetColumnFamily(column_family.id);
2971-
Status s = versions_->LogAndApply(&edit, &mutex_);
2974+
Status s = versions_->LogAndApply(default_cfd_, &edit, &mutex_);
29722975
if (s.ok()) {
29732976
// remove from internal data structures
29742977
versions_->DropColumnFamily(&edit);
@@ -3830,7 +3833,8 @@ Status DBImpl::DeleteFile(std::string name) {
38303833
}
38313834
}
38323835
edit.DeleteFile(level, number);
3833-
status = versions_->LogAndApply(&edit, &mutex_, db_directory_.get());
3836+
status = versions_->LogAndApply(default_cfd_, &edit, &mutex_,
3837+
db_directory_.get());
38343838
if (status.ok()) {
38353839
InstallSuperVersion(default_cfd_, deletion_state);
38363840
}
@@ -3977,7 +3981,7 @@ Status DB::OpenWithColumnFamilies(
39773981
edit.SetLogNumber(new_log_number);
39783982
impl->logfile_number_ = new_log_number;
39793983
impl->log_.reset(new log::Writer(std::move(lfile)));
3980-
s = impl->versions_->LogAndApply(&edit, &impl->mutex_,
3984+
s = impl->versions_->LogAndApply(impl->default_cfd_, &edit, &impl->mutex_,
39813985
impl->db_directory_.get());
39823986
}
39833987
if (s.ok()) {

db/db_test.cc

+3-2
Original file line numberDiff line numberDiff line change
@@ -5046,14 +5046,15 @@ void BM_LogAndApply(int iters, int num_base_files) {
50465046
std::vector<ColumnFamilyDescriptor> dummy;
50475047
dummy.push_back(ColumnFamilyDescriptor());
50485048
ASSERT_OK(vset.Recover(dummy));
5049+
auto default_cfd = vset.GetColumnFamilySet()->GetDefault();
50495050
VersionEdit vbase;
50505051
uint64_t fnum = 1;
50515052
for (int i = 0; i < num_base_files; i++) {
50525053
InternalKey start(MakeKey(2*fnum), 1, kTypeValue);
50535054
InternalKey limit(MakeKey(2*fnum+1), 1, kTypeDeletion);
50545055
vbase.AddFile(2, fnum++, 1 /* file size */, start, limit, 1, 1);
50555056
}
5056-
ASSERT_OK(vset.LogAndApply(&vbase, &mu));
5057+
ASSERT_OK(vset.LogAndApply(default_cfd, &vbase, &mu));
50575058

50585059
uint64_t start_micros = env->NowMicros();
50595060

@@ -5063,7 +5064,7 @@ void BM_LogAndApply(int iters, int num_base_files) {
50635064
InternalKey start(MakeKey(2*fnum), 1, kTypeValue);
50645065
InternalKey limit(MakeKey(2*fnum+1), 1, kTypeDeletion);
50655066
vedit.AddFile(2, fnum++, 1 /* file size */, start, limit, 1, 1);
5066-
vset.LogAndApply(&vedit, &mu);
5067+
vset.LogAndApply(default_cfd, &vedit, &mu);
50675068
}
50685069
uint64_t stop_micros = env->NowMicros();
50695070
unsigned int us = stop_micros - start_micros;

db/memtablelist.cc

+3-3
Original file line numberDiff line numberDiff line change
@@ -122,8 +122,8 @@ void MemTableList::PickMemtablesToFlush(std::vector<MemTable*>* ret) {
122122

123123
// Record a successful flush in the manifest file
124124
Status MemTableList::InstallMemtableFlushResults(
125-
const std::vector<MemTable*>& mems, VersionSet* vset, Status flushStatus,
126-
port::Mutex* mu, Logger* info_log, uint64_t file_number,
125+
ColumnFamilyData* cfd, const std::vector<MemTable*>& mems, VersionSet* vset,
126+
Status flushStatus, port::Mutex* mu, Logger* info_log, uint64_t file_number,
127127
std::set<uint64_t>& pending_outputs, std::vector<MemTable*>* to_delete,
128128
Directory* db_directory) {
129129
mu->AssertHeld();
@@ -177,7 +177,7 @@ Status MemTableList::InstallMemtableFlushResults(
177177
(unsigned long)m->file_number_);
178178

179179
// this can release and reacquire the mutex.
180-
s = vset->LogAndApply(&m->edit_, mu, db_directory);
180+
s = vset->LogAndApply(cfd, &m->edit_, mu, db_directory);
181181

182182
// we will be changing the version in the next code path,
183183
// so we better create a new one, since versions are immutable

db/memtablelist.h

+7-7
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#include <string>
99
#include <list>
1010
#include <vector>
11+
#include <set>
1112
#include "rocksdb/db.h"
1213
#include "rocksdb/options.h"
1314
#include "rocksdb/iterator.h"
@@ -17,6 +18,7 @@
1718

1819
namespace rocksdb {
1920

21+
class ColumnFamilyData;
2022
class InternalKeyComparator;
2123
class Mutex;
2224

@@ -90,13 +92,11 @@ class MemTableList {
9092
void PickMemtablesToFlush(std::vector<MemTable*>* mems);
9193

9294
// Commit a successful flush in the manifest file
93-
Status InstallMemtableFlushResults(const std::vector<MemTable*>& m,
94-
VersionSet* vset, Status flushStatus,
95-
port::Mutex* mu, Logger* info_log,
96-
uint64_t file_number,
97-
std::set<uint64_t>& pending_outputs,
98-
std::vector<MemTable*>* to_delete,
99-
Directory* db_directory);
95+
Status InstallMemtableFlushResults(
96+
ColumnFamilyData* cfd, const std::vector<MemTable*>& m, VersionSet* vset,
97+
Status flushStatus, port::Mutex* mu, Logger* info_log,
98+
uint64_t file_number, std::set<uint64_t>& pending_outputs,
99+
std::vector<MemTable*>* to_delete, Directory* db_directory);
100100

101101
// New memtables are inserted at the front of the list.
102102
// Takes ownership of the referenced held on *m by the caller of Add().

db/version_set.cc

+2-1
Original file line numberDiff line numberDiff line change
@@ -1973,7 +1973,8 @@ Status VersionSet::ReduceNumberOfLevels(const std::string& dbname,
19731973
VersionEdit ve;
19741974
port::Mutex dummy_mutex;
19751975
MutexLock l(&dummy_mutex);
1976-
return versions.LogAndApply(&ve, &dummy_mutex, nullptr, true);
1976+
return versions.LogAndApply(versions.GetColumnFamilySet()->GetDefault(), &ve,
1977+
&dummy_mutex, nullptr, true);
19771978
}
19781979

19791980
Status VersionSet::DumpManifest(Options& options, std::string& dscname,

db/version_set.h

-7
Original file line numberDiff line numberDiff line change
@@ -292,13 +292,6 @@ class VersionSet {
292292
port::Mutex* mu, Directory* db_directory = nullptr,
293293
bool new_descriptor_log = false);
294294

295-
Status LogAndApply(VersionEdit* edit, port::Mutex* mu,
296-
Directory* db_directory = nullptr,
297-
bool new_descriptor_log = false) {
298-
return LogAndApply(column_family_set_->GetDefault(), edit, mu, db_directory,
299-
new_descriptor_log);
300-
}
301-
302295
// Recover the last saved descriptor from persistent storage.
303296
Status Recover(const std::vector<ColumnFamilyDescriptor>& column_families);
304297

0 commit comments

Comments
 (0)