Skip to content

Instantly share code, notes, and snippets.

@rluisr
Last active February 1, 2024 08:59
Show Gist options
  • Save rluisr/c3fd3261cdd7266e13a25f2f63644c10 to your computer and use it in GitHub Desktop.
Save rluisr/c3fd3261cdd7266e13a25f2f63644c10 to your computer and use it in GitHub Desktop.
(orchestrator) check errant gtid transactions, fix it and execute can-replicate-from-gtid on all cluster and all combinations.
#!/bin/bash
set -eu
readonly CLUSTERS=( $( orchestrator -c clusters ) )
function can_replicate {
for cluster in "${CLUSTERS[@]}"
do
replicas=( $( orchestrator -c which-replicas -i "${cluster}") )
for replica_i in "${!replicas[@]}"
do
for other_i in "${!replicas[@]}"
do
if [ ${replica_i} -eq ${other_i} ]; then
continue
fi
source_replica="${replicas[${replica_i}]}"
destination="${replicas[${other_i}]}"
set +e
result=$( orchestrator -c can-replicate-from-gtid -i "${source_replica}" -d "${destination}" )
if [ $? -ne 0 ]; then
echo -e "${source_replica} to ${destination} cannot replicate\nError: ${result}\nCheck errant gtid http://<orchestrator ip>:3000/web/cluster/alias/prd-dbs07"
exit 2
fi
set -e
done
done
done
}
function check_errant {
for cluster in "${CLUSTERS[@]}"
do
replicas=( $( orchestrator -c which-replicas -i "${cluster}") )
for replica in "${replicas[@]}"
do
local result=$( orchestrator -c which-gtid-errant -i "${replica}" )
if [ -n "${result}" ]; then
inject_empty_transaction "${replica}"
fi
done
done
}
function inject_empty_transaction {
local replica="${1}"
orchestrator -c gtid-errant-inject-empty -i "${replica}"
}
function main {
check_errant
sleep 10s
can_replicate
}
main "$@"
This is free and unencumbered software released into the public domain.
Anyone is free to copy, modify, publish, use, compile, sell, or
distribute this software, either in source code form or as a compiled
binary, for any purpose, commercial or non-commercial, and by any
means.
In jurisdictions that recognize copyright laws, the author or authors
of this software dedicate any and all copyright interest in the
software to the public domain. We make this dedication for the benefit
of the public at large and to the detriment of our heirs and
successors. We intend this dedication to be an overt act of
relinquishment in perpetuity of all present and future rights to this
software under copyright law.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.
For more information, please refer to <https://unlicense.org>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment