forked from percona/orchestrator
-
Notifications
You must be signed in to change notification settings - Fork 10
Fix read_only scan error on MariaDB via CASE-WHEN string check #121
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
Merged
renecannao
merged 2 commits into
ProxySQL:master
from
ahmetsoguksu:fix/mariadb-read-only-bool-scan
Aug 11, 2026
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 |
|---|---|---|
| @@ -0,0 +1,65 @@ | ||
| #!/bin/bash | ||
| # Verify MariaDB read_only enum values are normalized correctly by discovery. | ||
| set -uo pipefail | ||
| cd "$(dirname "$0")/../.." || exit 1 | ||
| source tests/functional/lib.sh | ||
|
|
||
| echo "=== MARIADB READ_ONLY DISCOVERY TESTS ===" | ||
|
|
||
| COMPOSE="${COMPOSE:-docker compose -f tests/functional/docker-compose.yml -f tests/functional/docker-compose.mariadb.yml}" | ||
| TEST_INSTANCE="mysql2" | ||
|
|
||
| restore_read_only() { | ||
| $COMPOSE exec -T "$TEST_INSTANCE" mysql -uroot -ptestpass \ | ||
| -e "SET GLOBAL read_only=ON" >/dev/null 2>&1 || true | ||
| curl -s --max-time 10 "$ORC_URL/api/discover/$TEST_INSTANCE/3306" >/dev/null 2>&1 || true | ||
| } | ||
| trap restore_read_only EXIT | ||
|
|
||
| wait_for_orchestrator || { echo "FATAL: Orchestrator not reachable"; exit 1; } | ||
| discover_topology "mysql1" || { echo "FATAL: Topology not discovered"; exit 1; } | ||
|
|
||
| wait_for_api_read_only() { | ||
| local EXPECTED="$1" | ||
| local ACTUAL="" | ||
| for _ in $(seq 1 20); do | ||
| curl -s --max-time 10 "$ORC_URL/api/discover/$TEST_INSTANCE/3306" >/dev/null 2>&1 | ||
| ACTUAL=$(curl -s --max-time 10 "$ORC_URL/api/instance/$TEST_INSTANCE/3306" 2>/dev/null | python3 -c \ | ||
| "import json,sys; print(str(json.load(sys.stdin).get('ReadOnly')).lower())" 2>/dev/null || echo "") | ||
| if [ "$ACTUAL" = "$EXPECTED" ]; then | ||
| return 0 | ||
| fi | ||
| sleep 1 | ||
| done | ||
| echo "last API ReadOnly value: ${ACTUAL:-unavailable}" | ||
| return 1 | ||
| } | ||
|
|
||
| check_mode() { | ||
| local MODE="$1" | ||
| local EXPECTED="$2" | ||
| if ! $COMPOSE exec -T "$TEST_INSTANCE" mysql -uroot -ptestpass \ | ||
| -e "SET GLOBAL read_only=$MODE" >/dev/null 2>&1; then | ||
| fail "MariaDB rejected read_only=$MODE" | ||
| return | ||
| fi | ||
| if wait_for_api_read_only "$EXPECTED"; then | ||
| pass "read_only=$MODE is reported as ReadOnly=$EXPECTED" | ||
| else | ||
| fail "read_only=$MODE was not reported as ReadOnly=$EXPECTED" | ||
| fi | ||
| } | ||
|
|
||
| check_mode OFF false | ||
| check_mode ON true | ||
|
|
||
| MARIADB_MAJOR="$(mysql_version)" | ||
| MARIADB_MAJOR="${MARIADB_MAJOR%%.*}" | ||
| if [ "$MARIADB_MAJOR" -ge 12 ]; then | ||
| check_mode NO_LOCK true | ||
| check_mode NO_LOCK_NO_ADMIN true | ||
| else | ||
| skip "NO_LOCK modes require MariaDB 12 or newer" | ||
| fi | ||
|
|
||
| summary |
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.
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win
🧩 Analysis chain
🏁 Script executed:
Repository: ProxySQL/orchestrator
Length of output: 50378
🏁 Script executed:
Repository: ProxySQL/orchestrator
Length of output: 50377
🏁 Script executed:
Repository: ProxySQL/orchestrator
Length of output: 50377
🌐 Web query:
MariaDB read_only NO_LOCK NO_LOCK_NO_ADMIN supported versions official documentation💡 Result:
The options READ_ONLY_NO_LOCK and READ_ONLY_NO_LOCK_NO_ADMIN are part of an extension to the MariaDB read_only system variable introduced in MDEV-36425, which is associated with upcoming MariaDB 12.x versions [1][2]. These options provide more granular control over the read_only behavior: 1. READ_ONLY (or 1): Blocks changes for users without the 'READ ONLY ADMIN' privilege [1]. 2. READ_ONLY_NO_LOCK (or 2): In addition to blocking changes for non-admin users, it also blocks LOCK TABLES and SELECT IN SHARE MODE [1][3]. 3. READ_ONLY_NO_LOCK_NO_ADMIN (or 3): In addition to the above, it further restricts these operations even for users holding the 'READ ONLY ADMIN' privilege [1]. These settings were developed to allow for more robust restriction of operations on replicas to ensure they remain identical to the primary server by preventing unexpected blocking or modifications [1][4]. As these are recent additions for MariaDB 12.x, they may not be fully documented in older stable version manuals [2].
Citations:
🏁 Script executed:
Repository: ProxySQL/orchestrator
Length of output: 50377
Make the fallback explicit.
The current
CASEtreats every value except0andOFFas read-only. Use an allowlist so unknown values default to writable:Suggested CASE expression
The existing functional test already covers
OFF,ON, and MariaDB 12+NO_LOCKmodes.📝 Committable suggestion
🧰 Tools
🪛 OpenGrep (1.26.0)
[ERROR] 676-676: SQL query built via fmt.Sprintf or string concatenation passed to a database method. Use parameterized queries with placeholder arguments.
(coderabbit.sql-injection.go-query-format)
🤖 Prompt for AI Agents