Skip to content

Decommission loses the current version of a versioned object once its Expiration is due, and rebalance leaves the moved versions behind #265

Closed

Description

@botdeniska

Found while decommissioning a pool of a versioned bucket with an Expiration rule.

In a versioned bucket, an Expiration that is due on the current version does not delete that version. The expiry puts a delete marker on top of it, and the version stays as a noncurrent version. Decommission and rebalance do not take that into account. They skip such a version as "ILM expired", queue the expiry, and do not copy the version to another pool. This hits every object whose expiration became due after the last scanner pass, and every matching object when a rule is added or changed shortly before a decommission.

  • Decommission counts the skipped version as moved. What happens next depends on whether the queued expiry runs before or after the check at the end of the decommission. Either the decommission completes and the version is lost when the pool is removed, or it fails with at least N object(s)/version(s) were found in bucket ... after decommissioning. A version under COMPLIANCE retention is lost the same way, because retention does not hold back the delete marker. A transitioned current version is lost too.
  • Rebalance does not count the skipped version, so it never removes the source copies of that key. The versions it has already copied stay in the source pool as duplicates, and the scanner does not remove them. The same happens for any key with a version that ILM really deletes, for example under NoncurrentVersionExpiration.

Separately, removeMovedVersions fails with PreConditionFailed on a version that the walker skipped for ILM, if the expiry queue has not deleted that version yet. It then stops before it removes the newer, already moved versions. When the expiry queue lags behind the walk, every such key stays in the pool and the decommission fails.

Expected Behavior

  • An expired current version in a versioned or suspended bucket is moved like any other noncurrent version. The scanner then puts the delete marker on it in the destination pool. After the source pool is removed, the object holds DM, v3, v2, v1.
  • A version that ILM does delete (noncurrent expiration, a lone delete marker, an object without versions) is not moved. The moved versions of the same key are removed from the source pool whether or not the queued expiry has run yet. Decommission completes on the first run.
  • After a rebalance, the source pool holds no copies of the versions it moved.

Current Behavior

  • decommissionPool and checkAfterDecom, filterLifecycle (cmd/erasure-server-pool-decom.go:811-813, :1160-1162): every evt.Action.Delete() is queued and skipped, including DeleteAction on a versioned object. The walker counts it as decommissioned (:839-843), and checkAfterDecom does not count it as left behind (:1189-1195).
  • applyExpiryOnNonTransitionedObjects (cmd/data-scanner.go:1231-1263) sends DeleteAction without a version ID, so in a versioned bucket it adds a marker. DeleteObject puts the marker into the first pool that holds the key (cmd/erasure-server-pool.go:1376-1401), which can be the pool being decommissioned. Then:
    • if checkAfterDecom runs before the marker is written, the decommission completes while v3 is still in the old pool. The marker is then written there too, and both go when the pool is removed;
    • if the marker is written first, checkAfterDecom finds it and the decommission fails. A second decommission moves both and completes.
  • removeMovedVersions (cmd/erasure-server-pool-consistency.go:133) requires a copy in another pool for every version of the walker's snapshot (:172). A version skipped for ILM has none until the expiry deletes it. The versions are processed oldest first, so for a noncurrent expiration it fails on the first one, before the moved ones.
  • rebalanceBucket, filterLifecycle (cmd/erasure-server-pool-rebalance.go:598) has the same skip. The walker does not count the skipped version (:637-640), so rebalanced == len(fivs.Versions) (:744) never holds for that key, and removeMovedVersions is not called.

On main dd905b29f, with one native server and two pools of 4 drives:

decommission, Expiration.Date, 1 key, 3 rounds:
  before:              p1[v3 v2 v1]  p2[-]
  decommission:        complete=True failed=False                                   (3 of 3)
  after decommission:  p1[DM v3]     p2[v2 v1]
  log:                 pre-conditions you specified did not hold
  p1 removed:          p2[v2 v1]     S3[v2 v1]                                      v3 is gone

