fix: replication of placeholder filesystems (#744)

fixes https://github.com/zrepl/zrepl/issues/742

Before this PR, when chaining replication from
A => B => C, if B had placeholders and the `filesystems`
included these placeholders, we'd incorrectly
fail the planning phase with error
`sender does not have any versions`.

The non-placeholder child filesystems of these placeholders
would then fail to replicate because of the
initial-replication-dependency-tracking that we do, i.e.,
their parent failed to initially replication, hence
they fail to replicate as well
(`parent(s) failed during initial replication`).

We can do better than that because we have the information
whether a sender-side filesystem is a placeholder.
This PR makes the planner act on that information.
The outcome is that placeholders are replicated as
placeholders (albeit the receiver remains in control
of how these placeholders are created, i.e., `recv.placeholders`)
The mechanism to do it is:
1. Don't plan any replication steps for filesystems that
   are placeholders on the sender.
2. Ensure that, if a receiving-side filesystem exists, it
   is indeed a placeholder.

Check (2) may seem overly restrictive, but, the goal here
is not just to mirror all non-placeholder filesystems, but
also to mirror the hierarchy.

Testing performed:
- [x] confirm with issue reporter that this PR fixes their issue
- [x] add a regression test that fails without the changes in this PR
This commit is contained in:
Christian Schwarz
2024-09-05 23:26:42 +02:00
committed by GitHub
parent 440b07443f
commit 5615f4929a
5 changed files with 159 additions and 24 deletions
+1
View File
@@ -28,6 +28,7 @@ var Cases = []Case{BatchDestroy,
ReplicationIsResumableFullSend__both_GuaranteeResumability,
ReplicationIsResumableFullSend__initial_GuaranteeIncrementalReplication_incremental_GuaranteeIncrementalReplication,
ReplicationIsResumableFullSend__initial_GuaranteeResumability_incremental_GuaranteeIncrementalReplication,
ReplicationOfPlaceholderFilesystemsInChainedReplicationScenario,
ReplicationPlaceholderEncryption__EncryptOnReceiverUseCase__WorksIfConfiguredWithInherit,
ReplicationPlaceholderEncryption__UnspecifiedIsOkForClientIdentityPlaceholder,
ReplicationPlaceholderEncryption__UnspecifiedLeadsToFailureAtRuntimeWhenCreatingPlaceholders,
+97
View File
@@ -1483,3 +1483,100 @@ func ReplicationInitialFail(ctx *platformtest.Context) {
require.NotNil(ctx, report.Attempts[0].Filesystems[0].PlanError)
require.Contains(ctx, report.Attempts[0].Filesystems[0].PlanError.Err, "automatic conflict resolution for initial replication is disabled in config")
}
// https://github.com/zrepl/zrepl/issues/742
func ReplicationOfPlaceholderFilesystemsInChainedReplicationScenario(ctx *platformtest.Context) {
//
// Setup datasets
//
platformtest.Run(ctx, platformtest.PanicErr, ctx.RootDataset, `
CREATEROOT
+ "host1"
+ "host1/a"
+ "host1/a/b"
+ "host1/a/b@1"
+ "host2"
+ "host2/sink"
+ "host3"
+ "host3/sink"
`)
// Replicate host1/a to host2/sink
host1_a := ctx.RootDataset + "/host1/a"
host1_b := ctx.RootDataset + "/host1/a/b"
host2_sink := ctx.RootDataset + "/host2/sink"
host2_a := host2_sink + "/" + host1_a
host2_b := host2_sink + "/" + host1_b
host3_sink := ctx.RootDataset + "/host3/sink"
host3_a := host3_sink + "/" + host2_a
host3_b := host3_sink + "/" + host2_b
type job struct {
sender, receiver endpoint.JobID
receiver_root string
sender_filesystems_filter map[string]bool
}
h1_to_h2 := job{
sender: endpoint.MustMakeJobID("h1-to-h2-sender"),
receiver: endpoint.MustMakeJobID("h1-to-h2-receiver"),
sender_filesystems_filter: map[string]bool{
// omit host1_a so that it becomes a placeholder on host2
host1_b: true,
},
receiver_root: host2_sink,
}
h2_to_h3 := job{
sender: endpoint.MustMakeJobID("h2-to-h3-sender"),
receiver: endpoint.MustMakeJobID("h2-to-h3-receiver"),
sender_filesystems_filter: map[string]bool{
host2_sink: false,
host2_sink + "<": true,
},
receiver_root: host3_sink,
}
do_repl := func(j job) {
sfilter := filters.NewDatasetMapFilter(len(j.sender_filesystems_filter), true)
for lhs, rhs := range j.sender_filesystems_filter {
var err error
if rhs {
err = sfilter.Add(lhs, filters.MapFilterResultOk)
} else {
err = sfilter.Add(lhs, filters.MapFilterResultOmit)
}
require.NoError(ctx, err)
}
rep := replicationInvocation{
sjid: j.sender,
rjid: j.receiver,
sfilter: sfilter,
rfsRoot: j.receiver_root,
guarantee: pdu.ReplicationConfigProtectionWithKind(pdu.ReplicationGuaranteeKind_GuaranteeResumability),
receiverConfigHook: func(rc *endpoint.ReceiverConfig) {
rc.PlaceholderEncryption = endpoint.PlaceholderCreationEncryptionPropertyOff
},
}
r := rep.Do(ctx)
ctx.Logf("\n%s", pretty.Sprint(r))
}
do_repl(h1_to_h2)
do_repl(h2_to_h3)
// assert that the replication worked
mustGetFilesystemVersion(ctx, host3_b+"@1")
// assert placeholder status
for _, fs := range []string{host2_a, host3_a} {
st, err := zfs.ZFSGetFilesystemPlaceholderState(ctx, mustDatasetPath(fs))
require.NoError(ctx, err)
require.True(ctx, st.IsPlaceholder)
}
}