-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge '[Backport 5.4] Raft snapshot fixes' from Kamil Braun
Backports required to fix #16683 in 5.4: - add an API to trigger Raft snapshot - use the API when we restart and see that the existing snapshot is at index 0, to trigger a new one --- in order to fix broken deployments that already bootstrapped with index-0 snapshot (we may get such deployments by upgrading from 5.2) Closes #17123 * github.com:scylladb/scylladb: test_raft_snapshot_request: fix flakiness (again) test_raft_snapshot_request: fix flakiness Merge 'raft_group0: trigger snapshot if existing snapshot index is 0' from Kamil Braun Merge 'Add an API to trigger snapshot in Raft servers' from Kamil Braun
- Loading branch information
Showing
20 changed files
with
710 additions
and
201 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
{ | ||
"apiVersion":"0.0.1", | ||
"swaggerVersion":"1.2", | ||
"basePath":"{{Protocol}}://{{Host}}", | ||
"resourcePath":"/raft", | ||
"produces":[ | ||
"application/json" | ||
], | ||
"apis":[ | ||
{ | ||
"path":"/raft/trigger_snapshot/{group_id}", | ||
"operations":[ | ||
{ | ||
"method":"POST", | ||
"summary":"Triggers snapshot creation and log truncation for the given Raft group", | ||
"type":"string", | ||
"nickname":"trigger_snapshot", | ||
"produces":[ | ||
"application/json" | ||
], | ||
"parameters":[ | ||
{ | ||
"name":"group_id", | ||
"description":"The ID of the group which should get snapshotted", | ||
"required":true, | ||
"allowMultiple":false, | ||
"type":"string", | ||
"paramType":"path" | ||
}, | ||
{ | ||
"name":"timeout", | ||
"description":"Timeout in seconds after which the endpoint returns a failure. If not provided, 60s is used.", | ||
"required":false, | ||
"allowMultiple":false, | ||
"type":"long", | ||
"paramType":"query" | ||
} | ||
] | ||
} | ||
] | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
/* | ||
* Copyright (C) 2024-present ScyllaDB | ||
*/ | ||
|
||
/* | ||
* SPDX-License-Identifier: AGPL-3.0-or-later | ||
*/ | ||
|
||
#include <seastar/core/coroutine.hh> | ||
|
||
#include "api/api.hh" | ||
#include "api/api-doc/raft.json.hh" | ||
|
||
#include "service/raft/raft_group_registry.hh" | ||
|
||
using namespace seastar::httpd; | ||
|
||
extern logging::logger apilog; | ||
|
||
namespace api { | ||
|
||
namespace r = httpd::raft_json; | ||
using namespace json; | ||
|
||
void set_raft(http_context&, httpd::routes& r, sharded<service::raft_group_registry>& raft_gr) { | ||
r::trigger_snapshot.set(r, [&raft_gr] (std::unique_ptr<http::request> req) -> future<json_return_type> { | ||
raft::group_id gid{utils::UUID{req->param["group_id"]}}; | ||
auto timeout_dur = std::invoke([timeout_str = req->get_query_param("timeout")] { | ||
if (timeout_str.empty()) { | ||
return std::chrono::seconds{60}; | ||
} | ||
auto dur = std::stoll(timeout_str); | ||
if (dur <= 0) { | ||
throw std::runtime_error{"Timeout must be a positive number."}; | ||
} | ||
return std::chrono::seconds{dur}; | ||
}); | ||
|
||
std::atomic<bool> found_srv{false}; | ||
co_await raft_gr.invoke_on_all([gid, timeout_dur, &found_srv] (service::raft_group_registry& raft_gr) -> future<> { | ||
auto* srv = raft_gr.find_server(gid); | ||
if (!srv) { | ||
co_return; | ||
} | ||
|
||
found_srv = true; | ||
abort_on_expiry aoe(lowres_clock::now() + timeout_dur); | ||
apilog.info("Triggering Raft group {} snapshot", gid); | ||
auto result = co_await srv->trigger_snapshot(&aoe.abort_source()); | ||
if (result) { | ||
apilog.info("New snapshot for Raft group {} created", gid); | ||
} else { | ||
apilog.info("Could not create new snapshot for Raft group {}, no new entries applied", gid); | ||
} | ||
}); | ||
|
||
if (!found_srv) { | ||
throw std::runtime_error{fmt::format("Server for group ID {} not found", gid)}; | ||
} | ||
|
||
co_return json_void{}; | ||
}); | ||
} | ||
|
||
void unset_raft(http_context&, httpd::routes& r) { | ||
r::trigger_snapshot.unset(r); | ||
} | ||
|
||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
/* | ||
* Copyright (C) 2023-present ScyllaDB | ||
*/ | ||
|
||
/* | ||
* SPDX-License-Identifier: AGPL-3.0-or-later | ||
*/ | ||
|
||
#pragma once | ||
|
||
#include "api_init.hh" | ||
|
||
namespace api { | ||
|
||
void set_raft(http_context& ctx, httpd::routes& r, sharded<service::raft_group_registry>& raft_gr); | ||
void unset_raft(http_context& ctx, httpd::routes& r); | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.