This repository has been archived by the owner on Jun 23, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 59
feat: restrict the replication factor while creating app #963
Merged
Merged
Changes from 4 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
d66b24e
fix: restrict the replica count while creating app
b442b44
fix: restrict the replica count while creating app
empiredan 71664b8
fix: restrict the replica count while creating app
empiredan e4113ef
fix: restrict the replica count while creating app
empiredan bc8283d
feat: restrict the replica count while creating app
empiredan 2aa0d0f
Merge remote-tracking branch 'upstream/master' into check-replica-count
3f0f423
feat: restrict the replica count while creating app
empiredan f682163
feat: restrict the replica count while creating app
empiredan b35411d
feat: restrict the replica count while creating app
empiredan 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -56,6 +56,17 @@ using namespace dsn; | |
namespace dsn { | ||
namespace replication { | ||
|
||
const int32_t max_allowed_replica_count = 15; | ||
|
||
DSN_DEFINE_int32("meta_server", | ||
levy5307 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
min_allowed_replica_count, | ||
1, | ||
"min allowed replica count for arbitrary number of nodes in a cluster"); | ||
|
||
DSN_DEFINE_validator(min_allowed_replica_count, [](int32_t allowed_replica_count) -> bool { | ||
return allowed_replica_count > 0 && allowed_replica_count <= max_allowed_replica_count; | ||
}); | ||
|
||
static const char *lock_state = "lock"; | ||
static const char *unlock_state = "unlock"; | ||
|
||
|
@@ -1072,7 +1083,13 @@ void server_state::create_app(dsn::message_ex *msg) | |
opt.replica_count == exist_app.max_replica_count; | ||
}; | ||
|
||
if (request.options.partition_count <= 0 || request.options.replica_count <= 0) { | ||
auto level = _meta_svc->get_function_level(); | ||
if (level <= meta_function_level::fl_freezed) { | ||
derror_f("current meta function level is freezed since there are too few alive nodes"); | ||
response.err = ERR_STATE_FREEZED; | ||
will_create_app = false; | ||
} else if (request.options.partition_count <= 0 || | ||
!validate_target_max_replica_count(request.options.replica_count)) { | ||
response.err = ERR_INVALID_PARAMETERS; | ||
will_create_app = false; | ||
} else { | ||
|
@@ -2864,5 +2881,55 @@ void server_state::clear_app_envs(const app_env_rpc &env_rpc) | |
new_envs.c_str()); | ||
}); | ||
} | ||
|
||
namespace { | ||
|
||
bool validate_target_max_replica_count_internal(int32_t max_replica_count, | ||
int32_t alive_node_count, | ||
std::string &hint_message) | ||
{ | ||
if (max_replica_count > max_allowed_replica_count) { | ||
hint_message = fmt::format("requested replica count({}) exceeds the max " | ||
"allowed replica count({})", | ||
max_replica_count, | ||
max_allowed_replica_count); | ||
return false; | ||
} | ||
|
||
if (max_replica_count < FLAGS_min_allowed_replica_count) { | ||
hint_message = fmt::format("requested replica count({}) is less than the min " | ||
"allowed replica count({})", | ||
max_replica_count, | ||
FLAGS_min_allowed_replica_count); | ||
return false; | ||
} | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. you may don't need to split two if (max_replica_count > max_allowed_replica_count || max_replica_count < FLAGS_min_allowed_replica_count) {
hint_message = fmt::format("requested replica count({}) must be range within [min={} max={}] ",
max_replica_count,
FLAGS_min_allowed_replica_count
max_allowed_replica_count);
return false;
} There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ok, I'll merge the both conditions. A range seems more specific. |
||
if (max_replica_count > alive_node_count) { | ||
hint_message = fmt::format("there are not enough alive replica servers({}) " | ||
"for the requested replica count({})", | ||
alive_node_count, | ||
max_replica_count); | ||
return false; | ||
} | ||
|
||
return true; | ||
} | ||
|
||
} // anonymous namespace | ||
|
||
bool server_state::validate_target_max_replica_count(int32_t max_replica_count) | ||
{ | ||
auto alive_node_count = static_cast<int32_t>(_meta_svc->get_alive_node_count()); | ||
|
||
std::string hint_message; | ||
bool is_valid = validate_target_max_replica_count_internal( | ||
max_replica_count, alive_node_count, hint_message); | ||
if (!is_valid) { | ||
derror_f("target max replica count is invalid: message={}", hint_message); | ||
} | ||
|
||
return is_valid; | ||
} | ||
|
||
} // namespace replication | ||
} // namespace dsn |
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.
Why the
max
is not setdynamic variable
likemin
?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.
Initially the
max_allowed_replica_count
was set configurable. Then as discussed with @hycdong above,max_allowed_replica_count
has been changed as a const value, not a configurable one, since in normal cases it will not be updated.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.
By the way, the const int should be named like
k...
refer to google code styleThere 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.
Agreed. I'd considered following google code style such as the camel-case naming of constant which begins with 'k'. On the other hand, however I'd found many constants are named in upper or lower snake case before I turned to follow the existing custom. I think we should gradually unify the naming style.