-
Notifications
You must be signed in to change notification settings - Fork 5
fix(replication): prevent excessive wait times after deploy (fixes #131) #137
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: master
Are you sure you want to change the base?
Changes from all commits
c8b8dc8
9e7bd82
453271a
934eb17
df96a7f
7c358b9
829d68f
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 |
|---|---|---|
|
|
@@ -70,13 +70,66 @@ function check_output | |
| # Wait until wsrep_ready is ON for Galera/PXC nodes. | ||
| # This prevents grants and user DML from running before the node | ||
| # has joined the cluster. | ||
| # On non-Galera servers the status variable does not exist and | ||
| # this function returns immediately (no delay) once the server accepts | ||
| # connections. | ||
| # Detection and polling connect as root via socket (no password), | ||
| # because the sandbox user (msandbox) may not exist yet on fresh | ||
| # nodes (load_grants has not run). | ||
| # Connect failures are NOT treated as non-Galera: the pid file can | ||
| # appear before the server accepts connections, so we retry until | ||
| # root can connect, then check whether wsrep_ready exists. | ||
| function wait_until_wsrep_ready | ||
| { | ||
| local use_cmd=${1:-$SBDIR/use} | ||
| local max_attempts=${2:-60} | ||
| local sleep_sec=${3:-2} | ||
| local max_attempts=${1:-60} | ||
| local sleep_sec=${2:-2} | ||
| local mysql_cmd="" | ||
| local clients | ||
| if [ "$FLAVOR" = "mariadb" ]; then | ||
| clients="mariadb mysql" | ||
| else | ||
| clients="mysql mariadb" | ||
| fi | ||
| local d c | ||
| for d in "$CLIENT_BASEDIR/bin" "$BASEDIR/bin"; do | ||
| for c in $clients; do | ||
| if [ -x "$d/$c" ]; then | ||
| mysql_cmd="$d/$c" | ||
| break 2 | ||
| fi | ||
| done | ||
| done | ||
| if [ -z "$mysql_cmd" ]; then | ||
| echo "WARNING: no mysql/mariadb client found under $CLIENT_BASEDIR/bin or $BASEDIR/bin" >&2 | ||
| return 1 | ||
| fi | ||
| # Wait until root can connect via socket. Empty query output before | ||
| # connect succeeds must not be treated as "non-Galera". | ||
| # Keep this budget separate and modest: pid-file can appear slightly | ||
| # before the server accepts connections, but not for minutes. | ||
| local connect_attempts=30 | ||
| local connect_sleep=1 | ||
| local connected=0 | ||
| local i | ||
| for i in $(seq 1 $connect_attempts); do | ||
| if $mysql_cmd --no-defaults -S "$SOCKET_FILE" -u root -BN -e "SELECT 1" >/dev/null 2>&1; then | ||
| connected=1 | ||
| break | ||
| fi | ||
| sleep $connect_sleep | ||
| done | ||
| if [ "$connected" -ne 1 ]; then | ||
| echo "WARNING: cannot connect as root via socket after $((connect_attempts * connect_sleep))s" >&2 | ||
| return 1 | ||
| fi | ||
| # Connected: empty SHOW STATUS means wsrep_ready does not exist (non-Galera). | ||
| local wsrep_check | ||
| wsrep_check=$($mysql_cmd --no-defaults -S "$SOCKET_FILE" -u root -BN -e "SHOW STATUS LIKE 'wsrep_ready';" 2>/dev/null) | ||
| if [ -z "$wsrep_check" ]; then | ||
| return 0 | ||
| fi | ||
|
Comment on lines
+125
to
+130
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. 🩺 Stability & Availability | 🟠 Major | ⚡ Quick win Check the query's exit status before treating empty output as "non-Galera". Line 127 discards the exit status of Distinguish command failure from an empty-but-successful result. 🐛 Proposed fix to distinguish query failure from a genuinely missing variable # Connected: empty SHOW STATUS means wsrep_ready does not exist (non-Galera).
local wsrep_check
- wsrep_check=$($mysql_cmd --no-defaults -S "$SOCKET_FILE" -u root -BN -e "SHOW STATUS LIKE 'wsrep_ready';" 2>/dev/null)
- if [ -z "$wsrep_check" ]; then
- return 0
- fi
+ if wsrep_check=$($mysql_cmd --no-defaults -S "$SOCKET_FILE" -u root -BN -e "SHOW STATUS LIKE 'wsrep_ready';" 2>/dev/null); then
+ if [ -z "$wsrep_check" ]; then
+ return 0
+ fi
+ else
+ echo "WARNING: wsrep_ready query failed after connect; retrying" >&2
+ fi🤖 Prompt for AI Agents |
||
| for i in $(seq 1 $max_attempts); do | ||
| if $use_cmd -BN -e "SHOW STATUS LIKE 'wsrep_ready';" 2>/dev/null | grep -qi 'ON' ; then | ||
| if $mysql_cmd --no-defaults -S "$SOCKET_FILE" -u root -BN -e "SHOW STATUS LIKE 'wsrep_ready';" 2>/dev/null | grep -qiE 'wsrep_ready[[:space:]]+ON'; then | ||
| return 0 | ||
| fi | ||
| sleep $sleep_sec | ||
|
|
@@ -90,11 +143,11 @@ function wait_until_wsrep_ready | |
| # initialization to prevent the race where the first client command on a | ||
| # just-started replica fails with "Access denied" or connection errors. | ||
| # Observed especially with MySQL 8.4+ and 9.x. | ||
| # Usage: wait_until_replica_ready "$SBDIR/s1/use" 60 1 | ||
| # Usage: wait_until_replica_ready "$SBDIR/s1/use" 20 1 | ||
| function wait_until_replica_ready | ||
| { | ||
| local use_cmd=${1:-$SBDIR/use} | ||
| local max_attempts=${2:-60} | ||
| local max_attempts=${2:-20} | ||
| local sleep_sec=${3:-1} | ||
| for i in $(seq 1 $max_attempts); do | ||
| if $use_cmd -BN -e "SELECT 1;" >/dev/null 2>&1 ; then | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.