Skip to content

Commit e8f98e1

Browse files
authored
[release/6.x] Partial revert of #7314, use node's local snapshot when available (#7589)
1 parent bb20f7e commit e8f98e1

File tree

4 files changed

+27
-10
lines changed

4 files changed

+27
-10
lines changed

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,14 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
66
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
77

8+
## [6.0.19]
9+
10+
[6.0.19]: https://github.com/microsoft/CCF/releases/tag/6.0.19
11+
12+
### Changed
13+
14+
- Partial revert to `fetch_recent_snapshot` behaviour. Nodes will now use a local snapshot if available and sufficiently fresh, and only prefer the peer's snapshot if it is newer (#7589).
15+
816
## [6.0.18]
917

1018
[6.0.18]: https://github.com/microsoft/CCF/releases/tag/6.0.18

python/pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
44

55
[project]
66
name = "ccf"
7-
version = "6.0.18"
7+
version = "6.0.19"
88
authors = [
99
{ name="CCF Team", email="[email protected]" },
1010
]

src/host/main.cpp

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -886,9 +886,14 @@ int main(int argc, char** argv) // NOLINT(bugprone-exception-escape)
886886
config.command.join.fetch_recent_snapshot)
887887
{
888888
// Try to fetch a recent snapshot from peer
889+
const size_t latest_local_idx = latest_local_snapshot.has_value() ?
890+
snapshots::get_snapshot_idx_from_file_name(
891+
latest_local_snapshot->second) :
892+
0;
889893
auto latest_peer_snapshot = snapshots::fetch_from_peer(
890894
config.command.join.target_rpc_address,
891895
config.command.service_certificate_file,
896+
latest_local_idx,
892897
config.command.join.fetch_snapshot_max_attempts,
893898
config.command.join.fetch_snapshot_retry_interval.count_ms(),
894899
config.command.join.fetch_snapshot_max_size.count_bytes());
@@ -908,10 +913,9 @@ int main(int argc, char** argv) // NOLINT(bugprone-exception-escape)
908913
fs::path(latest_peer_snapshot->snapshot_name);
909914
if (files::exists(dst_path))
910915
{
911-
LOG_FAIL_FMT(
912-
"Overwriting existing snapshot at {} with data retrieved from "
913-
"peer",
914-
dst_path);
916+
throw std::logic_error(fmt::format(
917+
"Unable to write peer snapshot - already have a file at {}",
918+
dst_path));
915919
}
916920
files::dump(latest_peer_snapshot->snapshot_data, dst_path);
917921
startup_snapshot = latest_peer_snapshot->snapshot_data;

src/snapshots/fetch.h

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@ namespace snapshots
121121
static std::optional<SnapshotResponse> try_fetch_from_peer(
122122
const std::string& peer_address,
123123
const std::string& path_to_peer_ca,
124+
size_t latest_local_snapshot,
124125
size_t max_size)
125126
{
126127
try
@@ -135,8 +136,10 @@ namespace snapshots
135136
// redirects terminate, the final response is likely to be extremely large
136137
// so is fetched over multiple requests for a sub-range, returning
137138
// PARTIAL_CONTENT each time.
138-
std::string snapshot_url =
139-
fmt::format("https://{}/node/snapshot", peer_address);
139+
std::string snapshot_url = fmt::format(
140+
"https://{}/node/snapshot?since={}",
141+
peer_address,
142+
latest_local_snapshot);
140143

141144
// Fetch 4MB chunks at a time
142145
constexpr size_t range_size = 4L * 1024 * 1024;
@@ -239,7 +242,8 @@ namespace snapshots
239242

240243
if (status_code == HTTP_STATUS_NOT_FOUND)
241244
{
242-
LOG_INFO_FMT("Peer has no suitable snapshot");
245+
LOG_INFO_FMT(
246+
"Peer has no snapshot newer than {}", latest_local_snapshot);
243247
return std::nullopt;
244248
}
245249

@@ -340,6 +344,7 @@ namespace snapshots
340344
static std::optional<SnapshotResponse> fetch_from_peer(
341345
const std::string& peer_address,
342346
const std::string& path_to_peer_ca,
347+
size_t latest_local_snapshot,
343348
size_t max_attempts,
344349
size_t retry_delay_ms,
345350
size_t max_size)
@@ -357,8 +362,8 @@ namespace snapshots
357362
std::this_thread::sleep_for(std::chrono::milliseconds(retry_delay_ms));
358363
}
359364

360-
auto response =
361-
try_fetch_from_peer(peer_address, path_to_peer_ca, max_size);
365+
auto response = try_fetch_from_peer(
366+
peer_address, path_to_peer_ca, latest_local_snapshot, max_size);
362367
if (response.has_value())
363368
{
364369
return response;

0 commit comments

Comments
 (0)