Skip to content

Commit f778736

Browse files
authored
feat(mariadb): skip user-input SQL errors in reconfigure action to avoid infinite retry (#2889)
1 parent bb38a7c commit f778736

2 files changed

Lines changed: 61 additions & 6 deletions

File tree

addons/mariadb/scripts-ut-spec/reconfigure_persisted_alpha86_spec.sh

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -538,6 +538,27 @@ Describe "alpha.86 reconfigureAction.persisted semisync gates"
538538
End
539539
End
540540

541+
Describe "Rejected user-input SQL errors do not keep reconfigure on the failing path"
542+
It "base reconfigureAction skips classified engine rejects without exiting 1"
543+
When call extract_base_helper_body
544+
The status should be success
545+
The output should include 'skipped_count=$((skipped_count + 1))'
546+
The output should include 'parameter(s) were rejected by engine and skipped'
547+
The output should include 'if [ "${applied_count}" -eq 0 ] && [ "${skipped_count}" -eq 0 ]; then'
548+
The output should not include 'failing reconfigure to avoid accepting invalid rendered config'
549+
End
550+
551+
It "persisted reconfigureAction skips classified engine rejects without writing overrides or exiting 1"
552+
When call extract_persisted_helper_body
553+
The status should be success
554+
The output should include 'skipped_count=$((skipped_count + 1))'
555+
The output should include 'continue'
556+
The output should include 'parameter(s) were rejected by engine and skipped'
557+
The output should include 'if [ "${applied_count}" -eq 0 ] && [ "${skipped_count}" -eq 0 ]; then'
558+
The output should not include 'failing reconfigure to avoid accepting invalid rendered config'
559+
End
560+
End
561+
541562
Describe "Regression: KB-managed config has NO !includedir (alpha.84 v1 parser FAIL)"
542563
It "config/mariadb-semisync.tpl does NOT contain !includedir (mariadbd loads via --defaults-extra-file instead)"
543564
# alpha.84 v1 put !includedir into KB-managed my.cnf, which KB

addons/mariadb/templates/_helpers.tpl

Lines changed: 40 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -428,6 +428,7 @@ reconfigure:
428428
fi
429429

430430
applied_count=0
431+
skipped_count=0
431432
while IFS= read -r assignment; do
432433
[ -n "${assignment}" ] || continue
433434
case "${assignment}" in
@@ -453,12 +454,28 @@ reconfigure:
453454
echo "Set parameter ${param_name} to value ${param_value}"
454455
applied_count=$((applied_count + 1))
455456
else
456-
echo "Failed to set parameter ${param_name}=${param_value}: ${output}" >&2
457-
exit 1
457+
# Classify MariaDB SQL errors that are caused by bad user input.
458+
# These should not be retried indefinitely by the controller.
459+
error_code=$(printf '%s' "${output}" | grep -oE 'ERROR [0-9]+' | head -1 | awk '{print $2}')
460+
case "${error_code}" in
461+
1231|1232|1193|1064)
462+
echo "[REJECT] parameter ${param_name}=${param_value} rejected by engine (error ${error_code}): ${output}"
463+
echo "[REJECT] parameter ${param_name}=${param_value} rejected by engine (error ${error_code}): ${output}" >&2
464+
skipped_count=$((skipped_count + 1))
465+
;;
466+
*)
467+
echo "Failed to set parameter ${param_name}=${param_value}: ${output}" >&2
468+
exit 1
469+
;;
470+
esac
458471
fi
459472
done < "${parameter_file}"
460473

461-
if [ "${applied_count}" -eq 0 ]; then
474+
if [ "${skipped_count}" -gt 0 ]; then
475+
echo "${skipped_count} parameter(s) were rejected by engine and skipped"
476+
echo "${skipped_count} parameter(s) were rejected by engine and skipped" >&2
477+
fi
478+
if [ "${applied_count}" -eq 0 ] && [ "${skipped_count}" -eq 0 ]; then
462479
echo "No parameters were applied during reconfigure action" >&2
463480
exit 1
464481
fi
@@ -846,6 +863,7 @@ reconfigure:
846863
}
847864

848865
applied_count=0
866+
skipped_count=0
849867
while IFS= read -r assignment; do
850868
[ -n "${assignment}" ] || continue
851869
case "${assignment}" in
@@ -892,8 +910,20 @@ reconfigure:
892910
echo "Set parameter ${param_name} to value ${param_value}"
893911
applied_count=$((applied_count + 1))
894912
else
895-
echo "Failed to set parameter ${param_name}=${param_value}: ${output}" >&2
896-
exit 1
913+
# Classify MariaDB SQL errors that are caused by bad user input.
914+
error_code=$(printf '%s' "${output}" | grep -oE 'ERROR [0-9]+' | head -1 | awk '{print $2}')
915+
case "${error_code}" in
916+
1231|1232|1193|1064)
917+
echo "[REJECT] parameter ${param_name}=${param_value} rejected by engine (error ${error_code}): ${output}"
918+
echo "[REJECT] parameter ${param_name}=${param_value} rejected by engine (error ${error_code}): ${output}" >&2
919+
skipped_count=$((skipped_count + 1))
920+
continue
921+
;;
922+
*)
923+
echo "Failed to set parameter ${param_name}=${param_value}: ${output}" >&2
924+
exit 1
925+
;;
926+
esac
897927
fi
898928

899929
# alpha.86 v1 — persist the override AFTER SET GLOBAL succeeds.
@@ -956,7 +986,11 @@ reconfigure:
956986
# than catching the same issue at write time.
957987
done < "${parameter_file}"
958988

959-
if [ "${applied_count}" -eq 0 ]; then
989+
if [ "${skipped_count}" -gt 0 ]; then
990+
echo "${skipped_count} parameter(s) were rejected by engine and skipped"
991+
echo "${skipped_count} parameter(s) were rejected by engine and skipped" >&2
992+
fi
993+
if [ "${applied_count}" -eq 0 ] && [ "${skipped_count}" -eq 0 ]; then
960994
echo "No parameters were applied during reconfigure action" >&2
961995
exit 1
962996
fi

0 commit comments

Comments
 (0)