decommission, NoncurrentDays=1, 200 keys, _MINIO_DECOMMISSION_WORKERS=32 MINIO_ILM_EXPIRATION_WORKERS=1:
  decommission:        complete=False failed=True
  after decommission:  199 key(s) p1[v3 v2] p2[v3 v2]
  log:                 199 x pre-conditions you specified did not hold
                       at least 398 object(s)/version(s) were found in bucket `bkt` after decommissioning
  second decommission: complete=True, 200 key(s) p2[v3 v2]

rebalance, Expiration.Date:   p1[DM v3 v2 v1]  p2[v2 v1]
rebalance, NoncurrentDays=1:  p1[v3 v2]        p2[v3 v2]
  unchanged after a scanner pass over both pools; a second rebalance removes the duplicates

The first case is a race. Over 9 single-key runs, 7 lost v3 as above. In the other 2, the first decommission failed and a second one completed without loss. With 5 keys the first decommission usually failed. With default worker settings the expiry queue usually wins the race in the second case, and the decommission completes.

Possible Solution

  1. In the filterLifecycle of decommissionPool, checkAfterDecom and rebalanceBucket, treat DeleteAction on a versioned object (enabled or suspended) as no action. The version is moved like any other, and the scanner applies the expiry once the version lives in another pool.
  2. Rebalance counts a version skipped for ILM as handled, as decommission already does, so the source copies of the moved versions are removed.
  3. Pass the skipped versions to removeMovedVersions, which removes them from the source without requiring a moved copy, as the queued expiry would. Leaving them to the expiry does not work: once the newer versions are gone from the source pool, a skipped noncurrent version is the latest one there. The expiry re-evaluates the rule against that pool (cmd/erasure-object.go:2154), finds no action, and the version stays, so the decommission fails again.
  4. Exception: a version whose action deletes the whole object (ExpiredObjectAllVersions, DelMarkerExpiration) is the current version. Removing it from the source before the expiry runs would expose the moved older versions. It stays in the source until the queued expiry deletes the object in every pool, as on main.

I have a patch with tests and will open a PR.

Steps to Reproduce (for bugs)

The script repro.sh <work-dir> <silo-binary> [case ...] is attached. It needs mc, curl and xl-meta (go build -o xl-meta ./docs/debugging/xl-meta). It runs one native server with two pools of 4 directories:

  1. Start with p1 only, create the versioned bucket bkt, write v1, v2 and v3 of each key. For the noncurrent cases, v1 and v2 are back-dated by 5 and 4 days (X-Minio-Source-Mtime).
  2. Restart with p1 and p2, and set the rule right before the data movement, so the scanner cannot apply it first:
    • Expiration.Date two days ago, or
    • NoncurrentVersionExpiration.NoncurrentDays=1.
  3. mc admin decommission start p1 (decom-date, decom-noncurrent), or mc admin rebalance start (rebalance-date, rebalance-noncurrent).
  4. Read xl.meta of each pool. After a completed decommission, restart with p2 only and list the versions through S3.

Rebalance only moves data off a pool that is fuller than the others. The rebalance cases therefore need p1 and p2 on two filesystems of different size (P1ROOT, P2ROOT; the script header shows RAM disks on macOS), and a 200 MiB file on the p1 filesystem keeps p1 below the goal for the whole walk.

The manual equivalent of the first case:

