Skip to content

Commit

Permalink
refactor: rename 'value_schema_version' to 'pegasus data version' (#15)
Browse files Browse the repository at this point in the history
  • Loading branch information
acelyc111 authored Apr 18, 2019
1 parent 86d7fd6 commit 441dd88
Show file tree
Hide file tree
Showing 18 changed files with 62 additions and 62 deletions.
8 changes: 4 additions & 4 deletions db/column_family.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1006,7 +1006,7 @@ ColumnFamilySet::ColumnFamilySet(const std::string& dbname,
WriteBufferManager* write_buffer_manager,
WriteController* write_controller)
: max_column_family_(0),
value_schema_version_(db_options->default_value_schema_version),
pegasus_data_version_(db_options->pegasus_data_version),
last_manual_compact_finish_time_(0),
dummy_cfd_(new ColumnFamilyData(0, "", nullptr, nullptr, nullptr,
ColumnFamilyOptions(), *db_options,
Expand Down Expand Up @@ -1074,10 +1074,10 @@ size_t ColumnFamilySet::NumberOfColumnFamilies() const {
return column_families_.size();
}

uint32_t ColumnFamilySet::GetValueSchemaVersion() { return value_schema_version_; }
uint32_t ColumnFamilySet::GetPegasusDataVersion() const { return pegasus_data_version_; }

void ColumnFamilySet::SetValueSchemaVersion(uint32_t version) {
value_schema_version_ = version;
void ColumnFamilySet::SetPegasusDataVersion(uint32_t version) {
pegasus_data_version_ = version;
}

uint64_t ColumnFamilySet::GetLastManualCompactFinishTime() {
Expand Down
7 changes: 3 additions & 4 deletions db/column_family.h
Original file line number Diff line number Diff line change
Expand Up @@ -482,9 +482,8 @@ class ColumnFamilySet {
uint32_t GetMaxColumnFamily();
void UpdateMaxColumnFamily(uint32_t new_max_column_family);
size_t NumberOfColumnFamilies() const;
// Get and set value schema version.
uint32_t GetValueSchemaVersion();
void SetValueSchemaVersion(uint32_t version);
uint32_t GetPegasusDataVersion() const;
void SetPegasusDataVersion(uint32_t version);
uint64_t GetLastManualCompactFinishTime();
void SetLastManualCompactFinishTime(uint64_t ms);
ColumnFamilyData* CreateColumnFamily(const std::string& name, uint32_t id,
Expand Down Expand Up @@ -517,7 +516,7 @@ class ColumnFamilySet {
std::unordered_map<uint32_t, ColumnFamilyData*> column_family_data_;

uint32_t max_column_family_;
uint32_t value_schema_version_;
uint32_t pegasus_data_version_;
uint64_t last_manual_compact_finish_time_;
ColumnFamilyData* dummy_cfd_;
// We don't hold the refcount here, since default column family always exists
Expand Down
1 change: 0 additions & 1 deletion db/compaction_job_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,6 @@ class CompactionJobTest : public testing::Test {
new_db.SetLogNumber(0);
new_db.SetNextFile(2);
new_db.SetLastSequence(0);
new_db.SetValueSchemaVersion(0);

const std::string manifest = DescriptorFileName(dbname_, 1);
unique_ptr<WritableFile> file;
Expand Down
10 changes: 5 additions & 5 deletions db/db_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -764,11 +764,11 @@ uint64_t DBImpl::GetLastFlushedDecree() {
return d;
}

uint32_t DBImpl::GetValueSchemaVersion() {
mutex_.Lock();
uint32_t version = versions_->GetColumnFamilySet()->GetValueSchemaVersion();
mutex_.Unlock();
return version;
uint32_t DBImpl::GetPegasusDataVersion() const {
mutex_.Lock();
uint32_t version = versions_->GetColumnFamilySet()->GetPegasusDataVersion();
mutex_.Unlock();
return version;
}

uint64_t DBImpl::GetLastManualCompactFinishTime() {
Expand Down
2 changes: 1 addition & 1 deletion db/db_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ class DBImpl : public DB {

virtual uint64_t GetLastFlushedDecree() override;

virtual uint32_t GetValueSchemaVersion() override;
virtual uint32_t GetPegasusDataVersion() const override;

virtual uint64_t GetLastManualCompactFinishTime() override;

Expand Down
2 changes: 1 addition & 1 deletion db/db_impl_open.cc
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ Status DBImpl::NewDB() {
new_db.SetLogNumber(0);
new_db.SetNextFile(2);
new_db.SetLastSequence(0);
new_db.SetValueSchemaVersion(immutable_db_options_.default_value_schema_version);
new_db.SetPegasusDataVersion(immutable_db_options_.pegasus_data_version);

Status s;

Expand Down
1 change: 0 additions & 1 deletion db/flush_job_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ class FlushJobTest : public testing::Test {
new_db.SetLogNumber(0);
new_db.SetNextFile(2);
new_db.SetLastSequence(0);
new_db.SetValueSchemaVersion(0);

const std::string manifest = DescriptorFileName(dbname_, 1);
unique_ptr<WritableFile> file;
Expand Down
22 changes: 11 additions & 11 deletions db/version_edit.cc
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ void VersionEdit::Clear() {
last_flush_decree_ = 0;
next_file_number_ = 0;
max_column_family_ = 0;
value_schema_version_ = 0;
pegasus_data_version_ = 0;
last_manual_compact_finish_time_ = 0;
has_comparator_ = false;
has_log_number_ = false;
Expand All @@ -77,7 +77,7 @@ void VersionEdit::Clear() {
has_last_sequence_ = false;
has_last_flush_seq_decree_ = false;
has_max_column_family_ = false;
has_value_schema_version_ = false;
has_pegasus_data_version_ = false;
has_last_manual_compact_finish_time_ = false;
deleted_files_.clear();
new_files_.clear();
Expand Down Expand Up @@ -112,9 +112,9 @@ bool VersionEdit::EncodeTo(std::string* dst) const {
if (has_max_column_family_) {
PutVarint32Varint32(dst, kMaxColumnFamily, max_column_family_);
}
if (has_value_schema_version_) {
if (has_pegasus_data_version_) {
PutVarint32(dst, kValueSchemaVersion);
PutVarint32(dst, value_schema_version_);
PutVarint32(dst, pegasus_data_version_);
}
if (has_last_manual_compact_finish_time_) {
PutVarint32(dst, kLastManualCompactFinishTime);
Expand Down Expand Up @@ -363,10 +363,10 @@ Status VersionEdit::DecodeFrom(const Slice& src) {
break;

case kValueSchemaVersion:
if (GetVarint32(&input, &value_schema_version_)) {
has_value_schema_version_ = true;
if (GetVarint32(&input, &pegasus_data_version_)) {
has_pegasus_data_version_ = true;
} else {
msg = "value schema version";
msg = "Pegasus data version";
}
break;

Expand Down Expand Up @@ -574,9 +574,9 @@ std::string VersionEdit::DebugString(bool hex_key) const {
r.append("\n MaxColumnFamily: ");
AppendNumberTo(&r, max_column_family_);
}
if (has_value_schema_version_) {
if (has_pegasus_data_version_) {
r.append("\n ValueSchemaVersion: ");
AppendNumberTo(&r, value_schema_version_);
AppendNumberTo(&r, pegasus_data_version_);
}
if (has_last_manual_compact_finish_time_) {
r.append("\n LastManualCompactFinishTime: ");
Expand Down Expand Up @@ -655,8 +655,8 @@ std::string VersionEdit::DebugJSON(int edit_num, bool hex_key) const {
if (has_max_column_family_) {
jw << "MaxColumnFamily" << max_column_family_;
}
if (has_value_schema_version_) {
jw << "ValueSchemaVersion" << value_schema_version_;
if (has_pegasus_data_version_) {
jw << "PegasusDataVersion" << pegasus_data_version_;
}
if (has_last_manual_compact_finish_time_) {
jw << "LastManualCompactFinishTime" << last_manual_compact_finish_time_;
Expand Down
10 changes: 5 additions & 5 deletions db/version_edit.h
Original file line number Diff line number Diff line change
Expand Up @@ -199,9 +199,9 @@ class VersionEdit {
max_column_family_ = max_column_family;
}

void SetValueSchemaVersion(uint32_t value_schema_version) {
has_value_schema_version_ = true;
value_schema_version_ = value_schema_version;
void SetPegasusDataVersion(uint32_t pegasus_data_version) {
has_pegasus_data_version_ = true;
pegasus_data_version_ = pegasus_data_version;
}

void SetLastManualCompactFinishTime(uint64_t ms) {
Expand Down Expand Up @@ -320,7 +320,7 @@ class VersionEdit {
uint64_t prev_log_number_;
uint64_t next_file_number_;
uint32_t max_column_family_;
uint32_t value_schema_version_;
uint32_t pegasus_data_version_;
uint64_t last_manual_compact_finish_time_;
SequenceNumber last_sequence_;
// Used to mark the last sequence/decree of flushed memtables.
Expand All @@ -334,7 +334,7 @@ class VersionEdit {
bool has_last_sequence_;
bool has_last_flush_seq_decree_;
bool has_max_column_family_;
bool has_value_schema_version_;
bool has_pegasus_data_version_;
bool has_last_manual_compact_finish_time_;

DeletedFileSet deleted_files_;
Expand Down
34 changes: 17 additions & 17 deletions db/version_set.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2595,9 +2595,9 @@ Status VersionSet::LogAndApply(ColumnFamilyData* column_family_data,
w.edit_list.front()->SetMaxColumnFamily(
column_family_set_->GetMaxColumnFamily());
}
// also we need to persist value schema version
w.edit_list.front()->SetValueSchemaVersion(
column_family_set_->GetValueSchemaVersion());
// also we need to persist Pegasus data version
w.edit_list.front()->SetPegasusDataVersion(
column_family_set_->GetPegasusDataVersion());
}

// Unlock during expensive operations. New writes cannot get here
Expand Down Expand Up @@ -2898,14 +2898,14 @@ Status VersionSet::Recover(
bool have_prev_log_number = false;
bool have_next_file = false;
bool have_last_sequence = false;
bool have_value_schema_version = false;
bool have_pegasus_data_version = false;
bool have_last_manual_compact_finish_time = false;
uint64_t next_file = 0;
uint64_t last_sequence = 0;
uint64_t log_number = 0;
uint64_t previous_log_number = 0;
uint32_t max_column_family = 0;
uint32_t value_schema_version = 0;
uint32_t pegasus_data_version = 0;
uint64_t last_manual_compact_finish_time = 0;
std::unordered_map<uint32_t, BaseReferencedVersionBuilder*> builders;
std::unordered_map<uint32_t, std::pair<uint64_t, uint64_t>> last_flush_seq_decree_map;
Expand Down Expand Up @@ -3048,9 +3048,9 @@ Status VersionSet::Recover(
max_column_family = edit.max_column_family_;
}

if (edit.has_value_schema_version_) {
value_schema_version = edit.value_schema_version_;
have_value_schema_version = true;
if (edit.has_pegasus_data_version_) {
pegasus_data_version = edit.pegasus_data_version_;
have_pegasus_data_version = true;
}

if (edit.has_last_manual_compact_finish_time_) {
Expand Down Expand Up @@ -3081,9 +3081,9 @@ Status VersionSet::Recover(
s = Status::Corruption("no meta-lognumber entry in descriptor");
} else if (!have_last_sequence) {
s = Status::Corruption("no last-sequence-number entry in descriptor");
} else if (!have_value_schema_version) {
} else if (!have_pegasus_data_version) {
if (db_options_->pegasus_data) {
s = Status::Corruption("no value_schema_version entry in descriptor");
s = Status::Corruption("no pegasus-data-version entry in descriptor");
}
} else if (!have_last_manual_compact_finish_time) {
ROCKS_LOG_WARN(db_options_->info_log,
Expand All @@ -3095,7 +3095,7 @@ Status VersionSet::Recover(
}

column_family_set_->UpdateMaxColumnFamily(max_column_family);
column_family_set_->SetValueSchemaVersion(value_schema_version);
column_family_set_->SetPegasusDataVersion(pegasus_data_version);
column_family_set_->SetLastManualCompactFinishTime(last_manual_compact_finish_time);

MarkFileNumberUsed(previous_log_number);
Expand Down Expand Up @@ -3175,13 +3175,13 @@ Status VersionSet::Recover(
"last_sequence is %lu, log_number is %lu,"
"prev_log_number is %lu,"
"max_column_family is %u,"
"value_schema_version is %u,"
"pegasus_data_version is %u,"
"last_manual_compact_finish_time is %lu\n",
manifest_filename.c_str(), (unsigned long)manifest_file_number_,
(unsigned long)next_file_number_.load(), (unsigned long)last_sequence_,
(unsigned long)log_number, (unsigned long)prev_log_number_,
column_family_set_->GetMaxColumnFamily(),
column_family_set_->GetValueSchemaVersion(),
column_family_set_->GetPegasusDataVersion(),
column_family_set_->GetLastManualCompactFinishTime());

if (db_options_->pegasus_data) {
Expand Down Expand Up @@ -3508,8 +3508,8 @@ Status VersionSet::DumpManifest(Options& options, std::string& dscname,
column_family_set_->UpdateMaxColumnFamily(edit.max_column_family_);
}

if (edit.has_value_schema_version_) {
column_family_set_->SetValueSchemaVersion(edit.value_schema_version_);
if (edit.has_pegasus_data_version_) {
column_family_set_->SetPegasusDataVersion(edit.pegasus_data_version_);
}

if (edit.has_last_manual_compact_finish_time_) {
Expand Down Expand Up @@ -3582,11 +3582,11 @@ Status VersionSet::DumpManifest(Options& options, std::string& dscname,
auto& p = last_flush_seq_decree_map[0]; // default column family
printf(
"next_file_number %lu last_sequence %lu last_flush_sequence %lu "
"last_flush_decree %lu prev_log_number %lu max_column_family %u value_schema_version %u "
"last_flush_decree %lu prev_log_number %lu max_column_family %u pegasus_data_version %u "
"last_manual_compact_finish_time %lu\n",
(unsigned long)next_file_number_.load(), (unsigned long)last_sequence,
(unsigned long)p.first, (unsigned long)p.second, (unsigned long)previous_log_number,
column_family_set_->GetMaxColumnFamily(), column_family_set_->GetValueSchemaVersion(),
column_family_set_->GetMaxColumnFamily(), column_family_set_->GetPegasusDataVersion(),
column_family_set_->GetLastManualCompactFinishTime());
}

Expand Down
4 changes: 2 additions & 2 deletions include/rocksdb/db.h
Original file line number Diff line number Diff line change
Expand Up @@ -886,8 +886,8 @@ class DB {
// The last flushed decree.
virtual uint64_t GetLastFlushedDecree() { return 0; }

// The value schame version.
virtual uint32_t GetValueSchemaVersion() { return 0; }
// The Pegasus data version.
virtual uint32_t GetPegasusDataVersion() const { return 0; }

virtual uint64_t GetLastManualCompactFinishTime() { return 0; }

Expand Down
4 changes: 2 additions & 2 deletions include/rocksdb/options.h
Original file line number Diff line number Diff line change
Expand Up @@ -926,9 +926,9 @@ struct DBOptions {
// Default: false
bool pegasus_data = false;

// Default value schema version.
// Pegasus data version.
// Default: 0
uint32_t default_value_schema_version = 0;
uint32_t pegasus_data_version = 0;
};

// Options to control the behavior of a database (passed to DB::Open)
Expand Down
6 changes: 3 additions & 3 deletions options/db_options.cc
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ ImmutableDBOptions::ImmutableDBOptions(const DBOptions& options)
manual_wal_flush(options.manual_wal_flush),
seq_per_batch(options.seq_per_batch),
pegasus_data(options.pegasus_data),
default_value_schema_version(options.default_value_schema_version) {
pegasus_data_version(options.pegasus_data_version) {
}

void ImmutableDBOptions::Dump(Logger* log) const {
Expand Down Expand Up @@ -225,8 +225,8 @@ void ImmutableDBOptions::Dump(Logger* log) const {
manual_wal_flush);
ROCKS_LOG_HEADER(log, " Options.seq_per_batch: %d", seq_per_batch);
ROCKS_LOG_HEADER(log, " Options.pegasus_data: %d", pegasus_data);
ROCKS_LOG_HEADER(log, " Options.default_value_schema_version: %d",
default_value_schema_version);
ROCKS_LOG_HEADER(log, " Options.pegasus_data_version: %d",
pegasus_data_version);
}

MutableDBOptions::MutableDBOptions()
Expand Down
2 changes: 1 addition & 1 deletion options/db_options.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ struct ImmutableDBOptions {
bool manual_wal_flush;
bool seq_per_batch;
bool pegasus_data;
uint32_t default_value_schema_version;
uint32_t pegasus_data_version;
};

struct MutableDBOptions {
Expand Down
2 changes: 2 additions & 0 deletions options/options_helper.cc
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,8 @@ DBOptions BuildDBOptions(const ImmutableDBOptions& immutable_db_options,
immutable_db_options.preserve_deletes;
options.pegasus_data =
immutable_db_options.pegasus_data;
options.pegasus_data_version =
immutable_db_options.pegasus_data_version;

return options;
}
Expand Down
6 changes: 3 additions & 3 deletions options/options_helper.h
Original file line number Diff line number Diff line change
Expand Up @@ -376,10 +376,10 @@ static std::unordered_map<std::string, OptionTypeInfo> db_options_type_info = {
{offsetof(struct DBOptions, pegasus_data), OptionType::kBoolean,
OptionVerificationType::kNormal, false,
offsetof(struct ImmutableDBOptions, pegasus_data)}},
{"default_value_schema_version",
{offsetof(struct DBOptions, default_value_schema_version), OptionType::kUInt32T,
{"pegasus_data_version",
{offsetof(struct DBOptions, pegasus_data_version), OptionType::kUInt32T,
OptionVerificationType::kNormal, false,
offsetof(struct ImmutableDBOptions, default_value_schema_version)}}};
offsetof(struct ImmutableDBOptions, pegasus_data_version)}}};

// offset_of is used to get the offset of a class data member
// ex: offset_of(&ColumnFamilyOptions::num_levels)
Expand Down
2 changes: 1 addition & 1 deletion options/options_settable_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ TEST_F(OptionsSettableTest, DBOptionsAllFieldsSettable) {
"manual_wal_flush=false;"
"seq_per_batch=false;"
"pegasus_data=false;"
"default_value_schema_version=0;",
"pegasus_data_version=0;",
new_options));

ASSERT_EQ(unset_bytes_base, NumUnsetBytes(new_options_ptr, sizeof(DBOptions),
Expand Down
1 change: 1 addition & 0 deletions util/testutil.cc
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,7 @@ void RandomInitDBOptions(DBOptions* db_opt, Random* rnd) {

// uint32_t options
db_opt->max_subcompactions = rnd->Uniform(100000);
db_opt->pegasus_data_version = rnd->Uniform(100000);

// uint64_t options
static const uint64_t uint_max = static_cast<uint64_t>(UINT_MAX);
Expand Down

0 comments on commit 441dd88

Please sign in to comment.