Skip to content

Commit

Permalink
cluster: add recovery state to bootstrap cmd
Browse files Browse the repository at this point in the history
Recovery can be started with a new cluster config, in which case the
recovery will be added to the recovery table when applying the bootstrap
command.
  • Loading branch information
andrwng committed Nov 24, 2023
1 parent 34e3230 commit 048ee23
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 16 deletions.
4 changes: 2 additions & 2 deletions src/v/cluster/cluster_recovery_manager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,8 @@ cluster_recovery_manager::initialize_recovery(
// Replicate an update to start recovery. Once applied, this will update
// the recovery table.
cluster_recovery_init_cmd_data data;
data.manifest = std::move(manifest);
data.bucket = std::move(bucket);
data.state.manifest = std::move(manifest);
data.state.bucket = std::move(bucket);
auto errc = co_await replicate_and_wait(
_controller_stm,
_sharded_as,
Expand Down
9 changes: 6 additions & 3 deletions src/v/cluster/cluster_recovery_table.cc
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include "cluster/cluster_recovery_table.h"

#include "cluster/cloud_metadata/cluster_manifest.h"
#include "cluster/cluster_recovery_state.h"
#include "cluster/logger.h"
#include "cluster/types.h"

Expand Down Expand Up @@ -64,10 +65,12 @@ std::error_code cluster_recovery_table::apply(
"Initializing cluster recovery at offset {} with manifest {} from bucket "
"{}",
offset,
cmd.value.manifest,
cmd.value.bucket);
cmd.value.state.manifest,
cmd.value.state.bucket);
_states.emplace_back(
std::move(cmd.value.manifest), std::move(cmd.value.bucket));
std::move(cmd.value.state.manifest),
std::move(cmd.value.state.bucket),
wait_for_nodes::no);
_has_active_recovery.signal();
return errc::success;
}
Expand Down
4 changes: 2 additions & 2 deletions src/v/cluster/tests/cluster_recovery_table_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ namespace cluster {
namespace {
cluster_recovery_init_cmd make_init_cmd(int meta_id) {
cluster_recovery_init_cmd_data data;
data.manifest.metadata_id = cluster::cloud_metadata::cluster_metadata_id{
meta_id};
data.state.manifest.metadata_id
= cluster::cloud_metadata::cluster_metadata_id{meta_id};
return cluster_recovery_init_cmd{0, std::move(data)};
}
cluster_recovery_update_cmd make_update_cmd(
Expand Down
38 changes: 29 additions & 9 deletions src/v/cluster/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -3011,10 +3011,30 @@ struct user_and_credential
security::scram_credential credential;
};

struct cluster_recovery_init_state
: serde::envelope<
cluster_recovery_init_state,
serde::version<0>,
serde::compat_version<0>> {
using rpc_adl_exempt = std::true_type;
friend bool operator==(
const cluster_recovery_init_state&, const cluster_recovery_init_state&)
= default;

auto serde_fields() { return std::tie(manifest, bucket); }

// Cluster metadata manifest used to define the desired end state of the
// recovery.
cluster::cloud_metadata::cluster_metadata_manifest manifest;

// Bucket from which to download the cluster recovery state.
cloud_storage_clients::bucket_name bucket;
};

struct bootstrap_cluster_cmd_data
: serde::envelope<
bootstrap_cluster_cmd_data,
serde::version<2>,
serde::version<3>,
serde::compat_version<0>> {
using rpc_adl_exempt = std::true_type;

Expand All @@ -3028,7 +3048,8 @@ struct bootstrap_cluster_cmd_data
bootstrap_user_cred,
node_ids_by_uuid,
founding_version,
initial_nodes);
initial_nodes,
recovery_state);
}

model::cluster_uuid uuid;
Expand All @@ -3040,6 +3061,9 @@ struct bootstrap_cluster_cmd_data
// the node that generated the bootstrap record.
cluster_version founding_version{invalid_version};
std::vector<model::broker> initial_nodes;

// If set, begins a cluster recovery using this state as the basis.
std::optional<cluster_recovery_init_state> recovery_state;
};

struct cluster_recovery_init_cmd_data
Expand All @@ -3048,19 +3072,15 @@ struct cluster_recovery_init_cmd_data
serde::version<0>,
serde::compat_version<0>> {
using rpc_adl_exempt = std::true_type;

friend bool operator==(
const cluster_recovery_init_cmd_data&,
const cluster_recovery_init_cmd_data&)
= default;

auto serde_fields() { return std::tie(manifest, bucket); }
auto serde_fields() { return std::tie(state); }

// Cluster metadata manifest used to define the desired end state of the
// recovery.
cluster::cloud_metadata::cluster_metadata_manifest manifest;

// Bucket from which to download the cluster recovery state.
cloud_storage_clients::bucket_name bucket;
cluster_recovery_init_state state;
};

enum class recovery_stage : int8_t {
Expand Down

0 comments on commit 048ee23

Please sign in to comment.