Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Seed Driven Cluster Bootstrap #2

Draft
wants to merge 28 commits into
base: node_id_assignment
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
f371c12
storage: add node_uuid to storage API
andrwng Sep 23, 2022
c4da948
cluster: encapsulate cluster discovery
andrwng Sep 23, 2022
69bf703
cluster: introduce bootstrap service
andrwng Sep 23, 2022
b8d0088
redpanda: plumb cluster discovery into application
andrwng Oct 4, 2022
b499ca9
util: add named_type static constructor from args
andrwng Oct 6, 2022
830703a
application: generate node UUID on startup
andrwng Sep 24, 2022
8289d4f
cluster: command to register a UUID
andrwng Sep 29, 2022
f564905
features: add flag for node_id_assignment
andrwng Oct 4, 2022
c7a7b03
config: make node ID optional
andrwng Oct 6, 2022
6809715
cluster: auto-assign node ID when empty
andrwng Oct 6, 2022
0561b64
tests: add option to not configure node ID
andrwng Oct 6, 2022
556918b
cluster: unit tests for node ID assignment
andrwng Oct 6, 2022
84a23bd
cluster_discovery: read node ID from kvstore
andrwng Oct 6, 2022
0d753b8
cluster_discovery: add an abort source
andrwng Oct 6, 2022
59d5a7f
net: add node_id label to client metrics
andrwng Oct 4, 2022
8aa8c7d
cluster: allow node to join if address is used
andrwng Oct 4, 2022
5972afd
tests: ducktape test for node ID assignment
andrwng Oct 4, 2022
73cb74c
config: add empty_seed_starts_cluster to node_config
dlex Oct 5, 2022
82c8d18
cluster: adjustments to "node ID assignments"
dlex Oct 5, 2022
a24ec85
cluster: analysis of seed_servers by cluster_discovery
dlex Oct 6, 2022
72f2547
net: unresolved_address got a comparison op
dlex Oct 6, 2022
2909a9a
cluster: bootstrap controller command handling
dlex Oct 6, 2022
d812d26
cluster: cluster_uuid read from kvstore
dlex Oct 6, 2022
446dad3
cluster: bootstrap with seed_brokers
dlex Oct 6, 2022
3309009
cluster: bootstrap command issued
dlex Oct 6, 2022
58dbc8a
c/tests: verify single node SDCB mode
dlex Oct 6, 2022
6d61a10
cluster: bootstrap command creates default user
dlex Oct 6, 2022
87604ad
cluster: cluster_bootstrap_info implemented
dlex Oct 7, 2022
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
11 changes: 11 additions & 0 deletions src/v/cluster/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
find_package(Roaring REQUIRED)
include(rpcgen)
rpcgen(
TARGET bootstrap_rpc
IN_FILE ${CMAKE_CURRENT_SOURCE_DIR}/bootstrap.json
OUT_FILE ${CMAKE_CURRENT_BINARY_DIR}/cluster_bootstrap_service.h
INCLUDES ${CMAKE_BINARY_DIR}/src/v
)
rpcgen(
TARGET controller_rpc
IN_FILE ${CMAKE_CURRENT_SOURCE_DIR}/controller.json
Expand Down Expand Up @@ -85,6 +91,7 @@ v_cc_library(
security_frontend.cc
data_policy_manager.cc
data_policy_frontend.cc
cluster_discovery.cc
controller_api.cc
members_frontend.cc
members_backend.cc
Expand Down Expand Up @@ -113,8 +120,12 @@ v_cc_library(
partition_balancer_rpc_handler.cc
node_status_backend.cc
node_status_rpc_handler.cc
bootstrap_service.cc
cluster_uuid.cc
bootstrap_backend.cc
DEPS
Seastar::seastar
bootstrap_rpc
controller_rpc
metadata_rpc
id_allocator_rpc
Expand Down
15 changes: 15 additions & 0 deletions src/v/cluster/bootstrap.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"namespace": "cluster",
"service_name": "cluster_bootstrap",
"includes": [
"cluster/bootstrap_types.h"
],
"methods": [
{
"name": "cluster_bootstrap_info",
"input_type": "cluster_bootstrap_info_request",
"output_type": "cluster_bootstrap_info_reply"
}
]
}

102 changes: 102 additions & 0 deletions src/v/cluster/bootstrap_backend.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
/*
* Copyright 2022 Redpanda Data, Inc.
*
* Use of this software is governed by the Business Source License
* included in the file licenses/BSL.md
*
* As of the Change Date specified in that file, in accordance with
* the Business Source License, use of this software will be governed
* by the Apache License, Version 2.0
*/

#include "cluster/bootstrap_backend.h"

#include "cluster/commands.h"
#include "cluster/logger.h"
#include "cluster/types.h"
#include "security/credential_store.h"

namespace cluster {

bootstrap_backend::bootstrap_backend(
const std::optional<cluster_uuid>& cluster_uuid,
ss::sharded<security::credential_store>& credentials,
ss::sharded<storage::api>& storage)
: _cluster_uuid(cluster_uuid)
, _credentials(credentials)
, _storage(storage) {}

namespace {

std::error_code
do_apply(user_and_credential cred, security::credential_store& store) {
if (store.contains(cred.username)) return errc::user_exists;
store.put(cred.username, std::move(cred.credential));
return errc::success;
}

template<typename Cmd>
ss::future<std::error_code> dispatch_updates_to_cores(
Cmd cmd, ss::sharded<security::credential_store>& sharded_service) {
auto res = co_await sharded_service.map_reduce0(
[cmd](security::credential_store& service) {
return do_apply(std::move(cmd), service);
},
std::optional<std::error_code>{},
[](std::optional<std::error_code> result, std::error_code error_code) {
if (!result.has_value()) {
result = error_code;
} else {
vassert(
result.value() == error_code,
"State inconsistency across shards detected, "
"expected result: {}, have: {}",
result->value(),
error_code);
}
return result.value();
});
co_return res.value();
}

} // namespace

ss::future<std::error_code>
bootstrap_backend::apply_update(model::record_batch b) {
vlog(clusterlog.info, "Applying update to bootstrap_manager");

// handle node managements command
static constexpr auto accepted_commands
= make_commands_list<bootstrap_cluster_cmd>();
auto cmd = co_await cluster::deserialize(std::move(b), accepted_commands);

co_return co_await ss::visit(
cmd, [this](bootstrap_cluster_cmd cmd) -> ss::future<std::error_code> {
if (_cluster_uuid.has_value()) {
vlog(
clusterlog.debug,
"Skipping bootstrap_cluster_cmd {}, current cluster_uuid: {}",
cmd.value.uuid,
*_cluster_uuid);
co_return errc::success;
}

if (cmd.value.bootstrap_user_cred) {
const std::error_code res
= co_await dispatch_updates_to_cores<user_and_credential>(
*cmd.value.bootstrap_user_cred, _credentials);
if (res != errc::success) co_return res;
vlog(
clusterlog.info,
"Bootstrap user {} created",
cmd.value.bootstrap_user_cred->username);
}

_cluster_uuid = cmd.value.uuid;
co_await write_stored_cluster_uuid(_storage.local(), cmd.value.uuid);
vlog(clusterlog.info, "Cluster {} created", cmd.value.uuid);
co_return errc::success;
});
}

} // namespace cluster
60 changes: 60 additions & 0 deletions src/v/cluster/bootstrap_backend.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/*
* Copyright 2022 Redpanda Data, Inc.
*
* Use of this software is governed by the Business Source License
* included in the file licenses/BSL.md
*
* As of the Change Date specified in that file, in accordance with
* the Business Source License, use of this software will be governed
* by the Apache License, Version 2.0
*/

#pragma once

#include "cluster/cluster_uuid.h"
#include "cluster/fwd.h"
#include "model/record.h"
#include "model/record_batch_types.h"

#include <seastar/core/abort_source.hh>
#include <seastar/core/sharded.hh>

#include <optional>

namespace security {
class credential_store;
}

namespace cluster {

/**
* This class applies the cluster intitalization message to
* - itself, storing the cluster UUID value, also duplicating it to the kvstore
* - credintial_store, to initialize the bootstrap user
* - TODO: apply the initial licence
*/
class bootstrap_backend final {
public:
bootstrap_backend(
const std::optional<cluster_uuid>&,
ss::sharded<security::credential_store>&,
ss::sharded<storage::api>&);

ss::future<std::error_code> apply_update(model::record_batch);

bool is_batch_applicable(const model::record_batch& b) {
return b.header().type
== model::record_batch_type::cluster_bootstrap_cmd;
}

const std::optional<cluster_uuid>& get_cluster_uuid() const {
return _cluster_uuid;
}

private:
std::optional<cluster_uuid> _cluster_uuid;
ss::sharded<security::credential_store>& _credentials;
ss::sharded<storage::api>& _storage;
};

} // namespace cluster
39 changes: 39 additions & 0 deletions src/v/cluster/bootstrap_service.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// Copyright 2022 Redpanda Data, Inc.
//
// Use of this software is governed by the Business Source License
// included in the file licenses/BSL.md
//
// As of the Change Date specified in that file, in accordance with
// the Business Source License, use of this software will be governed
// by the Apache License, Version 2.0

#include "cluster/bootstrap_service.h"

#include "cluster/bootstrap_types.h"
#include "cluster/cluster_utils.h"
#include "cluster/logger.h"
#include "config/node_config.h"
#include "features/feature_table.h"

namespace cluster {

ss::future<cluster_bootstrap_info_reply>
bootstrap_service::cluster_bootstrap_info(
cluster_bootstrap_info_request&&, rpc::streaming_context&) {
cluster_bootstrap_info_reply r{};
r.broker = make_self_broker(config::node());
r.version = features::feature_table::get_latest_logical_version();
const std::vector<config::seed_server>& seed_servers
= config::node().seed_servers();
r.seed_servers.reserve(seed_servers.size());
std::transform(
seed_servers.cbegin(),
seed_servers.cend(),
std::back_inserter(r.seed_servers),
[](const config::seed_server& seed_server) { return seed_server.addr; });
r.empty_seed_starts_cluster = config::node().empty_seed_starts_cluster();
vlog(clusterlog.debug, "Replying cluster_bootstrap_info: {}", r);
co_return r;
}

} // namespace cluster
29 changes: 29 additions & 0 deletions src/v/cluster/bootstrap_service.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// Copyright 2022 Redpanda Data, Inc.
//
// Use of this software is governed by the Business Source License
// included in the file licenses/BSL.md
//
// As of the Change Date specified in that file, in accordance with
// the Business Source License, use of this software will be governed
// by the Apache License, Version 2.0
#pragma once

#include "cluster/bootstrap_types.h"
#include "cluster/cluster_bootstrap_service.h"

#include <seastar/core/sharded.hh>

namespace cluster {

// RPC service to be used when initialially bootstrapping a cluster.
// TODO: talk about how it's a slim service with few dependencies.
class bootstrap_service : public cluster_bootstrap_service {
public:
bootstrap_service(ss::scheduling_group sg, ss::smp_service_group ssg)
: cluster_bootstrap_service(sg, ssg) {}

ss::future<cluster_bootstrap_info_reply> cluster_bootstrap_info(
cluster_bootstrap_info_request&&, rpc::streaming_context&) override;
};

} // namespace cluster
63 changes: 63 additions & 0 deletions src/v/cluster/bootstrap_types.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
// Copyright 2022 Redpanda Data, Inc.
//
// Use of this software is governed by the Business Source License
// included in the file licenses/BSL.md
//
// As of the Change Date specified in that file, in accordance with
// the Business Source License, use of this software will be governed
// by the Apache License, Version 2.0
#pragma once

#include "cluster/types.h"
#include "model/fundamental.h"
#include "serde/serde.h"

#include <fmt/core.h>

#include <vector>

namespace cluster {

struct cluster_bootstrap_info_request
: serde::envelope<cluster_bootstrap_info_request, serde::version<0>> {
using rpc_adl_exempt = std::true_type;

friend std::ostream&
operator<<(std::ostream& o, const cluster_bootstrap_info_request&) {
fmt::print(o, "{{}}");
return o;
}

auto serde_fields() { return std::tie(); }
};

struct cluster_bootstrap_info_reply
: serde::envelope<cluster_bootstrap_info_reply, serde::version<0>> {
using rpc_adl_exempt = std::true_type;

model::broker broker;
cluster_version version;
std::vector<net::unresolved_address> seed_servers;
bool empty_seed_starts_cluster;
// TODO: add fields!
// - node UUID?

auto serde_fields() {
return std::tie(
broker, version, seed_servers, empty_seed_starts_cluster);
}

friend std::ostream&
operator<<(std::ostream& o, const cluster_bootstrap_info_reply& v) {
fmt::print(
o,
"{{broker: {}, version: {}, seed_servers: {}, ESCB: {}}}",
v.broker,
v.version,
v.seed_servers,
v.empty_seed_starts_cluster);
return o;
}
};

} // namespace cluster
Loading