fix(snapshot): verify and repair a sealed materialized tree
VoidBuildSystem CI / 1 · Requirements (push) Successful in 8s
VoidBuildSystem CI / 2B · Windows Wine build (debug) (push) Successful in 1m51s
VoidBuildSystem CI / 2A · Linux build (debug) (push) Successful in 2m55s
VoidBuildSystem CI / 2A · Linux build (sanitizers) (push) Successful in 3m10s
VoidBuildSystem CI / 2B · Windows Wine build (relwithdebinfo) (push) Successful in 3m6s
VoidBuildSystem CI / 3B · Windows Wine test (debug) (push) Successful in 17s
VoidBuildSystem CI / 3B · Windows Wine test (relwithdebinfo) (push) Successful in 18s
VoidBuildSystem CI / 2A · Linux build (relwithdebinfo) (push) Successful in 3m47s
VoidBuildSystem CI / 4B · Windows package (debug) (push) Successful in 18s
VoidBuildSystem CI / 4B · Windows package (relwithdebinfo) (push) Successful in 41s
VoidBuildSystem CI / 3A · Linux test (sanitizers) (push) Successful in 1m19s
VoidBuildSystem CI / 3A · Linux test (relwithdebinfo) (push) Successful in 5m16s
VoidBuildSystem CI / 3A · Linux test (debug) (push) Successful in 5m26s
VoidBuildSystem CI / 4A · Linux package (debug) (push) Successful in 1m14s
VoidBuildSystem CI / 4A · Linux package (sanitizers) (push) Successful in 1m22s
VoidBuildSystem CI / 4A · Linux package (relwithdebinfo) (push) Successful in 1m25s
VoidBuildSystem CI / 4A2 · VBS installers (self-hosted) (push) Failing after 1m27s
VoidBuildSystem CI / 5 · Release (push) Skipped
VoidBuildSystem CI / 4A2 · VBS installers (windows target) (push) Failing after 1m28s
VoidBuildSystem CI / 1 · Requirements (push) Successful in 8s
VoidBuildSystem CI / 2B · Windows Wine build (debug) (push) Successful in 1m51s
VoidBuildSystem CI / 2A · Linux build (debug) (push) Successful in 2m55s
VoidBuildSystem CI / 2A · Linux build (sanitizers) (push) Successful in 3m10s
VoidBuildSystem CI / 2B · Windows Wine build (relwithdebinfo) (push) Successful in 3m6s
VoidBuildSystem CI / 3B · Windows Wine test (debug) (push) Successful in 17s
VoidBuildSystem CI / 3B · Windows Wine test (relwithdebinfo) (push) Successful in 18s
VoidBuildSystem CI / 2A · Linux build (relwithdebinfo) (push) Successful in 3m47s
VoidBuildSystem CI / 4B · Windows package (debug) (push) Successful in 18s
VoidBuildSystem CI / 4B · Windows package (relwithdebinfo) (push) Successful in 41s
VoidBuildSystem CI / 3A · Linux test (sanitizers) (push) Successful in 1m19s
VoidBuildSystem CI / 3A · Linux test (relwithdebinfo) (push) Successful in 5m16s
VoidBuildSystem CI / 3A · Linux test (debug) (push) Successful in 5m26s
VoidBuildSystem CI / 4A · Linux package (debug) (push) Successful in 1m14s
VoidBuildSystem CI / 4A · Linux package (sanitizers) (push) Successful in 1m22s
VoidBuildSystem CI / 4A · Linux package (relwithdebinfo) (push) Successful in 1m25s
VoidBuildSystem CI / 4A2 · VBS installers (self-hosted) (push) Failing after 1m27s
VoidBuildSystem CI / 5 · Release (push) Skipped
VoidBuildSystem CI / 4A2 · VBS installers (windows target) (push) Failing after 1m28s
A concurrent capture can seal a tree while it is incomplete, and the seal marker makes that permanent (the installer jobs failed with missing VoidLibrary sources in the same tree id). After sealing or reusing a tree, check every entry exists; rebuild it (up to three attempts) when files are missing. Verified: the self-hosted VBS install still succeeds locally.
This commit is contained in:
1 parent
4f70e0640c
commit
2f989f85ea
1 file changed
+70
-49
+70
-49
@@ -491,62 +491,83 @@ Void::Result::Result<InputSnapshot, Void::Result::Error> capture_snapshot(
|
|||||||
if (options.materialize) {
|
if (options.materialize) {
|
||||||
snap.materialized_root = options.snapshot_store_dir / "trees" / snap.snapshot_id;
|
snap.materialized_root = options.snapshot_store_dir / "trees" / snap.snapshot_id;
|
||||||
const auto seal_marker = snap.materialized_root / ".sealed";
|
const auto seal_marker = snap.materialized_root / ".sealed";
|
||||||
if (!std::filesystem::exists(seal_marker, ec)) {
|
// A tree can be sealed while incomplete (interrupted concurrent capture),
|
||||||
// Unique per capture: concurrent captures in one process share the
|
// and the seal marker would make that permanent: verify and repair.
|
||||||
// pid, and a shared staging directory lets one capture remove files
|
for (int materialize_attempt = 0; materialize_attempt < 3; ++materialize_attempt) {
|
||||||
// another has already copied (sealing an incomplete tree).
|
if (!std::filesystem::exists(seal_marker, ec)) {
|
||||||
static std::atomic<std::uint64_t> staging_sequence{0};
|
// Unique per capture: concurrent captures in one process share the
|
||||||
const auto tmp_tree =
|
// pid, and a shared staging directory lets one capture remove files
|
||||||
options.snapshot_store_dir / "trees" /
|
// another has already copied (sealing an incomplete tree).
|
||||||
(snap.snapshot_id + ".staging_" +
|
static std::atomic<std::uint64_t> staging_sequence{0};
|
||||||
std::to_string(static_cast<long long>(::getpid())) + "_" +
|
const auto tmp_tree =
|
||||||
std::to_string(staging_sequence.fetch_add(1, std::memory_order_relaxed)));
|
options.snapshot_store_dir / "trees" /
|
||||||
std::filesystem::remove_all(tmp_tree, ec);
|
(snap.snapshot_id + ".staging_" +
|
||||||
std::filesystem::create_directories(tmp_tree, ec);
|
std::to_string(static_cast<long long>(::getpid())) + "_" +
|
||||||
|
std::to_string(staging_sequence.fetch_add(1, std::memory_order_relaxed)));
|
||||||
|
std::filesystem::remove_all(tmp_tree, ec);
|
||||||
|
std::filesystem::create_directories(tmp_tree, ec);
|
||||||
|
|
||||||
for (auto &[logical, entry] : snap.entries) {
|
for (auto &[logical, entry] : snap.entries) {
|
||||||
const auto dst = tmp_tree / logical;
|
const auto dst = tmp_tree / logical;
|
||||||
std::filesystem::create_directories(dst.parent_path(), ec);
|
std::filesystem::create_directories(dst.parent_path(), ec);
|
||||||
if (entry.kind == EntryKind::RegularFile && !entry.materialized_path.empty()) {
|
if (entry.kind == EntryKind::RegularFile &&
|
||||||
auto copied =
|
!entry.materialized_path.empty()) {
|
||||||
Platform::copy_isolated(entry.materialized_path, dst, entry.mode);
|
auto copied =
|
||||||
if (!copied) {
|
Platform::copy_isolated(entry.materialized_path, dst, entry.mode);
|
||||||
std::filesystem::remove_all(tmp_tree, ec);
|
if (!copied) {
|
||||||
return std::unexpected{copied.error()};
|
std::filesystem::remove_all(tmp_tree, ec);
|
||||||
}
|
return std::unexpected{copied.error()};
|
||||||
(void)Platform::set_canonical_mtime(dst, options.reproducibility_epoch);
|
}
|
||||||
} else if (entry.kind == EntryKind::Symlink) {
|
(void)Platform::set_canonical_mtime(dst,
|
||||||
if (!entry.sha256.empty()) {
|
options.reproducibility_epoch);
|
||||||
// Materialize symlinked regular file target inside snapshot tree
|
} else if (entry.kind == EntryKind::Symlink) {
|
||||||
// safely.
|
if (!entry.sha256.empty()) {
|
||||||
const auto src_target = source_files_to_verify.find(logical);
|
// Materialize symlinked regular file target inside snapshot
|
||||||
if (src_target != source_files_to_verify.end()) {
|
// tree safely.
|
||||||
auto copied =
|
const auto src_target = source_files_to_verify.find(logical);
|
||||||
Platform::copy_isolated(src_target->second, dst, entry.mode);
|
if (src_target != source_files_to_verify.end()) {
|
||||||
if (!copied) {
|
auto copied = Platform::copy_isolated(src_target->second, dst,
|
||||||
std::filesystem::remove_all(tmp_tree, ec);
|
entry.mode);
|
||||||
return std::unexpected{copied.error()};
|
if (!copied) {
|
||||||
|
std::filesystem::remove_all(tmp_tree, ec);
|
||||||
|
return std::unexpected{copied.error()};
|
||||||
|
}
|
||||||
|
(void)Platform::set_canonical_mtime(
|
||||||
|
dst, options.reproducibility_epoch);
|
||||||
}
|
}
|
||||||
(void)Platform::set_canonical_mtime(dst,
|
|
||||||
options.reproducibility_epoch);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
(void)Platform::atomic_write_file(tmp_tree / ".sealed",
|
||||||
(void)Platform::atomic_write_file(tmp_tree / ".sealed", snap.snapshot_id + "\n",
|
snap.snapshot_id + "\n", false);
|
||||||
false);
|
std::filesystem::rename(tmp_tree, snap.materialized_root, ec);
|
||||||
std::filesystem::rename(tmp_tree, snap.materialized_root, ec);
|
if (ec) {
|
||||||
if (ec) {
|
// Another concurrent worker may have sealed the identical
|
||||||
// Another concurrent worker may have sealed the identical content-addressed
|
// content-addressed tree.
|
||||||
// tree.
|
std::filesystem::remove_all(tmp_tree, ec);
|
||||||
std::filesystem::remove_all(tmp_tree, ec);
|
if (!std::filesystem::exists(seal_marker, ec)) {
|
||||||
if (!std::filesystem::exists(seal_marker, ec)) {
|
return std::unexpected{make_error(
|
||||||
return std::unexpected{
|
Void::System::SystemErrorCode::io_error,
|
||||||
make_error(Void::System::SystemErrorCode::io_error,
|
std::format("snapshot: failed publishing tree '{}'",
|
||||||
std::format("snapshot: failed publishing tree '{}'",
|
snap.materialized_root.string()))};
|
||||||
snap.materialized_root.string()))};
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::size_t missing = 0;
|
||||||
|
for (const auto &[logical, entry] : snap.entries) {
|
||||||
|
std::error_code check_ec;
|
||||||
|
if (!std::filesystem::exists(snap.materialized_root / logical, check_ec)) {
|
||||||
|
++missing;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (missing == 0) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
std::fprintf(stderr,
|
||||||
|
"snapshot: materialized tree '%s' misses %zu file(s); rebuilding\n",
|
||||||
|
snap.snapshot_id.c_str(), missing);
|
||||||
|
std::filesystem::remove_all(snap.materialized_root, ec);
|
||||||
}
|
}
|
||||||
for (auto &[logical, entry] : snap.entries) {
|
for (auto &[logical, entry] : snap.entries) {
|
||||||
entry.materialized_path = snap.materialized_root / logical;
|
entry.materialized_path = snap.materialized_root / logical;
|
||||||
|
|||||||
Reference in new issue
Block a user