-
Notifications
You must be signed in to change notification settings - Fork 91
đ (ZENKO-5303) make voting and priority right #2452
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
base: development/2.15
Are you sure you want to change the base?
Changes from all commits
528728f
8993623
af6419d
d60b127
e4d966a
1c791a6
f29e6c9
da83b20
a7f8be2
f29073d
514ca64
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -951,6 +951,32 @@ EOF | |
| grep -q "ok: 1" <<<"$result" | ||
| } | ||
|
|
||
| ######################## | ||
| # Get if secondary node already has voting rights | ||
| # Globals: | ||
| # MONGODB_* | ||
| # Arguments: | ||
| # $1 - node | ||
| # $2 - port | ||
| # Returns: | ||
| # Boolean | ||
| ######################### | ||
| mongodb_secondary_node_has_voting_rights() { | ||
| local -r node="${1:?node is required}" | ||
| local -r port="${2:?port is required}" | ||
| local result | ||
|
|
||
| debug "Checking voting rights of the node" | ||
| result=$( | ||
| mongodb_execute_print_output "$MONGODB_INITIAL_PRIMARY_ROOT_USER" "$MONGODB_INITIAL_PRIMARY_ROOT_PASSWORD" "admin" "$MONGODB_INITIAL_PRIMARY_HOST" "$MONGODB_INITIAL_PRIMARY_PORT_NUMBER" <<EOF | ||
| rs.conf().members.filter(m => m.host === '$node:$port' && m.votes > 0 && m.priority > 0).length === 1 | ||
| EOF | ||
| ) | ||
| debug "$result" | ||
|
|
||
| grep -q "true" <<<"$result" | ||
| } | ||
|
|
||
| ######################## | ||
| # Get if hidden node is pending | ||
| # Globals: | ||
|
|
@@ -1187,7 +1213,15 @@ mongodb_configure_secondary() { | |
| exit 1 | ||
| fi | ||
| mongodb_wait_confirmation "$node" "$port" | ||
| fi | ||
|
|
||
| # Grant voting rights to the node if it does not have them yet. This must be | ||
| # done even when the node is already in the cluster: a previous attempt may | ||
| # have added it with votes/priority 0 and failed (or been restarted) before | ||
| # granting voting rights, leaving the node stuck without them. | ||
| if mongodb_secondary_node_has_voting_rights "$node" "$port"; then | ||
| info "Node already has voting rights" | ||
| else | ||
|
Contributor
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. this will not behave properly when we have 9-replicas, where 2 nodes are always "non voting". This is expected, and we must not try to change that (in particular, the voting nodes must be in precisely the expected DC for proper redundancy) â the change will make the startup slower on these extra secondaries -(re-)trying to make them voting-, possibly with the extra risk of changing the set of voters... |
||
| # Ensure that secondary nodes do not count as voting members until they are fully initialized | ||
| # https://docs.mongodb.com/manual/reference/method/rs.add/#behavior | ||
| if ! retry_while "mongodb_is_secondary_node_ready $node $port" "$MONGODB_INIT_RETRY_ATTEMPTS" "$MONGODB_INIT_RETRY_DELAY"; then | ||
|
|
@@ -1198,17 +1232,16 @@ mongodb_configure_secondary() { | |
| # Grant voting rights to node | ||
| # https://docs.mongodb.com/manual/tutorial/modify-psa-replica-set-safely/ | ||
| if ! retry_while "mongodb_configure_secondary_node_voting $node $port" "$MONGODB_INIT_RETRY_ATTEMPTS" "$MONGODB_INIT_RETRY_DELAY"; then | ||
| error "Secondary node did not get marked as secondary" | ||
| error "Secondary node did not get granted voting rights" | ||
| exit 1 | ||
| fi | ||
| fi | ||
|
|
||
| # Mark node as readable. This is necessary in cases where the PVC is lost | ||
| if is_boolean_yes "$MONGODB_SET_SECONDARY_OK"; then | ||
| mongodb_execute_print_output "$MONGODB_INITIAL_PRIMARY_ROOT_USER" "$MONGODB_INITIAL_PRIMARY_ROOT_PASSWORD" "admin" <<EOF | ||
| # Mark node as readable. This is necessary in cases where the PVC is lost | ||
| if is_boolean_yes "$MONGODB_SET_SECONDARY_OK"; then | ||
| mongodb_execute_print_output "$MONGODB_INITIAL_PRIMARY_ROOT_USER" "$MONGODB_INITIAL_PRIMARY_ROOT_PASSWORD" "admin" <<EOF | ||
| rs.secondaryOk() | ||
| EOF | ||
| fi | ||
|
|
||
| fi | ||
| } | ||
|
|
||
|
|
@@ -1667,3 +1700,46 @@ mongodb_execute_print_output() { | |
| mongodb_execute() { | ||
| debug_execute mongodb_execute_print_output "$@" | ||
| } | ||
|
|
||
| # Copyright Broadcom, Inc. All Rights Reserved. | ||
| # SPDX-License-Identifier: APACHE-2.0 | ||
|
|
||
| # shellcheck disable=SC2148 | ||
|
|
||
| ######################## | ||
| # Execute an arbitrary query/queries against the running MongoDB service | ||
| # Stdin: | ||
| # Query/queries to execute | ||
| # Arguments: | ||
| # $1 - User to run queries | ||
| # $2 - Password | ||
| # $3 - Database where to run the queries | ||
| # $4 - Host (default to result of get_mongo_hostname function) | ||
| # $5 - Port (default $MONGODB_PORT_NUMBER) | ||
| # $6 - Extra arguments (default $MONGODB_SHELL_EXTRA_FLAGS) | ||
| # Returns: | ||
| # None | ||
| ######################## | ||
| mongodb_execute() { | ||
|
Contributor
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. already merged : please rebase on top of actual target branch |
||
| local -r user="${1:-}" | ||
| local -r password="${2:-}" | ||
| local -r database="${3:-}" | ||
| local -r host="${4:-$(get_mongo_hostname)}" | ||
| local -r port="${5:-$MONGODB_PORT_NUMBER}" | ||
| local -r extra_args="${6:-$MONGODB_SHELL_EXTRA_FLAGS}" | ||
| local final_user="$user" | ||
| # If password is empty it means no auth, do not specify user | ||
| [[ -z "$password" ]] && final_user="" | ||
|
|
||
| local -a args=("--host" "$host" "--port" "$port") | ||
| [[ -n "$final_user" ]] && args+=("-u" "$final_user") | ||
| [[ -n "$password" ]] && args+=("-p" "$password") | ||
| if [[ -n "$extra_args" ]]; then | ||
| local extra_args_array=() | ||
| read -r -a extra_args_array <<<"$extra_args" | ||
| [[ "${#extra_args_array[@]}" -gt 0 ]] && args+=("${extra_args_array[@]}") | ||
| fi | ||
| [[ -n "$database" ]] && args+=("$database") | ||
|
|
||
| "$MONGODB_BIN_DIR/mongosh" "${args[@]}" | ||
| } | ||
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: