Skip to content

Commit

Permalink
fix: update db version only if rebuild_db or all migrations was applied
Browse files Browse the repository at this point in the history
  • Loading branch information
kstdl committed Apr 18, 2023
1 parent 9168449 commit 10f29fa
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 15 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ set(TARAXA_NET_VERSION 1)
set(TARAXA_DB_MAJOR_VERSION 1)
# Minor version should be modified when changes to the database are made in the tables that can be rebuilt from the
# basic tables
set(TARAXA_DB_MINOR_VERSION 0)
set(TARAXA_DB_MINOR_VERSION 1)

# Defines Taraxa library target.
project(taraxa-node VERSION ${TARAXA_VERSION})
Expand Down
2 changes: 2 additions & 0 deletions libraries/core_libs/node/src/node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@ void FullNode::init() {
} else if (db_->hasMinorVersionChanged()) {
storage::migration::Manager(db_).applyAll();
}
db_->updateDbVersions();

if (db_->getDagBlocksCount() == 0) {
db_->setGenesisHash(conf_.genesis.genesisHash());
}
Expand Down
1 change: 1 addition & 0 deletions libraries/core_libs/storage/include/storage/storage.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@ class DbStorage : public std::enable_shared_from_this<DbStorage> {
void loadSnapshots();
void disableSnapshots();
void enableSnapshots();
void updateDbVersions();

uint32_t getMajorVersion() const;
std::unique_ptr<rocksdb::Iterator> getColumnIterator(const Column& c);
Expand Down
23 changes: 9 additions & 14 deletions libraries/core_libs/storage/src/storage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,23 +79,18 @@ DbStorage::DbStorage(fs::path const& path, uint32_t db_snapshot_each_n_pbft_bloc

kMajorVersion_ = getStatusField(StatusDbField::DbMajorVersion);
uint32_t minor_version = getStatusField(StatusDbField::DbMinorVersion);
auto save_db_versions = [&]() {
saveStatusField(StatusDbField::DbMajorVersion, TARAXA_DB_MAJOR_VERSION);
saveStatusField(StatusDbField::DbMinorVersion, TARAXA_DB_MINOR_VERSION);
};
if (kMajorVersion_ == 0 && minor_version == 0) {
save_db_versions();
} else {
if (kMajorVersion_ != TARAXA_DB_MAJOR_VERSION) {
major_version_changed_ = true;
save_db_versions();
} else if (minor_version != TARAXA_DB_MINOR_VERSION) {
minor_version_changed_ = true;
save_db_versions();
}
if (kMajorVersion_ != 0 && kMajorVersion_ != TARAXA_DB_MAJOR_VERSION) {
major_version_changed_ = true;
} else if (minor_version != TARAXA_DB_MINOR_VERSION) {
minor_version_changed_ = true;
}
}

void DbStorage::updateDbVersions() {
saveStatusField(StatusDbField::DbMajorVersion, TARAXA_DB_MAJOR_VERSION);
saveStatusField(StatusDbField::DbMinorVersion, TARAXA_DB_MINOR_VERSION);
}

void DbStorage::rebuildColumns(const rocksdb::Options& options) {
std::unique_ptr<rocksdb::DB> db;
std::vector<std::string> column_families;
Expand Down

0 comments on commit 10f29fa

Please sign in to comment.