silo server "$D/p1/d{1...4}" &                     # write v1 v2 v3 of bkt/obj-001, stop
silo server "$D/p1/d{1...4}" "$D/p2/d{1...4}" &
mc ilm import t/bkt <<'EOF'
{"Rules":[{"ID":"expire","Status":"Enabled","Filter":{"Prefix":"obj-"},"Expiration":{"Date":"2026-10-27T00:00:00Z"}}]}
EOF
mc admin decommission start t/ "$D/p1/d{1...4}"
mc admin decommission status t/ "$D/p1/d{1...4}"
silo server "$D/p2/d{1...4}" &                     # after Complete
mc ls --versions t/bkt/obj-001
repro.sh
#!/usr/bin/env bash
# Repro for the SILO issue: decommission and rebalance skip the current version that ILM expires in a
# versioned bucket (Expiration only puts a delete marker on top of it, the version stays noncurrent),
# and leave the source copies of moved versions behind when ILM deletes another version of the key.
#
# One native server per round, MINIO_CI_CD=1, no Docker. The data is written with pool p1 only, then the
# server restarts with p1 and p2. The ILM rule is set right before the decommission or rebalance of p1,
# so the scanner cannot apply it first. The result is read from the xl.meta of the first drive of each
# pool, and through S3 once p1 is removed.
#
# Usage: repro.sh <work-dir> <silo-binary> [case ...]
#   decom-date        ROUNDS (3) rounds, one key with v1 v2 v3, Expiration.Date in the past. A completed
#                     decommission is followed by a restart with p2 only. Expected: v3 v2 v1 in p2, and
#                     DM v3 v2 v1 once the scanner (or a listing) applies the rule there.
#   decom-noncurrent  200 keys, v1 and v2 back-dated by 5 and 4 days, v3 now, NoncurrentDays=1 (v1
#                     expires), _MINIO_DECOMMISSION_WORKERS=32 MINIO_ILM_EXPIRATION_WORKERS=1, so the
#                     expiry queue lags behind the walk. Expected: complete, v3 v2 in p2.
#   rebalance-date, rebalance-noncurrent  5 keys, the same data and rules, rebalance instead of
#                     decommission. Expected: p1 empty, the same versions in p2.
#   Default: both decom cases, and the rebalance cases when P1ROOT and P2ROOT are set.
# Needs curl (with --aws-sigv4), python3, mc and xl-meta (go build -o xl-meta ./docs/debugging/xl-meta).
# Env: MC=mc XLMETA=xl-meta PORT=9340 (PORT+1 is the console) ROUNDS=3
#   P1ROOT, P2ROOT: rebalance only moves data off a pool that is fuller than the others, so p1 and p2
#   must be on two filesystems of different size. A 200 MiB file on the p1 filesystem keeps p1 below the
#   goal for the whole walk. On macOS, for example:
#     diskutil erasevolume HFS+ rp1 $(hdiutil attach -nomount ram://655360)    # 320 MiB
#     diskutil erasevolume HFS+ rp2 $(hdiutil attach -nomount ram://2097152)   # 1 GiB
#     P1ROOT=/Volumes/rp1 P2ROOT=/Volumes/rp2 repro.sh ...
# Each round keeps its server log in <work-dir>/<case>-<round>/; the drives are removed at the end.
set -u

WORK=${1:?usage: repro.sh <work-dir> <silo-binary> [case ...]}
BIN=${2:?usage: repro.sh <work-dir> <silo-binary> [case ...]}
shift 2
CASES=${*:-"decom-date decom-noncurrent${P1ROOT:+ rebalance-date rebalance-noncurrent}"}
MC=${MC:-mc}
XLMETA=${XLMETA:-xl-meta}
PORT=${PORT:-9340}
ROUNDS=${ROUNDS:-3}
mkdir -p "$WORK"
WORK=$(cd "$WORK" && pwd)
export MINIO_ROOT_USER=minioadmin MINIO_ROOT_PASSWORD=minioadmin MINIO_CI_CD=1
export MC_CONFIG_DIR="$WORK/.mc" MC_HOST_t="http://minioadmin:[email protected]:$PORT"
EP="http://127.0.0.1:$PORT"
PID=""
BALLAST=""

stop() {
	[ -n "$PID" ] || return 0
	kill "$PID" 2>/dev/null
	wait "$PID" 2>/dev/null
	PID=""
}
cleanup() {
	stop
	[ -z "$BALLAST" ] || rm -f "$BALLAST"
}
trap cleanup EXIT
trap 'cleanup; exit 130' INT TERM

