Fix empty member removal log, improve comment (#28)

This commit is contained in:
shaoyue
2021-12-21 16:29:28 +08:00
committed by GitHub
parent 88459fa1b9
commit 3968769b13
2 changed files with 5 additions and 2 deletions

View File

@@ -19,4 +19,7 @@ if is_empty_value "${endpoints}"; then
fi
read -r -a extra_flags <<< "$(etcdctl_auth_flags)"
extra_flags+=("--endpoints=${endpoints}" "--debug=true")
etcdctl member remove "$(cat "${ETCD_DATA_DIR}/member_id")" "${extra_flags[@]}" > "$(dirname "$ETCD_DATA_DIR")/member_removal.log"
# We use 'stdbuf' to ensure memory buffers are flushed to disk
# so we reduce the chances that the "member_removal.log" file is empty.
# ref: https://www.gnu.org/software/coreutils/manual/html_node/stdbuf-invocation.html#stdbuf-invocation
stdbuf -oL etcdctl member remove "$(cat "${ETCD_DATA_DIR}/member_id")" "${extra_flags[@]}" > "$(dirname "$ETCD_DATA_DIR")/member_removal.log"

View File

@@ -312,7 +312,7 @@ etcd_store_member_id() {
if retry_while "etcdctl ${extra_flags[*]} member list" >/dev/null 2>&1; then
while [[ ! -s "${ETCD_DATA_DIR}/member_id" ]]; do
# We use 'stdbuf' to ensure memory buffers are flushed to disk
# so we reduce the chances that the "member_id" file is not created.
# so we reduce the chances that the "member_id" file is empty.
# ref: https://www.gnu.org/software/coreutils/manual/html_node/stdbuf-invocation.html#stdbuf-invocation
read -r -a advertised_array <<< "$(tr ',;' ' ' <<< "$ETCD_ADVERTISE_CLIENT_URLS")"
stdbuf -oL etcdctl "${extra_flags[@]}" member list | grep -w "${advertised_array[0]}" | awk -F "," '{ print $1}' > "${ETCD_DATA_DIR}/member_id" || true