From 3a0bfaa633cff342dd6f048496acd2ccc75aeaf4 Mon Sep 17 00:00:00 2001 From: Thiago Silva Date: Fri, 5 May 2023 15:45:18 -0300 Subject: [PATCH] Add a test case for RocksDB v21 to v22 upgrade --- nano/core_test/block_store.cpp | 51 ++++++++++++++++++++++++++++++++-- nano/node/rocksdb/rocksdb.hpp | 3 ++ 2 files changed, 52 insertions(+), 2 deletions(-) diff --git a/nano/core_test/block_store.cpp b/nano/core_test/block_store.cpp index 5814499b..9fc0f906 100644 --- a/nano/core_test/block_store.cpp +++ b/nano/core_test/block_store.cpp @@ -17,10 +17,10 @@ #include +#include #include #include - -#include +#include using namespace std::chrono_literals; @@ -2214,6 +2214,53 @@ namespace lmdb check_correct_state (); } } + +namespace rocksdb +{ + TEST (rocksdb_block_store, upgrade_v21_v22) + { + if (!nano::rocksdb_config::using_rocksdb_in_tests ()) + { + // Don't test this in LMDB mode + GTEST_SKIP (); + } + + auto const path = nano::unique_path (); + nano::logger_mt logger; + nano::stats stats; + auto const check_correct_state = [&] () { + nano::rocksdb::store store (logger, path, nano::dev::constants); + auto transaction (store.tx_begin_write ()); + ASSERT_EQ (store.version.get (transaction), store.version_current); + ASSERT_FALSE (store.column_family_exists ("unchecked")); + }; + + // Testing current version doesn't contain the unchecked table + check_correct_state (); + + // Setting the database to its 21st version state + { + nano::rocksdb::store store (logger, path, nano::dev::constants); + + // Create a column family for "unchecked" + ::rocksdb::ColumnFamilyOptions new_cf_options; + ::rocksdb::ColumnFamilyHandle * new_cf_handle; + ::rocksdb::Status status = store.db->CreateColumnFamily (new_cf_options, "unchecked", &new_cf_handle); + store.handles.emplace_back (new_cf_handle); + + // The new column family was created successfully, and 'new_cf_handle' now points to it. + ASSERT_TRUE (status.ok ()); + + // Rollback the database version number. + auto transaction (store.tx_begin_write ()); + store.version.put (transaction, 21); + ASSERT_EQ (store.version.get (transaction), 21); + } + + // Testing the upgrade code worked + check_correct_state (); + } +} } TEST (mdb_block_store, upgrade_backup) diff --git a/nano/node/rocksdb/rocksdb.hpp b/nano/node/rocksdb/rocksdb.hpp index 101a694b..47f3e718 100644 --- a/nano/node/rocksdb/rocksdb.hpp +++ b/nano/node/rocksdb/rocksdb.hpp @@ -31,6 +31,8 @@ class rocksdb_block_store_tombstone_count_Test; namespace rocksdb { + class rocksdb_block_store_upgrade_v21_v22_Test; + /** * rocksdb implementation of the block store */ @@ -171,6 +173,7 @@ namespace rocksdb constexpr static int base_block_cache_size = 8; friend class nano::rocksdb_block_store_tombstone_count_Test; + friend class nano::rocksdb::rocksdb_block_store_upgrade_v21_v22_Test; }; } // namespace rocksdb } // namespace nano