start() { # <pool>...: server env comes from SRV_ENV
	env ${SRV_ENV:-} "$BIN" server --address "127.0.0.1:$PORT" --console-address "127.0.0.1:$((PORT + 1))" "$@" >>"$CD/server.log" 2>&1 &
	PID=$!
	for _ in $(seq 1 150); do
		curl -sf -o /dev/null "$EP/minio/health/cluster" && return 0
		kill -0 "$PID" 2>/dev/null || break
		sleep 0.2
	done
	echo "server did not start, see $CD/server.log"
	exit 1
}

days_ago() { # <days> [midnight]
	python3 -I -c 'import sys,datetime as d
t = d.datetime.now(d.timezone.utc) - d.timedelta(days=int(sys.argv[1]))
print(t.strftime("%Y-%m-%dT00:00:00Z" if len(sys.argv) > 2 else "%Y-%m-%dT%H:%M:%S.%fZ"))' "$@"
}

put() { # <key> <label> [mtime]: one PUT, records "<versionId> <label>"
	local hdr=() vid
	[ -z "${3:-}" ] || hdr=(-H "X-Minio-Source-Replication-Request: true" -H "X-Minio-Source-Mtime: $3")
	vid=$(curl -sS --aws-sigv4 "aws:amz:us-east-1:s3" --user minioadmin:minioadmin -o /dev/null -D - -X PUT \
		${hdr[@]+"${hdr[@]}"} --data-binary "$1 $2" "$EP/bkt/$1" | tr -d '\r' | awk -F': ' 'tolower($1)=="x-amz-version-id"{print $2}')
	[ -n "$vid" ] || { echo "PUT bkt/$1 ($2) failed"; exit 1; }
	echo "$vid $2" >>"$CD/labels"
}

# view <tag> <name>=<pool dir>...: versions per key and pool from xl.meta, keys with the same layout counted together.
view() {
	local tag=$1
	shift
	echo "   $tag:"
	python3 -I - "$XLMETA" "$CD/labels" "$@" <<'PY'
import collections, json, os, subprocess, sys
xlmeta, labels_f, pools = sys.argv[1], sys.argv[2], [a.split("=", 1) for a in sys.argv[3:]]
labels = {}
for line in open(labels_f):
    vid, label = line.split()
    labels[vid.replace("-", "").lower()] = label
keys = set()
for _, d in pools:
    b = os.path.join(d, "d1", "bkt")
    if os.path.isdir(b):
        keys.update(os.listdir(b))
rows = collections.Counter()
for k in sorted(keys):
    cols = []
    for name, d in pools:
        f = os.path.join(d, "d1", "bkt", k, "xl.meta")
        vs = []
        if os.path.exists(f):
            for v in json.loads(subprocess.run([xlmeta, f], capture_output=True, text=True).stdout).get("Versions", []):
                h = v["Header"]
                vs.append("DM" if h["Type"] == 2 else labels.get(h["VersionID"].replace("-", "").lower(), "?"))
        cols.append(f"{name}[{' '.join(vs) or '-'}]")
    rows["  ".join(cols)] += 1
for row, n in rows.items():
    print(f"     {n:>3} key(s)  {row}")
if not rows:
    print("       no keys")
PY
}

s3view() { # versions per key as listed through S3, newest first
	"$MC" ls --versions --json t/bkt/ | python3 -I -c '
import collections, json, sys
labels = {}
for line in open(sys.argv[1]):
    vid, label = line.split()
    labels[vid] = label
keys = collections.defaultdict(list)
for line in sys.stdin:
    j = json.loads(line)
    if j.get("status") == "success":
        keys[j["key"]].append("DM" if j.get("isDeleteMarker") else labels.get(j.get("versionId"), "?"))
rows = collections.Counter(" ".join(v) for v in keys.values())
for row, n in rows.items():
    print(f"     {n:>3} key(s)  S3[{row}]")
' "$CD/labels"
}

