Skip to content
Permalink
Browse files

fix bookmark edge case where replication was already done to the late…

…st snapshot (+ test)
  • Loading branch information...
phreaker0 committed Jan 30, 2019
1 parent 9ec0c0b commit 7141eab594ff8a362f2e4f3a8565eab699ce1f7e
Showing with 51 additions and 0 deletions.
  1. +5 −0 syncoid
  2. +46 −0 tests/syncoid/4_bookmark_replication_edge_case/run.sh
@@ -654,6 +654,11 @@ sub syncdataset {
# do a normal replication if bookmarks aren't used or if previous
# bookmark replication was only done to the next oldest snapshot
if (!$bookmark || $nextsnapshot) {
if ($matchingsnap eq $newsyncsnap) {
# edge case: bookmark replication used the latest snapshot
return 0;
}

my $sendcmd = "$sourcesudocmd $zfscmd send $sendoptions $args{'streamarg'} $sourcefsescaped\@$matchingsnapescaped $sourcefsescaped\@$newsyncsnapescaped";
my $recvcmd = "$targetsudocmd $zfscmd receive $recvoptions $receiveextraargs $forcedrecv $targetfsescaped";
my $pvsize = getsendsize($sourcehost,"$sourcefs\@$matchingsnap","$sourcefs\@$newsyncsnap",$sourceisroot);
@@ -0,0 +1,46 @@
#!/bin/bash

# test replication edge cases with bookmarks

set -x
set -e

. ../../common/lib.sh

POOL_IMAGE="/tmp/syncoid-test-4.zpool"
POOL_SIZE="200M"
POOL_NAME="syncoid-test-4"
TARGET_CHECKSUM="ad383b157b01635ddcf13612ac55577ad9c8dcf3fbfc9eb91792e27ec8db739b -"

truncate -s "${POOL_SIZE}" "${POOL_IMAGE}"

zpool create -m none -f "${POOL_NAME}" "${POOL_IMAGE}"

function cleanUp {
zpool export "${POOL_NAME}"
}

# export pool in any case
trap cleanUp EXIT

zfs create "${POOL_NAME}"/src
zfs snapshot "${POOL_NAME}"/src@snap1
zfs bookmark "${POOL_NAME}"/src@snap1 "${POOL_NAME}"/src#snap1
# initial replication
../../../syncoid --no-sync-snap --debug --compress=none "${POOL_NAME}"/src "${POOL_NAME}"/dst
# destroy last common snapshot on source
zfs destroy "${POOL_NAME}"/src@snap1
zfs snapshot "${POOL_NAME}"/src@snap2

# replicate which should fallback to bookmarks and stop because it's already on the latest snapshot
../../../syncoid --no-sync-snap --debug --compress=none "${POOL_NAME}"/src "${POOL_NAME}"/dst || exit 1

# verify
output=$(zfs list -t snapshot -r -H -o name "${POOL_NAME}")
checksum=$(echo "${output}" | grep -v syncoid_ | shasum -a 256)

if [ "${checksum}" != "${TARGET_CHECKSUM}" ]; then
exit 1
fi

exit 0

0 comments on commit 7141eab

Please sign in to comment.
You can’t perform that action at this time.