-
Notifications
You must be signed in to change notification settings - Fork 593
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
CORE-7000: Node ID/UUID Override #22972
Merged
michael-redpanda
merged 8 commits into
redpanda-data:dev
from
oleiman:nodeuuid/core-7000/poc
Sep 20, 2024
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
9cfd280
uuid_t: Add istream operator and yaml conversion
oleiman dddbe3e
config: Introduce node_id_override
oleiman 4d573fa
config: Node configs for uuid and id overrides
oleiman d2b85f2
app: Apply node_id_overrides at startup
oleiman c96f4ae
dt/admin_uuid: Tests for ghost node issue and nodewise mitigation
oleiman 951cc77
app: Introduce override CLI options
oleiman afe076d
dt/rp: Adds extra CLI args to `RedpandaService.start_redpanda`
oleiman ace0d61
dt/admin_uuid: Integration test for CLI options
oleiman File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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
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,76 @@ | ||
/* | ||
* Copyright 2024 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 "config/node_overrides.h" | ||
|
||
#include "re2/re2.h" | ||
|
||
#include <iostream> | ||
#include <string> | ||
|
||
namespace config { | ||
|
||
std::ostream& operator<<(std::ostream& os, const config::node_id_override& v) { | ||
return os << ssx::sformat("{}:{}:{}", v.key, v.uuid, v.id); | ||
} | ||
|
||
std::istream& operator>>(std::istream& is, config::node_id_override& v) { | ||
std::string s; | ||
is >> s; | ||
|
||
const static re2::RE2 pattern{R"(^([^:]+):([^:]+):([^:]+)$)"}; | ||
vassert(pattern.ok(), "Regex compilation failed"); | ||
|
||
std::string curr, uuid, id; | ||
|
||
if (!re2::RE2::FullMatch(s, pattern, &curr, &uuid, &id)) { | ||
throw std::runtime_error(fmt::format( | ||
michael-redpanda marked this conversation as resolved.
Show resolved
Hide resolved
|
||
R"(Formatting error: '{}', must be of form '<uuid>:<uuid>:<id>')", | ||
s)); | ||
} | ||
|
||
v.key = boost::lexical_cast<model::node_uuid>(curr); | ||
v.uuid = boost::lexical_cast<model::node_uuid>(uuid); | ||
v.id = boost::lexical_cast<model::node_id>(id); | ||
michael-redpanda marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
return is; | ||
} | ||
|
||
void node_override_store::maybe_set_overrides( | ||
model::node_uuid node_uuid, | ||
const std::vector<config::node_id_override>& overrides) { | ||
vassert(ss::this_shard_id() == 0, "Only set overrides on shard 0"); | ||
for (const auto& o : overrides) { | ||
if (o.key == node_uuid) { | ||
if (_uuid_override.has_value() || _id_override.has_value()) { | ||
throw std::runtime_error( | ||
"Invalid node ID override: Limit one override per broker"); | ||
break; | ||
} | ||
_uuid_override.emplace(o.uuid); | ||
_id_override.emplace(o.id); | ||
} | ||
} | ||
} | ||
|
||
const std::optional<model::node_uuid>& | ||
node_override_store::node_uuid() const noexcept { | ||
vassert(ss::this_shard_id() == 0, "Only get overrides on shard 0"); | ||
return _uuid_override; | ||
} | ||
|
||
const std::optional<model::node_id>& | ||
node_override_store::node_id() const noexcept { | ||
vassert(ss::this_shard_id() == 0, "Only get overrides on shard 0"); | ||
return _id_override; | ||
} | ||
|
||
} // namespace config |
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,111 @@ | ||
/* | ||
* Copyright 2024 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 "config/convert.h" | ||
#include "model/fundamental.h" | ||
#include "ssx/sformat.h" | ||
|
||
#include <yaml-cpp/yaml.h> | ||
|
||
#include <iosfwd> | ||
#include <vector> | ||
|
||
namespace config { | ||
|
||
/** | ||
* In-memory representation of a Node ID/UUID override candidate. | ||
* | ||
* Semantics surrounding when and how to apply an override | ||
* are not represented here and should be carefully considered at the | ||
* point of usage. | ||
*/ | ||
struct node_id_override { | ||
node_id_override() = default; | ||
node_id_override( | ||
model::node_uuid key, | ||
model::node_uuid uuid_value, | ||
model::node_id id_value) | ||
: key(key) | ||
, uuid(uuid_value) | ||
, id(id_value) {} | ||
model::node_uuid key{}; | ||
model::node_uuid uuid{}; | ||
model::node_id id{}; | ||
|
||
private: | ||
friend std::ostream& | ||
operator<<(std::ostream& os, const node_id_override& v); | ||
friend std::istream& operator>>(std::istream& is, node_id_override& v); | ||
friend bool operator==(const node_id_override&, const node_id_override&) | ||
= default; | ||
}; | ||
|
||
/** | ||
* Thin data structure to encapsulate 'node_id_override' filtering and | ||
* short-term storage. | ||
* | ||
* Given an array of 'node_id_override's, select the appropriate override as: | ||
* | ||
* For some instance 'node_id_override O', 'O.uuid' and 'O.id' should | ||
* be applied to some node if and only if its _current_ UUID matches | ||
* 'O.key'. | ||
*/ | ||
struct node_override_store { | ||
node_override_store() = default; | ||
|
||
/** | ||
* From the provided vector, accept the override (if one exists) whose | ||
* 'key' matches 'node_uuid'. | ||
* | ||
* Throws if multiple overrides match 'node_uuid' | ||
*/ | ||
void maybe_set_overrides( | ||
michael-redpanda marked this conversation as resolved.
Show resolved
Hide resolved
|
||
model::node_uuid node_uuid, | ||
const std::vector<config::node_id_override>& overrides); | ||
|
||
const std::optional<model::node_uuid>& node_uuid() const noexcept; | ||
const std::optional<model::node_id>& node_id() const noexcept; | ||
|
||
private: | ||
std::optional<model::node_uuid> _uuid_override; | ||
std::optional<model::node_id> _id_override; | ||
}; | ||
|
||
} // namespace config | ||
|
||
namespace YAML { | ||
|
||
template<> | ||
struct convert<config::node_id_override> { | ||
using type = config::node_id_override; | ||
static inline Node encode(const type& rhs) { | ||
Node node; | ||
node["current_uuid"] = ssx::sformat("{}", rhs.key); | ||
node["new_uuid"] = ssx::sformat("{}", rhs.uuid); | ||
node["new_id"] = ssx::sformat("{}", rhs.id); | ||
|
||
return node; | ||
} | ||
|
||
static inline bool decode(const Node& node, type& rhs) { | ||
if (!node["current_uuid"] || !node["new_uuid"] || !node["new_id"]) { | ||
return false; | ||
} | ||
rhs.key = node["current_uuid"].as<model::node_uuid>(); | ||
rhs.uuid = node["new_uuid"].as<model::node_uuid>(); | ||
rhs.id = node["new_id"].as<model::node_id>(); | ||
return true; | ||
} | ||
}; | ||
|
||
} // namespace YAML |
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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: any reason for the "construct lambda then immediately call" pattern?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
personal preference. "initialize this optional with the result of
from_string
or, if it throws, nullptr" feels a bit neater than "initialize this optional to nullptr then assign the result offrom_string
, unless it throws". The ID in the outer scope receives a value at exactly one code point.