Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ci-expanded.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
1 change: 1 addition & 0 deletions builds/cmake/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ if ( MSVC )
add_compile_options(
/W4
/permissive-
/Zc:inline
/bigobj
/Zc:__cplusplus
/Zc:preprocessor
Expand Down
1 change: 1 addition & 0 deletions builds/msvc/properties/Common.props
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
<WarningLevel>Level4</WarningLevel>
<ExternalWarningLevel>Level4</ExternalWarningLevel>
<ConformanceMode>true</ConformanceMode>
<RemoveUnreferencedCodeData>true</RemoveUnreferencedCodeData>
<LanguageStandard_C>stdc11</LanguageStandard_C>
<EnforceTypeConversionRules>true</EnforceTypeConversionRules>
<RuntimeTypeInfo>true</RuntimeTypeInfo>
Expand Down
49 changes: 49 additions & 0 deletions include/bitcoin/database/impl/store/store_open.ipp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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<one> 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
Expand Down
13 changes: 12 additions & 1 deletion include/bitcoin/database/impl/store/store_restore.ipp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions include/bitcoin/database/store.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
25 changes: 25 additions & 0 deletions test/store/store_open.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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() };
Expand Down
4 changes: 2 additions & 2 deletions test/store/store_restore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}

Expand Down
Loading