After `zpool import -T`, a later import can pick up the discarded timeline
System information
| Distribution | FreeBSD 15.1-RELEASE (KVM guest) |
| Architecture | x86_64 |
| ZFS Version | master 5db13c747, built from source |
Describe the problem you're observing
After a successful zpool import -T <txg>, new txgs are numbered from
<txg> + 1. The uberblocks of the timeline that was rewound past are still in
the label ring, with higher txg numbers. If the pool is exported before its new
timeline has overtaken them, the next plain zpool import selects the highest
one, i.e. the discarded timeline. Changes made after the rewind silently
disappear, or, if the new timeline has already reused that timeline's blocks,
the import fails with an I/O error and suggests -F.
As far as I can see, the cause is in spa_load_best(): when the first
spa_load() of the requested txg succeeds, it returns before
spa_last_ubsync_txg is set, so spa_ld_select_uberblock_done() sets
spa_first_txg = spa_last_synced_txg(spa) + 1. On the rewind path that runs
after a failed load, spa_last_ubsync_txg is the txg of the newest uberblock,
and new txgs start above it. The early return predates #18967.
Describe how to reproduce the problem
#!/bin/sh
set -e
D=/var/tmp/stale-ub; P=staleub
rm -rf $D; mkdir -p $D; truncate -s 256m $D/d0
zpool create $P $D/d0
zpool sync $P
T=$(zdb -u $P | awk '$1 == "txg" { print $3 }')
for i in 1 2 3; do # the timeline to discard
zfs set user:mark=discarded$i $P
zpool sync $P
done
zpool export $P
zpool import -d $D -T $T $P # mark is '-' here, as expected
touch /$P/written-after-rewind
zpool sync $P
zpool export $P
zpool import -d $D $P
zfs get -H -o value user:mark $P # prints discarded3
ls /$P/written-after-rewind # No such file or directoryFive runs: three brought back user:mark=discarded3 and lost the new file.
One failed the final import with cannot import 'staleub': I/O error. In one,
the -T import itself failed. zdb -lu shows why: after the rewind and export,
the highest uberblock on disk is still txg 32 from the discarded timeline.
Is starting new txgs above the newest uberblock on disk after a -T import the
intended behaviour, i.e. is this a bug? If it is, I'm happy to look at a fix.
I ran into this while working on #19077: the test there imports an explicit txg and then exports and re-imports the pool.
Source: openzfs/zfs