Skip to content

Commit

Permalink
Update store.restore() to clone latest snap back to /primary.
Browse files Browse the repository at this point in the history
  • Loading branch information
evoskuil committed Mar 16, 2024
1 parent 9e6562e commit 3537d17
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 8 deletions.
16 changes: 13 additions & 3 deletions include/bitcoin/database/impl/store.ipp
Expand Up @@ -758,17 +758,27 @@ code CLASS::restore(const event_handler& handler) NOEXCEPT

if (file::is_directory(primary))
{
// Clear invalid /heads and recover from /primary.
if (!file::clear_directory(heads)) ec = error::clear_directory;
// Clear invalid /heads, recover from /primary, clone to /primary.
if (!file::clear_directory(heads)) ec = error::clear_directory;
else if (!file::remove(heads)) ec = error::remove_directory;
else if (!file::rename(primary, heads)) ec = error::rename_directory;
else if (!file::copy_directory(heads, primary))
{
ec = error::copy_directory;
/* bool */ file::remove(primary);
}
}
else if (file::is_directory(secondary))
{
// Clear invalid /heads and recover from /secondary.
if (!file::clear_directory(heads)) ec = error::clear_directory;
if (!file::clear_directory(heads)) ec = error::clear_directory;
else if (!file::remove(heads)) ec = error::remove_directory;
else if (!file::rename(secondary, heads)) ec = error::rename_directory;
else if (!file::copy_directory(heads, primary))
{
ec = error::copy_directory;
/* bool */ file::remove(primary);
}
}
else
{
Expand Down
13 changes: 8 additions & 5 deletions test/store.cpp
Expand Up @@ -515,8 +515,9 @@ BOOST_AUTO_TEST_CASE(store__restore__primary_closed__restore_table)
// There are no backup index files to open.
BOOST_REQUIRE_EQUAL(instance.restore_(), error::restore_table);

// Rename /primary to /indexes.
BOOST_REQUIRE(!test::folder(configuration.path / schema::dir::primary));
// Rename /primary to /indexes and copy to /primary.
////BOOST_REQUIRE(!test::folder(configuration.path / schema::dir::primary));
BOOST_REQUIRE(test::folder(configuration.path / schema::dir::primary));
BOOST_REQUIRE(test::folder(configuration.path / schema::dir::heads));
}

Expand Down Expand Up @@ -556,8 +557,9 @@ BOOST_AUTO_TEST_CASE(store__restore__primary_secondary_loaded__restore_table)
// There are no backup index files to open.
BOOST_REQUIRE_EQUAL(instance.restore_(), error::restore_table);

// Rename /primary to /indexes.
BOOST_REQUIRE(!test::folder(configuration.path / schema::dir::primary));
// Rename /primary to /indexes and copy to /primary.
////BOOST_REQUIRE(!test::folder(configuration.path / schema::dir::primary));
BOOST_REQUIRE(test::folder(configuration.path / schema::dir::primary));
BOOST_REQUIRE(test::folder(configuration.path / schema::dir::secondary));
BOOST_REQUIRE(test::folder(configuration.path / schema::dir::heads));
}
Expand All @@ -576,7 +578,8 @@ BOOST_AUTO_TEST_CASE(store__restore__snapshot__success_unlocks)
BOOST_REQUIRE(test::folder(configuration.path / schema::dir::primary));
BOOST_REQUIRE_EQUAL(instance.close(events), error::success);
BOOST_REQUIRE_EQUAL(instance.restore(events), error::success);
BOOST_REQUIRE(!test::folder(configuration.path / schema::dir::primary));
BOOST_REQUIRE(test::folder(configuration.path / schema::dir::primary));
////BOOST_REQUIRE(!test::folder(configuration.path / schema::dir::primary));

BOOST_REQUIRE(!test::exists(instance.flush_lock_file()));
BOOST_REQUIRE(!test::exists(instance.process_lock_file()));
Expand Down

0 comments on commit 3537d17

Please sign in to comment.