decom_wait() { # prints the final status, returns 0 when complete
	local st=""
	for _ in $(seq 1 300); do
		st=$("$MC" admin decommission status --json t/ "$P1" 2>&1)
		echo "$st" | grep -q '"complete":true\|"failed":true\|"canceled":true' && break
		sleep 1
	done
	echo "$st" | python3 -I -c 'import json,sys
i = json.load(sys.stdin).get("decommissionInfo", {})
print("   decommission: complete=%s failed=%s" % (i.get("complete"), i.get("failed")))'
	echo "$st" | grep -q '"complete":true'
}

rebalance_wait() {
	for _ in $(seq 1 300); do
		"$MC" admin rebalance status --json t/ 2>&1 | grep -q '"status":"Started"' || break
		sleep 1
	done
	"$MC" admin rebalance status --json t/ 2>&1 | python3 -I -c 'import json,sys
for p in json.load(sys.stdin).get("pools", []):
    print("   rebalance: pool %s status=%s" % (p.get("id"), p.get("status")))'
}

errors() { # server log errors of the data movement
	grep -hoE 'pre-conditions you specified did not hold|at least [0-9]+ object\(s\)/version\(s\) were found[^(]*' "$CD/server.log" |
		sort | uniq -c | sed 's/^/   log: /'
}

