diff --git a/.github/workflows/ci-expanded.yml b/.github/workflows/ci-expanded.yml
index 3d3bbad21..359360249 100644
--- a/.github/workflows/ci-expanded.yml
+++ b/.github/workflows/ci-expanded.yml
@@ -1934,7 +1934,7 @@ jobs:
warnings:
needs: [ gnu, musl, cmake, presets, msvc ]
- if: ${{ !cancelled() && (github.event_name != 'pull_request' || github.event.action != 'closed') }}
+ if: ${{ success() && github.event_name == 'push' }}
continue-on-error: true
runs-on: ubuntu-latest
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
index 762c86dbe..6b31f230d 100644
--- a/.github/workflows/ci.yml
+++ b/.github/workflows/ci.yml
@@ -942,7 +942,7 @@ jobs:
warnings:
needs: [ gnu, cmake, presets, msvc ]
- if: ${{ !cancelled() && (github.event_name != 'pull_request' || github.event.action != 'closed') }}
+ if: ${{ success() && github.event_name == 'push' }}
continue-on-error: true
runs-on: ubuntu-latest
diff --git a/builds/cmake/CMakeLists.txt b/builds/cmake/CMakeLists.txt
index ac2bee3a1..90058afa3 100644
--- a/builds/cmake/CMakeLists.txt
+++ b/builds/cmake/CMakeLists.txt
@@ -88,6 +88,7 @@ if ( MSVC )
add_compile_options(
/W4
/permissive-
+ /Zc:inline
/bigobj
/Zc:__cplusplus
/Zc:preprocessor
diff --git a/builds/msvc/properties/Common.props b/builds/msvc/properties/Common.props
index 5b7676a28..19b79df35 100644
--- a/builds/msvc/properties/Common.props
+++ b/builds/msvc/properties/Common.props
@@ -25,6 +25,7 @@
Level4
Level4
true
+ true
stdc11
true
true
diff --git a/include/bitcoin/database/impl/store/store_open.ipp b/include/bitcoin/database/impl/store/store_open.ipp
index d624b7e78..1150d3c8a 100644
--- a/include/bitcoin/database/impl/store/store_open.ipp
+++ b/include/bitcoin/database/impl/store/store_open.ipp
@@ -756,6 +756,20 @@ code CLASS::read_envelope(database::envelope& stored) NOEXCEPT
if (!transactor_mutex_.try_lock())
return error::transactor_lock;
+ if (fault_lock_.is_locked())
+ {
+ transactor_mutex_.unlock();
+ return error::fault_lock;
+ }
+
+ // Heads are not intact under flush lock, so schema is of the snapshot.
+ if (flush_lock_.is_locked())
+ {
+ const auto failed = read_snapshot(stored.schema);
+ transactor_mutex_.unlock();
+ return failed ? failed : error::flush_lock;
+ }
+
auto ec = envelope_head_.open();
if (!ec) ec = envelope_head_.load();
if (!ec)
@@ -788,6 +802,41 @@ code CLASS::read_envelope(database::envelope& stored) NOEXCEPT
return ec;
}
+// Schema of the snapshot that restore recovers, compiled if none or empty.
+TEMPLATE
+code CLASS::read_snapshot(system::config::version& version) NOEXCEPT
+{
+ const auto primary = configuration_.path / schema::dir::primary;
+ const auto secondary = configuration_.path / schema::dir::secondary;
+ version = database::envelope::compiled;
+ if (!file::is_directory(primary) && !file::is_directory(secondary))
+ return error::success;
+
+ const auto& folder = file::is_directory(primary) ? primary : secondary;
+ Storage envelope_head
+ {
+ head(folder, schema::caches::envelope), envelope_settings,
+ sequential, !staged, shared
+ };
+
+ table::envelope snapshot{ envelope_head };
+ auto ec = envelope_head.open();
+ if (!ec) ec = envelope_head.load();
+ if (!ec && !is_zero(snapshot.head_size()))
+ {
+ table::envelope::raw raw{};
+ if (snapshot.get(zero, raw))
+ version = database::envelope::get_schema(raw.data);
+ else
+ ec = error::verify_table;
+ }
+
+ // unload and close errors override ec.
+ if (const auto unloaded = envelope_head.unload()) ec = unloaded;
+ if (const auto closed = envelope_head.close()) ec = closed;
+ return ec;
+}
+
// A created store has no envelope until it is populated.
TEMPLATE
code CLASS::load_schema() NOEXCEPT
diff --git a/include/bitcoin/database/impl/store/store_restore.ipp b/include/bitcoin/database/impl/store/store_restore.ipp
index c776c9973..24a4f471b 100644
--- a/include/bitcoin/database/impl/store/store_restore.ipp
+++ b/include/bitcoin/database/impl/store/store_restore.ipp
@@ -52,7 +52,18 @@ code CLASS::restore(const event_handler& handler) NOEXCEPT
return error::flush_lock;
}
- code ec{ error::success };
+ system::config::version version{};
+ auto ec = read_snapshot(version);
+ if (!ec && version != database::envelope::compiled)
+ ec = error::schema_version;
+
+ if (ec)
+ {
+ if (!process_lock_.try_unlock()) ec = error::process_unlock;
+ transactor_mutex_.unlock();
+ return ec;
+ }
+
const auto heads = configuration_.path / schema::dir::heads;
const auto primary = configuration_.path / schema::dir::primary;
const auto secondary = configuration_.path / schema::dir::secondary;
diff --git a/include/bitcoin/database/store.hpp b/include/bitcoin/database/store.hpp
index a3a7eb862..bfcae4686 100644
--- a/include/bitcoin/database/store.hpp
+++ b/include/bitcoin/database/store.hpp
@@ -171,6 +171,7 @@ class store
bool get_schema(system::config::version& schema) const NOEXCEPT;
code load_schema() NOEXCEPT;
code load_envelope() NOEXCEPT;
+ code read_snapshot(system::config::version& version) NOEXCEPT;
void store_envelope(code& ec) NOEXCEPT;
code put_envelope(const database::envelope& stored) NOEXCEPT;
diff --git a/test/store/store_open.cpp b/test/store/store_open.cpp
index f271bfd77..fca490472 100644
--- a/test/store/store_open.cpp
+++ b/test/store/store_open.cpp
@@ -522,6 +522,31 @@ BC_AUTO_TEST_CASE(store__read_envelope__uncreated__failure)
BC_REQUIRE(instance.read_envelope(stored));
}
+BC_AUTO_TEST_CASE(store__read_envelope__fault_locked__fault_lock)
+{
+ settings configuration{ test::database_settings() };
+ configuration.path = TEST_DIRECTORY;
+ database::envelope stored{};
+ test::map_store instance{ configuration };
+ BC_REQUIRE(!instance.create(test::events));
+ BC_REQUIRE(!instance.close(test::events));
+ BC_REQUIRE(test::create(instance.fault_lock_file()));
+ BC_REQUIRE_EQUAL(instance.read_envelope(stored), error::fault_lock);
+}
+
+BC_AUTO_TEST_CASE(store__read_envelope__flush_locked_without_snapshot__flush_lock_compiled)
+{
+ settings configuration{ test::database_settings() };
+ configuration.path = TEST_DIRECTORY;
+ database::envelope stored{};
+ test::map_store instance{ configuration };
+ BC_REQUIRE(!instance.create(test::events));
+ BC_REQUIRE(!instance.close(test::events));
+ BC_REQUIRE(test::create(instance.flush_lock_file()));
+ BC_REQUIRE_EQUAL(instance.read_envelope(stored), error::flush_lock);
+ BC_REQUIRE(stored.schema == envelope::compiled);
+}
+
BC_AUTO_TEST_CASE(store__read_envelope__created__stored)
{
settings configuration{ test::database_settings() };
diff --git a/test/store/store_restore.cpp b/test/store/store_restore.cpp
index e21243acd..8199cb8c4 100644
--- a/test/store/store_restore.cpp
+++ b/test/store/store_restore.cpp
@@ -164,8 +164,8 @@ BC_AUTO_TEST_CASE(store__restore__secondary_closed__open_failure)
BC_REQUIRE(test::create(test::flush_lock_file(configuration.path)));
BC_REQUIRE(instance.restore_());
- // No primary, so rename /secondary to /heads.
- BC_REQUIRE(!test::folder(configuration.path / schema::dir::secondary));
+ // Snapshot without an envelope is refused before it is moved.
+ BC_REQUIRE(test::folder(configuration.path / schema::dir::secondary));
BC_REQUIRE(test::folder(configuration.path / schema::dir::heads));
}