Apache Pulsar multi-tenant backlog quarantine and priority event router
Drain a multi-tenant Pulsar topic and route each batch by tenant priority tier, logging ENTERPRISE traffic and quarantining the rest, with a Slack report per run.
Migrate Redis to Valkey or a newer Redis with replication. Write protect the source, compare every key, promote the target and keep a rollback.
# SPDX-License-Identifier: Apache-2.0
id: redis-valkey-live-migration-verified-cutover
namespace: company.team
description: Migrate a Redis or Valkey server to Valkey or a newer Redis with
replication, then cut over only after every key matches and the old server is
write protected.
concurrency:
limit: 1
behavior: QUEUE
inputs:
- id: mode
type: SELECT
values:
- PREPARE
- CUTOVER
- ROLLBACK
- FINALIZE
defaults: PREPARE
description: PREPARE starts replication to the target. CUTOVER protects the
source, proves the match and promotes the target. ROLLBACK undoes a
cutover or a freeze. FINALIZE ends the migration after a completed
cutover.
- id: source_host
type: STRING
defaults: redis-source
- id: source_port
type: STRING
defaults: "6379"
validator: ^[0-9]{2,5}$
- id: source_user
type: STRING
defaults: ""
description: ACL user of the source. Leave empty for the default user.
- id: source_password
type: SECRET
defaults: "{{ secret('REDIS_SOURCE_PASSWORD') }}"
- id: target_host
type: STRING
defaults: valkey-target
- id: target_port
type: STRING
defaults: "6379"
validator: ^[0-9]{2,5}$
- id: target_user
type: STRING
defaults: ""
- id: target_password
type: SECRET
defaults: "{{ secret('REDIS_TARGET_PASSWORD') }}"
- id: migration_name
type: STRING
defaults: redis-migration
validator: ^[a-z0-9-]{1,40}$
description: Name of the migration. Its state is kept in the namespace KV store
under this name.
- id: tools_image
type: STRING
defaults: redis:7-alpine
description: Image that provides redis-cli.
- id: docker_network
type: STRING
defaults: bridge
- id: freeze_seconds
type: STRING
defaults: "300"
validator: ^[0-9]{1,4}$
description: How long the source holds writes and expirations while the match is proved.
- id: lag_rounds
type: STRING
defaults: "24"
validator: ^[0-9]{1,2}$
description: Maximum catch-up checks during a cutover. They run 5 seconds apart.
- id: verify_percent
type: STRING
defaults: "100"
validator: ^([1-9][0-9]?|100)$
description: Share of the keys that the comparison reads. Use 100 for a full proof.
- id: dry_run
type: BOOL
defaults: true
- id: auto_remediate
type: BOOL
defaults: false
variables:
live: "{{ inputs.dry_run == false and inputs.auto_remediate == true }}"
inspect_sh: |
set -eu
q() { _h=$1; _p=$2; _u=$3; _w=$4; shift 4; REDISCLI_AUTH="$_w" redis-cli -h "$_h" -p "$_p" ${_u:+--user "$_u"} "$@" 2>&1 | tr -d '\r'; }
field() { printf '%s\n' "$1" | sed -n "s/^$2://p" | head -1; }
num() { printf '%s\n' "$1" | awk 'NR==1 { v=$1+0 } END { print v+0 }'; }
json=""
inspect() { # prefix host port user pw
pre=$1; h=$2; p=$3; u=$4; w=$5
ping=$(q "$h" "$p" "$u" "$w" PING | head -1)
if [ "$ping" != "PONG" ]; then json="$json\"${pre}_reachable\":false,\"${pre}_error\":\"$(printf '%s' "$ping" | tr -d '"\\')\","; return; fi
srv=$(q "$h" "$p" "$u" "$w" INFO server); rep=$(q "$h" "$p" "$u" "$w" INFO replication); ks=$(q "$h" "$p" "$u" "$w" INFO keyspace); mem=$(q "$h" "$p" "$u" "$w" INFO memory)
ver=$(field "$srv" valkey_version); flavor=valkey
if [ -z "$ver" ]; then ver=$(field "$srv" redis_version); flavor=redis; fi
vnum=$(printf '%s' "$ver" | awk -F. '{ printf "%d", $1*10000+$2*100+$3 }')
keys=$(printf '%s\n' "$ks" | sed -n 's/^db[0-9]*:keys=\([0-9]*\),.*/\1/p' | awk '{ s+=$1 } END { print s+0 }')
mr=$(q "$h" "$p" "$u" "$w" CONFIG GET min-replicas-to-write | sed -n 2p); case "$mr" in ''|*[!0-9]*) mr=denied;; esac
json="$json\"${pre}_reachable\":true,\"${pre}_version\":\"$ver\",\"${pre}_flavor\":\"$flavor\",\"${pre}_version_num\":$vnum,\"${pre}_role\":\"$(field "$rep" role)\",\"${pre}_connected_replicas\":$(num "$(field "$rep" connected_slaves)"),\"${pre}_master_offset\":$(num "$(field "$rep" master_repl_offset)"),\"${pre}_replica_offset\":$(num "$(field "$rep" slave_repl_offset)"),\"${pre}_link\":\"$(field "$rep" master_link_status)\",\"${pre}_sync_in_progress\":$(num "$(field "$rep" master_sync_in_progress)"),\"${pre}_master_host\":\"$(field "$rep" master_host)\",\"${pre}_keys\":$keys,\"${pre}_min_replicas\":\"$mr\",\"${pre}_used_memory\":$(num "$(field "$mem" used_memory)"),\"${pre}_maxmemory\":$(num "$(field "$mem" maxmemory)"),"
}
inspect src "$SRC_HOST" "$SRC_PORT" "${SRC_USER:-}" "$SRC_PW"
inspect tgt "$TGT_HOST" "$TGT_PORT" "${TGT_USER:-}" "$TGT_PW"
printf '::{"outputs":{%s"done":true}}::\n' "$json"
verify_sh: |
set -eu
export LC_ALL=C
q() { # side host port user pw ...
_h=$1; _p=$2; _u=$3; _w=$4; shift 4
REDISCLI_AUTH="$_w" redis-cli -h "$_h" -p "$_p" ${_u:+--user "$_u"} "$@"
}
digest_side() { # name host port user pw
n=$1; h=$2; p=$3; u=$4; w=$5
: > "$n.tsv"
dbs=$(q "$h" "$p" "$u" "$w" INFO keyspace | sed -n 's/^db\([0-9]*\):.*/\1/p')
for db in $dbs; do
q "$h" "$p" "$u" "$w" -n "$db" --scan --count 1000 | sort -u > "$n.$db.keys"
if [ "$PERCENT" -lt 100 ]; then
awk -v pct="$PERCENT" '{ c=0; for(i=1;i<=length($0);i++){ c=(c*31+index("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789:_-.",substr($0,i,1)))%100 } if (c<pct) print }' "$n.$db.keys" > "$n.$db.sel"
else cp "$n.$db.keys" "$n.$db.sel"; fi
set --
while IFS= read -r k; do
set -- "$@" "$k"
if [ "$#" -ge 100 ]; then flush_batch "$n" "$db" "$h" "$p" "$u" "$w" "$@"; set --; fi
done < "$n.$db.sel"
if [ "$#" -gt 0 ]; then flush_batch "$n" "$db" "$h" "$p" "$u" "$w" "$@"; fi
done
sort "$n.tsv" -o "$n.tsv"
}
flush_batch() {
n=$1; db=$2; h=$3; p=$4; u=$5; w=$6; shift 6
q "$h" "$p" "$u" "$w" -n "$db" EVAL_RO "$LUA" "$#" "$@" > batch.out
i=0
while IFS= read -r d; do i=$((i+1)); eval "k=\${$i}"; printf 'db%s:%s\t%s\n' "$db" "$k" "$d"; done < batch.out >> "$n.tsv"
}
digest_side src "$SRC_HOST" "$SRC_PORT" "${SRC_USER:-}" "$SRC_PW"
digest_side tgt "$TGT_HOST" "$TGT_PORT" "${TGT_USER:-}" "$TGT_PW"
awk -F'\t' 'FNR==NR { s[$1]=$2; next } { t[$1]=$2 } END {
ns=0; nt=0; mt=0; ms=0; df=0; sample=""
for (k in s) { ns++; if (!(k in t)) { mt++; if (n<5) { sample=sample (sample==""?"":" ") "missing:" k; n++ } } else if (s[k]!=t[k]) { df++; if (n<5) { sample=sample (sample==""?"":" ") "different:" k; n++ } } }
for (k in t) { nt++; if (!(k in s)) { ms++; if (n<5) { sample=sample (sample==""?"":" ") "extra:" k; n++ } } }
printf "%d %d %d %d %d %s\n", ns, nt, mt, ms, df, sample > "result.txt" }' src.tsv tgt.tsv
read ns nt mt ms df sample < result.txt || true
hash=$(sha256sum src.tsv | cut -d' ' -f1)
tgthash=$(sha256sum tgt.tsv | cut -d' ' -f1)
printf '::{"outputs":{"keys_source":%s,"keys_target":%s,"missing_on_target":%s,"extra_on_target":%s,"different":%s,"source_hash":"%s","target_hash":"%s","examples":"%s"}}::\n' "$ns" "$nt" "$mt" "$ms" "$df" "$hash" "$tgthash" "$(printf '%s' "$sample" | tr -d '"\\')"
digest_lua: |
local function ser(v)
if type(v) == 'table' then
local parts = {}
for i = 1, #v do parts[#parts + 1] = ser(v[i]) end
return '[' .. table.concat(parts, ',') .. ']'
end
return tostring(v)
end
local out = {}
for i, key in ipairs(KEYS) do
local t = redis.call('TYPE', key)['ok']
local blob = ''
if t == 'string' then
blob = redis.call('GET', key)
elseif t == 'hash' then
local a = redis.call('HGETALL', key)
local pairs_ = {}
for j = 1, #a, 2 do pairs_[#pairs_ + 1] = a[j] .. '\1' .. a[j + 1] end
table.sort(pairs_)
blob = table.concat(pairs_, '\2')
elseif t == 'list' then
blob = table.concat(redis.call('LRANGE', key, 0, -1), '\2')
elseif t == 'set' then
local m = redis.call('SMEMBERS', key)
table.sort(m)
blob = table.concat(m, '\2')
elseif t == 'zset' then
blob = table.concat(redis.call('ZRANGE', key, 0, -1, 'WITHSCORES'), '\2')
elseif t == 'stream' then
blob = ser(redis.call('XRANGE', key, '-', '+'))
end
local ok, exp = pcall(redis.call, 'PEXPIRETIME', key)
if not ok then exp = -3 end
out[i] = redis.sha1hex(key .. '\0' .. t .. '\0' .. tostring(exp) .. '\0' .. blob)
end
return out
probe_source_sh: |
set -eu
out=$(REDISCLI_AUTH="$SRC_PW" timeout 5 redis-cli -h "$SRC_HOST" -p "$SRC_PORT" ${SRC_USER:+--user "$SRC_USER"} SET "kestra:probe:$EXEC" 1 2>&1 | tr -d '\r' | head -1 || true)
refused=false
case "$out" in *NOREPLICAS*) refused=true;; esac
if [ "$out" = "OK" ]; then REDISCLI_AUTH="$SRC_PW" redis-cli -h "$SRC_HOST" -p "$SRC_PORT" ${SRC_USER:+--user "$SRC_USER"} DEL "kestra:probe:$EXEC" >/dev/null; fi
printf '::{"outputs":{"source_refused":%s,"answer":"%s"}}::\n' "$refused" "$(printf '%s' "$out" | tr -d '"\\')"
probe_target_sh: |
set -eu
c() { REDISCLI_AUTH="$TGT_PW" redis-cli -h "$TGT_HOST" -p "$TGT_PORT" ${TGT_USER:+--user "$TGT_USER"} "$@" 2>&1 | tr -d '\r'; }
role=$(c INFO replication | sed -n 's/^role://p' | head -1)
w=$(c SET "kestra:probe:$EXEC" 1 | head -1)
g=$(c GET "kestra:probe:$EXEC" | head -1)
c DEL "kestra:probe:$EXEC" >/dev/null
ok=false
if [ "$role" = "master" ] && [ "$w" = "OK" ] && [ "$g" = "1" ]; then ok=true; fi
printf '::{"outputs":{"target_writable":%s,"role":"%s"}}::\n' "$ok" "$role"
probe_reopen_sh: |
set -eu
c() { REDISCLI_AUTH="$SRC_PW" redis-cli -h "$SRC_HOST" -p "$SRC_PORT" ${SRC_USER:+--user "$SRC_USER"} "$@" 2>&1 | tr -d '\r'; }
w=$(c SET "kestra:probe:$EXEC" 1 | head -1)
c DEL "kestra:probe:$EXEC" >/dev/null || true
ok=false
if [ "$w" = "OK" ]; then ok=true; fi
printf '::{"outputs":{"source_writable":%s,"answer":"%s"}}::\n' "$ok" "$(printf '%s' "$w" | tr -d '"\\')"
tasks:
- id: inspect
type: io.kestra.plugin.scripts.shell.Commands
containerImage: "{{ inputs.tools_image }}"
taskRunner:
type: io.kestra.plugin.scripts.runner.docker.Docker
networkMode: "{{ inputs.docker_network }}"
entryPoint: []
env:
SRC_HOST: "{{ inputs.source_host }}"
SRC_PORT: "{{ inputs.source_port }}"
SRC_USER: "{{ inputs.source_user }}"
SRC_PW: "{{ inputs.source_password }}"
TGT_HOST: "{{ inputs.target_host }}"
TGT_PORT: "{{ inputs.target_port }}"
TGT_USER: "{{ inputs.target_user }}"
TGT_PW: "{{ inputs.target_password }}"
commands:
- "{{ vars.inspect_sh }}"
- id: require_reachable
type: io.kestra.plugin.core.execution.Fail
condition: >-
{{ outputs.inspect.vars.src_reachable != true or
outputs.inspect.vars.tgt_reachable != true or
(inputs.source_host == inputs.target_host and inputs.source_port == inputs.target_port) }}
errorMessage: The source or the target cannot be reached with these credentials.
They may also point at the same server.
- id: require_compatible
type: io.kestra.plugin.core.execution.Fail
condition: >-
{{ outputs.inspect.vars.src_role != 'master' or
(outputs.inspect.vars.tgt_flavor == 'redis' and (outputs.inspect.vars.src_flavor != 'redis' or outputs.inspect.vars.tgt_version_num < outputs.inspect.vars.src_version_num)) or
(outputs.inspect.vars.tgt_flavor == 'valkey' and outputs.inspect.vars.src_flavor == 'redis' and outputs.inspect.vars.src_version_num > 70299) or
(outputs.inspect.vars.tgt_flavor == 'valkey' and outputs.inspect.vars.src_flavor == 'valkey' and outputs.inspect.vars.tgt_version_num < outputs.inspect.vars.src_version_num) }}
errorMessage: The source must be a master. The target must not be older than the
source. A Redis target cannot replicate from Valkey and Valkey replicates
only from Redis OSS 7.2 or older.
- id: plan
type: io.kestra.plugin.core.log.Log
message: >-
Mode {{ inputs.mode }}. Source {{ outputs.inspect.vars.src_flavor }} {{
outputs.inspect.vars.src_version }} with {{ outputs.inspect.vars.src_keys
}} keys, target {{ outputs.inspect.vars.tgt_flavor }} {{
outputs.inspect.vars.tgt_version }} with {{ outputs.inspect.vars.tgt_keys
}} keys, role {{ outputs.inspect.vars.tgt_role }}. {{ render(vars.live) ==
'true' ? 'Live run: changes will be applied.' : 'Dry run: nothing is
changed on either server.' }}
- id: live_run
type: io.kestra.plugin.core.flow.If
condition: "{{ render(vars.live) == 'true' }}"
then:
- id: read_state
type: io.kestra.plugin.core.kv.Get
key: "redis-migration-{{ inputs.migration_name }}"
errorOnMissing: false
- id: current
type: io.kestra.plugin.core.output.OutputValues
values:
state: "{{ (outputs.read_state.value ?? {}).state ?? 'NONE' }}"
- id: require_allowed_state
type: io.kestra.plugin.core.execution.Fail
condition: >-
{{ (inputs.mode == 'PREPARE' and not (['NONE', 'PREPARING',
'PREPARED', 'ROLLED_BACK'] contains outputs.current.values.state)) or
(inputs.mode == 'CUTOVER' and not (['PREPARED', 'ROLLED_BACK', 'FREEZING', 'FROZEN'] contains outputs.current.values.state)) or
(inputs.mode == 'ROLLBACK' and not (['FREEZING', 'FROZEN', 'COMPLETED'] contains outputs.current.values.state)) or
(inputs.mode == 'FINALIZE' and outputs.current.values.state != 'COMPLETED') }}
errorMessage: "The recorded migration state does not allow this mode. PREPARE
needs no cutover in progress, CUTOVER needs a prepared migration,
ROLLBACK needs a freeze or a completed cutover to undo and FINALIZE
needs a completed cutover."
- id: prepare
type: io.kestra.plugin.core.flow.If
condition: "{{ inputs.mode == 'PREPARE' }}"
then:
- id: require_empty_target
type: io.kestra.plugin.core.execution.Fail
condition: "{{ outputs.inspect.vars.tgt_keys != 0 and
outputs.inspect.vars.tgt_master_host != inputs.source_host }}"
errorMessage: The target already holds keys and is not replicating from this
source. PREPARE needs an empty target because replication replaces
its data.
- id: preparing_mark
type: io.kestra.plugin.core.flow.If
condition: "{{ outputs.current.values.state == 'NONE' }}"
then:
- id: preparing_state
type: io.kestra.plugin.core.kv.Set
key: "redis-migration-{{ inputs.migration_name }}"
kvType: JSON
value: '{"state":"PREPARING"}'
- id: allow_source_login
type: io.kestra.plugin.core.flow.If
condition: "{{ inputs.source_password != '' }}"
then:
- id: set_masterauth
type: io.kestra.plugin.redis.cli.RedisCLI
host: "{{ inputs.target_host }}"
port: "{{ inputs.target_port }}"
username: "{{ inputs.target_user }}"
password: "{{ inputs.target_password }}"
containerImage: "{{ inputs.tools_image }}"
taskRunner:
type: io.kestra.plugin.scripts.runner.docker.Docker
networkMode: "{{ inputs.docker_network }}"
entryPoint: []
commands:
- CONFIG SET masterauth "{{ inputs.source_password }}"
- id: allow_source_user
type: io.kestra.plugin.core.flow.If
condition: "{{ inputs.source_user != '' }}"
then:
- id: set_masteruser
type: io.kestra.plugin.redis.cli.RedisCLI
host: "{{ inputs.target_host }}"
port: "{{ inputs.target_port }}"
username: "{{ inputs.target_user }}"
password: "{{ inputs.target_password }}"
containerImage: "{{ inputs.tools_image }}"
taskRunner:
type: io.kestra.plugin.scripts.runner.docker.Docker
networkMode: "{{ inputs.docker_network }}"
entryPoint: []
commands:
- CONFIG SET masteruser "{{ inputs.source_user }}"
- id: start_replication
type: io.kestra.plugin.core.flow.If
condition: "{{ outputs.inspect.vars.tgt_master_host != inputs.source_host }}"
then:
- id: replicate_from_source
type: io.kestra.plugin.redis.cli.RedisCLI
host: "{{ inputs.target_host }}"
port: "{{ inputs.target_port }}"
username: "{{ inputs.target_user }}"
password: "{{ inputs.target_password }}"
containerImage: "{{ inputs.tools_image }}"
taskRunner:
type: io.kestra.plugin.scripts.runner.docker.Docker
networkMode: "{{ inputs.docker_network }}"
entryPoint: []
commands:
- REPLICAOF {{ inputs.source_host }} {{ inputs.source_port }}
- id: wait_initial_sync
type: io.kestra.plugin.core.flow.LoopUntil
condition: >-
{{ outputs.sync_status.vars.tgt_role == 'slave' and
outputs.sync_status.vars.tgt_link == 'up' and
outputs.sync_status.vars.tgt_sync_in_progress == 0 and
(outputs.sync_status.vars.tgt_keys > 0 or outputs.sync_status.vars.src_keys == 0) }}
checkFrequency:
interval: PT5S
maxIterations: 60
failOnMaxReached: true
tasks:
- id: sync_status
type: io.kestra.plugin.scripts.shell.Commands
containerImage: "{{ inputs.tools_image }}"
taskRunner:
type: io.kestra.plugin.scripts.runner.docker.Docker
networkMode: "{{ inputs.docker_network }}"
entryPoint: []
env:
SRC_HOST: "{{ inputs.source_host }}"
SRC_PORT: "{{ inputs.source_port }}"
SRC_USER: "{{ inputs.source_user }}"
SRC_PW: "{{ inputs.source_password }}"
TGT_HOST: "{{ inputs.target_host }}"
TGT_PORT: "{{ inputs.target_port }}"
TGT_USER: "{{ inputs.target_user }}"
TGT_PW: "{{ inputs.target_password }}"
commands:
- "{{ vars.inspect_sh }}"
- id: prepared_mark
type: io.kestra.plugin.core.flow.If
condition: "{{ outputs.current.values.state != 'PREPARED' }}"
then:
- id: prepared_state
type: io.kestra.plugin.core.kv.Set
key: "redis-migration-{{ inputs.migration_name }}"
kvType: JSON
value: '{"state":"PREPARED","keys":{{ outputs.sync_status.vars.tgt_keys }}}'
- id: cutover_approval
type: io.kestra.plugin.core.flow.If
condition: "{{ inputs.mode == 'CUTOVER' and outputs.current.values.state !=
'FROZEN' }}"
then:
- id: approve_cutover
type: io.kestra.plugin.core.flow.Pause
pauseDuration: PT1H
behavior: FAIL
onResume:
- id: approved
type: BOOL
defaults: false
description: Approve write protecting the source and promoting the target.
- id: writers_stopped
type: BOOL
defaults: false
description: Confirm that applications can tolerate refused writes on the source
until they use the target.
- id: cutover
type: io.kestra.plugin.core.flow.If
condition: >-
{{ inputs.mode == 'CUTOVER' and
(outputs.current.values.state == 'FROZEN' or
(outputs.approve_cutover.onResume.approved == true and outputs.approve_cutover.onResume.writers_stopped == true)) }}
then:
- id: recheck
type: io.kestra.plugin.scripts.shell.Commands
containerImage: "{{ inputs.tools_image }}"
taskRunner:
type: io.kestra.plugin.scripts.runner.docker.Docker
networkMode: "{{ inputs.docker_network }}"
entryPoint: []
env:
SRC_HOST: "{{ inputs.source_host }}"
SRC_PORT: "{{ inputs.source_port }}"
SRC_USER: "{{ inputs.source_user }}"
SRC_PW: "{{ inputs.source_password }}"
TGT_HOST: "{{ inputs.target_host }}"
TGT_PORT: "{{ inputs.target_port }}"
TGT_USER: "{{ inputs.target_user }}"
TGT_PW: "{{ inputs.target_password }}"
commands:
- "{{ vars.inspect_sh }}"
- id: require_unchanged_plan
type: io.kestra.plugin.core.execution.Fail
condition: >-
{{ outputs.recheck.vars.tgt_role != 'slave' or
outputs.recheck.vars.tgt_link != 'up' or
outputs.recheck.vars.tgt_sync_in_progress != 0 or
outputs.recheck.vars.tgt_master_host != inputs.source_host or outputs.recheck.vars.src_role != 'master' or
outputs.recheck.vars.src_min_replicas == 'denied' }}
errorMessage: The target is no longer replicating from the source or the source
refuses CONFIG commands. Nothing was changed. Run PREPARE again or
give the user the CONFIG permission.
- id: freeze_values
type: io.kestra.plugin.core.output.OutputValues
values:
original: "{{ ['FREEZING', 'FROZEN'] contains outputs.current.values.state ?
outputs.read_state.value.original_min_replicas :
outputs.recheck.vars.src_min_replicas }}"
fence: "{{ ['FREEZING', 'FROZEN'] contains outputs.current.values.state ?
outputs.read_state.value.fence :
outputs.recheck.vars.src_connected_replicas + 1 }}"
pause_ms: "{{ inputs.freeze_seconds | number * 1000 }}"
- id: freezing_state
type: io.kestra.plugin.core.kv.Set
key: "redis-migration-{{ inputs.migration_name }}"
kvType: JSON
value: '{"state":"FREEZING","original_min_replicas":"{{
outputs.freeze_values.values.original }}","fence":{{
outputs.freeze_values.values.fence }}}'
- id: fence_source
type: io.kestra.plugin.redis.cli.RedisCLI
host: "{{ inputs.source_host }}"
port: "{{ inputs.source_port }}"
username: "{{ inputs.source_user }}"
password: "{{ inputs.source_password }}"
containerImage: "{{ inputs.tools_image }}"
taskRunner:
type: io.kestra.plugin.scripts.runner.docker.Docker
networkMode: "{{ inputs.docker_network }}"
entryPoint: []
commands:
- CONFIG SET min-replicas-to-write {{
outputs.freeze_values.values.fence }}
- id: fence_proof
type: io.kestra.plugin.core.flow.If
condition: "{{ outputs.current.values.state != 'FROZEN' }}"
then:
- id: fence_check
type: io.kestra.plugin.scripts.shell.Commands
containerImage: "{{ inputs.tools_image }}"
taskRunner:
type: io.kestra.plugin.scripts.runner.docker.Docker
networkMode: "{{ inputs.docker_network }}"
entryPoint: []
env:
SRC_HOST: "{{ inputs.source_host }}"
SRC_PORT: "{{ inputs.source_port }}"
SRC_USER: "{{ inputs.source_user }}"
SRC_PW: "{{ inputs.source_password }}"
EXEC: "{{ execution.id }}"
commands:
- "{{ vars.probe_source_sh }}"
- id: require_fenced
type: io.kestra.plugin.core.execution.Fail
condition: "{{ outputs.fence_check.vars.source_refused != true }}"
errorMessage: The source still accepted a write after the fence. Run ROLLBACK to
restore it and check that no proxy or Redis feature bypasses
min-replicas-to-write.
- id: hold_source_writes
type: io.kestra.plugin.redis.cli.RedisCLI
host: "{{ inputs.source_host }}"
port: "{{ inputs.source_port }}"
username: "{{ inputs.source_user }}"
password: "{{ inputs.source_password }}"
containerImage: "{{ inputs.tools_image }}"
taskRunner:
type: io.kestra.plugin.scripts.runner.docker.Docker
networkMode: "{{ inputs.docker_network }}"
entryPoint: []
commands:
- CLIENT PAUSE {{ outputs.freeze_values.values.pause_ms }} WRITE
- id: frozen_position
type: io.kestra.plugin.scripts.shell.Commands
containerImage: "{{ inputs.tools_image }}"
taskRunner:
type: io.kestra.plugin.scripts.runner.docker.Docker
networkMode: "{{ inputs.docker_network }}"
entryPoint: []
env:
SRC_HOST: "{{ inputs.source_host }}"
SRC_PORT: "{{ inputs.source_port }}"
SRC_USER: "{{ inputs.source_user }}"
SRC_PW: "{{ inputs.source_password }}"
TGT_HOST: "{{ inputs.target_host }}"
TGT_PORT: "{{ inputs.target_port }}"
TGT_USER: "{{ inputs.target_user }}"
TGT_PW: "{{ inputs.target_password }}"
commands:
- "{{ vars.inspect_sh }}"
- id: frozen_state
type: io.kestra.plugin.core.kv.Set
key: "redis-migration-{{ inputs.migration_name }}"
kvType: JSON
value: '{"state":"FROZEN","original_min_replicas":"{{
outputs.freeze_values.values.original }}","fence":{{
outputs.freeze_values.values.fence }},"freeze_offset":{{
outputs.frozen_position.vars.src_master_offset }}}'
- id: catch_up
type: io.kestra.plugin.core.flow.LoopUntil
condition: "{{ outputs.drain_status.vars.tgt_link == 'up' and
outputs.drain_status.vars.tgt_replica_offset >=
outputs.frozen_position.vars.src_master_offset }}"
checkFrequency:
interval: PT5S
maxIterations: "{{ inputs.lag_rounds }}"
failOnMaxReached: true
tasks:
- id: drain_status
type: io.kestra.plugin.scripts.shell.Commands
containerImage: "{{ inputs.tools_image }}"
taskRunner:
type: io.kestra.plugin.scripts.runner.docker.Docker
networkMode: "{{ inputs.docker_network }}"
entryPoint: []
env:
SRC_HOST: "{{ inputs.source_host }}"
SRC_PORT: "{{ inputs.source_port }}"
SRC_USER: "{{ inputs.source_user }}"
SRC_PW: "{{ inputs.source_password }}"
TGT_HOST: "{{ inputs.target_host }}"
TGT_PORT: "{{ inputs.target_port }}"
TGT_USER: "{{ inputs.target_user }}"
TGT_PW: "{{ inputs.target_password }}"
commands:
- "{{ vars.inspect_sh }}"
- id: verify
type: io.kestra.plugin.scripts.shell.Commands
containerImage: "{{ inputs.tools_image }}"
taskRunner:
type: io.kestra.plugin.scripts.runner.docker.Docker
networkMode: "{{ inputs.docker_network }}"
entryPoint: []
env:
SRC_HOST: "{{ inputs.source_host }}"
SRC_PORT: "{{ inputs.source_port }}"
SRC_USER: "{{ inputs.source_user }}"
SRC_PW: "{{ inputs.source_password }}"
TGT_HOST: "{{ inputs.target_host }}"
TGT_PORT: "{{ inputs.target_port }}"
TGT_USER: "{{ inputs.target_user }}"
TGT_PW: "{{ inputs.target_password }}"
PERCENT: "{{ inputs.verify_percent }}"
LUA: "{{ vars.digest_lua }}"
commands:
- "{{ vars.verify_sh }}"
- id: require_match
type: io.kestra.plugin.core.execution.Fail
condition: "{{ outputs.verify.vars.missing_on_target != 0 or
outputs.verify.vars.extra_on_target != 0 or
outputs.verify.vars.different != 0 }}"
errorMessage: "The target does not match the source. First differences: {{
outputs.verify.vars.examples }}. The source stays write protected.
Fix the target and run CUTOVER again or run ROLLBACK."
- id: promote_target
type: io.kestra.plugin.redis.cli.RedisCLI
host: "{{ inputs.target_host }}"
port: "{{ inputs.target_port }}"
username: "{{ inputs.target_user }}"
password: "{{ inputs.target_password }}"
containerImage: "{{ inputs.tools_image }}"
taskRunner:
type: io.kestra.plugin.scripts.runner.docker.Docker
networkMode: "{{ inputs.docker_network }}"
entryPoint: []
commands:
- REPLICAOF NO ONE
- id: promotion_check
type: io.kestra.plugin.scripts.shell.Commands
containerImage: "{{ inputs.tools_image }}"
taskRunner:
type: io.kestra.plugin.scripts.runner.docker.Docker
networkMode: "{{ inputs.docker_network }}"
entryPoint: []
env:
TGT_HOST: "{{ inputs.target_host }}"
TGT_PORT: "{{ inputs.target_port }}"
TGT_USER: "{{ inputs.target_user }}"
TGT_PW: "{{ inputs.target_password }}"
EXEC: "{{ execution.id }}"
commands:
- "{{ vars.probe_target_sh }}"
- id: require_promoted
type: io.kestra.plugin.core.execution.Fail
condition: "{{ outputs.promotion_check.vars.target_writable != true }}"
errorMessage: The target did not become a writable master after the promotion.
- id: completed_state
type: io.kestra.plugin.core.kv.Set
key: "redis-migration-{{ inputs.migration_name }}"
kvType: JSON
value: '{"state":"COMPLETED","original_min_replicas":"{{
outputs.freeze_values.values.original }}","fence":{{
outputs.freeze_values.values.fence }},"freeze_offset":{{
outputs.frozen_position.vars.src_master_offset }},"keys":{{
outputs.verify.vars.keys_source }},"dataset_hash":"{{
outputs.verify.vars.source_hash }}"}'
- id: cutover_done
type: io.kestra.plugin.core.log.Log
message: >-
Cutover recorded at replication offset {{
outputs.frozen_position.vars.src_master_offset }}: {{
outputs.verify.vars.keys_source }} keys match on the target.
Repoint the applications now. The source refuses writes.
- id: rollback_or_finalize
type: io.kestra.plugin.core.flow.If
condition: "{{ inputs.mode == 'ROLLBACK' or inputs.mode == 'FINALIZE' }}"
then:
- id: compare_completed_cutover
type: io.kestra.plugin.core.flow.If
condition: "{{ inputs.mode == 'ROLLBACK' and outputs.current.values.state ==
'COMPLETED' }}"
then:
- id: compare_before_change
type: io.kestra.plugin.scripts.shell.Commands
containerImage: "{{ inputs.tools_image }}"
taskRunner:
type: io.kestra.plugin.scripts.runner.docker.Docker
networkMode: "{{ inputs.docker_network }}"
entryPoint: []
env:
SRC_HOST: "{{ inputs.source_host }}"
SRC_PORT: "{{ inputs.source_port }}"
SRC_USER: "{{ inputs.source_user }}"
SRC_PW: "{{ inputs.source_password }}"
TGT_HOST: "{{ inputs.target_host }}"
TGT_PORT: "{{ inputs.target_port }}"
TGT_USER: "{{ inputs.target_user }}"
TGT_PW: "{{ inputs.target_password }}"
PERCENT: "{{ inputs.verify_percent }}"
LUA: "{{ vars.digest_lua }}"
commands:
- "{{ vars.verify_sh }}"
- id: approve_change
type: io.kestra.plugin.core.flow.Pause
pauseDuration: PT1H
behavior: FAIL
onResume:
- id: approved
type: BOOL
defaults: false
description: Approve ROLLBACK (undo the freeze or the cutover) or FINALIZE (end
the migration).
- id: discard_target_changes
type: BOOL
defaults: false
description: For a ROLLBACK after a completed cutover, confirm that anything
written to the target since then may be discarded.
- id: rollback
type: io.kestra.plugin.core.flow.If
condition: "{{ inputs.mode == 'ROLLBACK' and
outputs.approve_change.onResume.approved == true }}"
then:
- id: require_no_target_changes
type: io.kestra.plugin.core.execution.Fail
condition: >-
{{ outputs.current.values.state == 'COMPLETED' and
outputs.approve_change.onResume.discard_target_changes != true
and
(outputs.compare_before_change.vars.missing_on_target != 0 or outputs.compare_before_change.vars.extra_on_target != 0 or outputs.compare_before_change.vars.different != 0) }}
errorMessage: "The target changed after the cutover. Confirm
discard_target_changes to roll back. First differences: {{
outputs.compare_before_change.vars.examples }}."
- id: demote_target
type: io.kestra.plugin.core.flow.If
condition: "{{ outputs.current.values.state == 'COMPLETED' }}"
then:
- id: replicate_again
type: io.kestra.plugin.redis.cli.RedisCLI
host: "{{ inputs.target_host }}"
port: "{{ inputs.target_port }}"
username: "{{ inputs.target_user }}"
password: "{{ inputs.target_password }}"
containerImage: "{{ inputs.tools_image }}"
taskRunner:
type: io.kestra.plugin.scripts.runner.docker.Docker
networkMode: "{{ inputs.docker_network }}"
entryPoint: []
commands:
- REPLICAOF {{ inputs.source_host }} {{ inputs.source_port
}}
- id: release_source_writes
type: io.kestra.plugin.redis.cli.RedisCLI
host: "{{ inputs.source_host }}"
port: "{{ inputs.source_port }}"
username: "{{ inputs.source_user }}"
password: "{{ inputs.source_password }}"
containerImage: "{{ inputs.tools_image }}"
taskRunner:
type: io.kestra.plugin.scripts.runner.docker.Docker
networkMode: "{{ inputs.docker_network }}"
entryPoint: []
commands:
- CLIENT UNPAUSE
- id: restore_min_replicas
type: io.kestra.plugin.redis.cli.RedisCLI
host: "{{ inputs.source_host }}"
port: "{{ inputs.source_port }}"
username: "{{ inputs.source_user }}"
password: "{{ inputs.source_password }}"
containerImage: "{{ inputs.tools_image }}"
taskRunner:
type: io.kestra.plugin.scripts.runner.docker.Docker
networkMode: "{{ inputs.docker_network }}"
entryPoint: []
commands:
- CONFIG SET min-replicas-to-write {{
outputs.read_state.value.original_min_replicas }}
- id: reopen_check
type: io.kestra.plugin.scripts.shell.Commands
containerImage: "{{ inputs.tools_image }}"
taskRunner:
type: io.kestra.plugin.scripts.runner.docker.Docker
networkMode: "{{ inputs.docker_network }}"
entryPoint: []
env:
SRC_HOST: "{{ inputs.source_host }}"
SRC_PORT: "{{ inputs.source_port }}"
SRC_USER: "{{ inputs.source_user }}"
SRC_PW: "{{ inputs.source_password }}"
EXEC: "{{ execution.id }}"
commands:
- "{{ vars.probe_reopen_sh }}"
- id: require_reopened
type: io.kestra.plugin.core.execution.Fail
condition: "{{ outputs.reopen_check.vars.source_writable != true }}"
errorMessage: The source still refuses writes after the rollback.
- id: rolled_back_state
type: io.kestra.plugin.core.kv.Set
key: "redis-migration-{{ inputs.migration_name }}"
kvType: JSON
value: '{"state":"ROLLED_BACK"}'
- id: finalize
type: io.kestra.plugin.core.flow.If
condition: "{{ inputs.mode == 'FINALIZE' and
outputs.approve_change.onResume.approved == true }}"
then:
- id: clear_masterauth
type: io.kestra.plugin.redis.cli.RedisCLI
host: "{{ inputs.target_host }}"
port: "{{ inputs.target_port }}"
username: "{{ inputs.target_user }}"
password: "{{ inputs.target_password }}"
containerImage: "{{ inputs.tools_image }}"
taskRunner:
type: io.kestra.plugin.scripts.runner.docker.Docker
networkMode: "{{ inputs.docker_network }}"
entryPoint: []
commands:
- CONFIG SET masterauth ""
- id: forget_migration
type: io.kestra.plugin.core.kv.Delete
key: "redis-migration-{{ inputs.migration_name }}"
- id: finalized
type: io.kestra.plugin.core.log.Log
message: Migration finished. The old server still refuses writes. Stop it when
no client uses it.
errors:
- id: alert_migration_failure
type: io.kestra.plugin.slack.notifications.SlackIncomingWebhook
url: "{{ secret('SLACK_WEBHOOK_URL') }}"
payload: >-
{{ {'text': 'Redis migration ' ~ inputs.mode ~ ' failed. Execution ' ~
execution.id ~ '. If the source refuses writes after a failed CUTOVER, run
ROLLBACK to restore it or fix the cause and run CUTOVER again.'} | toJson
}}
triggers:
- id: scheduled_readiness
type: io.kestra.plugin.core.trigger.Schedule
disabled: true
cron: "0 * * * *"
inputs:
mode: PREPARE
dry_run: true
auto_remediate: false
A Redis move to Valkey or to a new major version usually means a downtime window or a blind copy. Replication keeps the new server current while the old one serves. The last steps are the risky ones: stopping writers, waiting for the exact catch-up point, proving that no key is missing and keeping the old server from taking writes after the switch. This flow runs those steps in order and records the result.
PREPARE checks the versions, because Valkey replicates only from Redis OSS 7.2 or older. It sets the replication login on the empty target, starts REPLICAOF and waits until the link is up.
CUTOVER asks for approval through a Pause. It sets min-replicas-to-write above the replica count so the source refuses writes with NOREPLICAS and proves that with a probe write. CLIENT PAUSE holds writes and expirations while the match is proved. The flow waits until the target reached the source offset. A read-only Lua digest then compares every key on both servers by type, value and expiry. Only then does it promote the target with REPLICAOF NO ONE and check that it takes writes.
ROLLBACK restores the source. After a completed cutover it re-attaches the target and refuses when the target changed, unless you confirm. FINALIZE ends the migration.
A target that matches the source key for key at a recorded replication offset. A source that refuses writes after the switch. A state record in the KV store for each step, so every mode can run again after a failure.
Teams that move Redis to Valkey, upgrade a Redis major version or change hosts and cannot accept a long outage.
Pause holds the approval. LoopUntil waits for the sync and the catch-up. The KV store keeps the migration state between runs. A failed step leaves a defined state with a rerun or a rollback.
Kestra 2.0.6 and 2.0.5 with Redis 7.2 to Valkey 8.1, Redis 7.2 to Redis 8.6 and Valkey 8.1 to Valkey 9. Writers ran during the sync and the cutover. A limited user whose fence failed, a target that no longer matched, a stale approval, rollback and finalize were exercised. Each result was compared with DEBUG DIGEST.
A source that is a master and an empty target on the same network. An ACL user that may run CONFIG on the source. Docker workers with the redis-cli image. The Redis, Shell scripts and Slack plugins.
REDIS_SOURCE_PASSWORD, REDIS_TARGET_PASSWORD and SLACK_WEBHOOK_URL.
mode selects PREPARE, CUTOVER, ROLLBACK or FINALIZE. dry_run defaults to true and auto_remediate to false, so nothing changes until both are flipped. freeze_seconds bounds the write hold. verify_percent samples the keys when a full read is too slow.
Add TLS flags to the redis-cli calls for a managed service. Redis Cluster, modules and stream consumer groups are outside the flow. The key comparison reads whole values, so sample very large datasets.
This blueprint was created by zkasuran.
Drain a multi-tenant Pulsar topic and route each batch by tenant priority tier, logging ENTERPRISE traffic and quarantining the rest, with a Slack report per run.
Run a parametrized Python script in Kestra that emits downloadable files, named outputs, and custom metrics.
Fan out a list of data partitions and process each one in parallel with isolated Python scripts in Docker, capturing row-count and timing metrics.
Stream Apache Pulsar messages straight into MySQL in real time, one row per event.
Compare live embeddings with stored vectors and repair an approved batch only when held-out retrieval has degraded.
Audit Qdrant vector collections for operational status degradation and HNSW indexing lag with automated Slack alerts.