run_round() { # <case> <round>
	local c=$1 kind=${1%%-*} rule=${1#*-} nkeys=5 i t5 t4
	CD="$WORK/$c-$2"
	rm -rf "$CD"
	mkdir -p "$CD"
	: >"$CD/labels"
	SRV_ENV=""
	[ "$c" = decom-date ] && nkeys=1
	if [ "$c" = decom-noncurrent ]; then
		nkeys=200
		SRV_ENV="_MINIO_DECOMMISSION_WORKERS=32 MINIO_ILM_EXPIRATION_WORKERS=1"
	fi
	if [ "$kind" = rebalance ]; then
		R1="${P1ROOT:?set P1ROOT and P2ROOT for the rebalance cases}/$c-$2" R2="${P2ROOT:?}/$c-$2"
		BALLAST="$P1ROOT/ballast"
		rm -f "$BALLAST"
	else
		R1="$CD/p1" R2="$CD/p2"
	fi
	rm -rf "$R1" "$R2"
	P1="$R1/d{1...4}" P2="$R2/d{1...4}"
	echo "-- $c, round $2: $nkeys key(s)${SRV_ENV:+, $SRV_ENV}"

	start "$P1"
	"$MC" mb -q t/bkt >/dev/null && "$MC" version enable t/bkt >/dev/null || exit 1
	t5=$(days_ago 5) t4=$(days_ago 4)
	for i in $(seq -f '%03g' 1 "$nkeys"); do
		if [ "$rule" = noncurrent ]; then
			put "obj-$i" v1 "$t5"
			put "obj-$i" v2 "$t4"
		else
			put "obj-$i" v1
			put "obj-$i" v2
		fi
		put "obj-$i" v3
	done
	stop

	[ "$kind" = rebalance ] && dd if=/dev/zero of="$BALLAST" bs=1048576 count=200 2>/dev/null
	start "$P1" "$P2"
	if [ "$rule" = date ]; then
		echo "{\"Rules\":[{\"ID\":\"expire\",\"Status\":\"Enabled\",\"Filter\":{\"Prefix\":\"obj-\"},\"Expiration\":{\"Date\":\"$(days_ago 2 midnight)\"}}]}"
	else
		echo '{"Rules":[{"ID":"noncurrent","Status":"Enabled","Filter":{"Prefix":"obj-"},"NoncurrentVersionExpiration":{"NoncurrentDays":1}}]}'
	fi >"$CD/lifecycle.json"
	"$MC" ilm import t/bkt <"$CD/lifecycle.json" >/dev/null || exit 1
	view "before" p1="$R1" p2="$R2"

	if [ "$kind" = rebalance ]; then
		"$MC" admin rebalance start t/ >/dev/null || exit 1
		sleep 1
		rebalance_wait
		sleep 5 # the expiry queue drains
		view "after rebalance" p1="$R1" p2="$R2"
		errors
		stop
		rm -f "$BALLAST"
		rm -rf "$R1" "$R2"
		return
	fi

	"$MC" admin decommission start t/ "$P1" >/dev/null || exit 1
	local ok=0
	decom_wait && ok=1
	sleep 5 # the expiry queue drains
	view "after decommission" p1="$R1" p2="$R2"
	errors
	if [ "$ok" = 0 ]; then
		echo "   decommission failed, starting it again"
		"$MC" admin decommission start t/ "$P1" >/dev/null
		decom_wait && ok=1
		sleep 5
		view "after the second decommission" p1="$R1" p2="$R2"
	fi
	stop
	if [ "$ok" = 1 ]; then
		start "$P2"
		view "p1 removed, server restarted with p2 only" p2="$R2"
		s3view
		stop
	fi
	rm -rf "$R1" "$R2"
}

"$BIN" --version | head -1
for c in $CASES; do
	rounds=1
	[ "$c" = decom-date ] && rounds=$ROUNDS
	for r in $(seq 1 "$rounds"); do
		run_round "$c" "$r"
	done
done
rm -rf "$WORK/.mc"

Context

A versioned bucket with an Expiration rule is a common setup: objects get a delete marker after N days and the noncurrent versions are removed later. The scanner applies the rule in cycles. Every object that became due since the last pass is exposed during a decommission. All matching objects are exposed when the rule is added or changed shortly before one. The lost version is the one the rule meant to keep as noncurrent, including versions under object lock retention. The operator sees Complete.

Regression

No. The skip comes from upstream MinIO. Upstream then removes the key from the source pool with a prefix delete, so there the skipped version is removed whenever the walker skips it. removeMovedVersions makes it depend on timing.

Your Environment

  • Version used (silo --version): main at dd905b29f, built from source
  • Server setup and configuration: one node, two pools of 4 local directories, MINIO_CI_CD=1; the rebalance cases on two RAM disks of 320 MiB and 1 GiB
  • Operating System and version (uname -a): macOS (Darwin 27.0.0, arm64); mc RELEASE.2025-07-21T05-28-08Z

Activity

  1. moved this from Backlog to In progress in Siloon Oct 31, 2026
  2. moved this from In progress to Done in Siloon Nov 2, 2026
  3. Vonng commented on Nov 9, 2026

    @Vonng
    Member

    Post-20261026 resolution record.

    Implemented: 19910230a, a995921e5, 0a546c7a7, 1bd0b1b04.

    Decommission and rebalance move a due current version when lifecycle only creates a marker, and remove moved source copies after checking the destination. The follow-up preserves cleanup ownership, rechecks lifecycle changes and verifies physical completion. Its accidental scheduling of ILM deletes for replication was subsequently removed; API delete replication is preserved. Additional progress and cancellation repairs are in #307.

    Verification: TestPoolsDecommissionLifecycleExpiry, TestPoolsRebalanceLifecycleExpiry, TestPoolsMigrationLifecycleChangePreservesSource, TestPoolsMigrationLifecycleExpiryNotReplicated passed in the preserved 2026-11-08 validation at bb31c2618. This audit checked the pass records, log hashes and recorded exit codes.

    Result: The covered migration no longer loses the expired current version or leaves successfully moved versions behind. The final behavior does not opt lifecycle deletions into replication.

    These changes are in public main. They are not part of the latest published server release, RELEASE.2026-10-26T00-00-00Z.

  4. added theissue type on Nov 9, 2026
  5. added this to the 20261109 milestone on Nov 9, 2026
  6. added
    bug
    on Nov 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    Projects

    • Status
      Done

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions