Skip to content

Commit

Permalink
zfs.NilBool: document its purpose and move it to its own package 'nod…
Browse files Browse the repository at this point in the history
…efault'
  • Loading branch information
problame committed Feb 20, 2021
1 parent 70bbdfe commit 1c937e5
Show file tree
Hide file tree
Showing 13 changed files with 104 additions and 59 deletions.
3 changes: 2 additions & 1 deletion daemon/job/build_jobs_sendrecvoptions.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"github.com/zrepl/zrepl/config"
"github.com/zrepl/zrepl/daemon/filters"
"github.com/zrepl/zrepl/endpoint"
"github.com/zrepl/zrepl/util/nodefault"
"github.com/zrepl/zrepl/zfs"
)

Expand All @@ -23,7 +24,7 @@ func buildSenderConfig(in SendingJobConfig, jobID endpoint.JobID) (*endpoint.Sen

return &endpoint.SenderConfig{
FSF: fsf,
Encrypt: &zfs.NilBool{B: in.GetSendOptions().Encrypted},
Encrypt: &nodefault.Bool{B: in.GetSendOptions().Encrypted},
JobID: jobID,
}, nil
}
Expand Down
3 changes: 2 additions & 1 deletion daemon/job/snapjob.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"github.com/prometheus/client_golang/prometheus"

"github.com/zrepl/zrepl/daemon/logging/trace"
"github.com/zrepl/zrepl/util/nodefault"

"github.com/zrepl/zrepl/config"
"github.com/zrepl/zrepl/daemon/filters"
Expand Down Expand Up @@ -179,7 +180,7 @@ func (j *SnapJob) doPrune(ctx context.Context) {
JobID: j.name,
FSF: j.fsfilter,
// FIXME encryption setting is irrelevant for SnapJob because the endpoint is only used as pruner.Target
Encrypt: &zfs.NilBool{B: true},
Encrypt: &nodefault.Bool{B: true},
})
j.prunerMtx.Lock()
j.pruner = j.prunerFactory.BuildLocalPruner(ctx, sender, alwaysUpToDateReplicationCursorHistory{sender})
Expand Down
7 changes: 4 additions & 3 deletions endpoint/endpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,20 @@ import (
"github.com/zrepl/zrepl/util/chainedio"
"github.com/zrepl/zrepl/util/chainlock"
"github.com/zrepl/zrepl/util/envconst"
"github.com/zrepl/zrepl/util/nodefault"
"github.com/zrepl/zrepl/util/semaphore"
"github.com/zrepl/zrepl/zfs"
)

type SenderConfig struct {
FSF zfs.DatasetFilter
Encrypt *zfs.NilBool
Encrypt *nodefault.Bool
JobID JobID
}

func (c *SenderConfig) Validate() error {
c.JobID.MustValidate()
if err := c.Encrypt.Validate(); err != nil {
if err := c.Encrypt.ValidateNoDefault(); err != nil {
return errors.Wrap(err, "`Encrypt` field invalid")
}
if _, err := StepHoldTag(c.JobID); err != nil {
Expand All @@ -43,7 +44,7 @@ type Sender struct {
pdu.UnsafeReplicationServer // prefer compilation errors over default 'method X not implemented' impl

FSFilter zfs.DatasetFilter
encrypt *zfs.NilBool
encrypt *nodefault.Bool
jobId JobID
}

Expand Down
13 changes: 7 additions & 6 deletions endpoint/endpoint_zfs_abstraction.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (

"github.com/zrepl/zrepl/daemon/logging/trace"
"github.com/zrepl/zrepl/util/envconst"
"github.com/zrepl/zrepl/util/nodefault"
"github.com/zrepl/zrepl/util/semaphore"
"github.com/zrepl/zrepl/zfs"
)
Expand Down Expand Up @@ -257,7 +258,7 @@ type ListZFSHoldsAndBookmarksQuery struct {

type CreateTXGRangeBound struct {
CreateTXG uint64
Inclusive *zfs.NilBool // must not be nil
Inclusive *nodefault.Bool // must not be nil
}

// A non-empty range of CreateTXGs
Expand Down Expand Up @@ -300,7 +301,7 @@ func (q *ListZFSHoldsAndBookmarksQuery) Validate() error {
var createTXGRangeBoundAllowCreateTXG0 = envconst.Bool("ZREPL_ENDPOINT_LIST_ABSTRACTIONS_QUERY_CREATETXG_RANGE_BOUND_ALLOW_0", false)

func (i *CreateTXGRangeBound) Validate() error {
if err := i.Inclusive.Validate(); err != nil {
if err := i.Inclusive.ValidateNoDefault(); err != nil {
return errors.Wrap(err, "Inclusive")
}
if i.CreateTXG == 0 && !createTXGRangeBoundAllowCreateTXG0 {
Expand Down Expand Up @@ -419,7 +420,7 @@ func (r *CreateTXGRange) String() string {
if r.Since == nil {
fmt.Fprintf(&buf, "~")
} else {
if err := r.Since.Inclusive.Validate(); err != nil {
if err := r.Since.Inclusive.ValidateNoDefault(); err != nil {
fmt.Fprintf(&buf, "?")
} else if r.Since.Inclusive.B {
fmt.Fprintf(&buf, "[")
Expand All @@ -435,7 +436,7 @@ func (r *CreateTXGRange) String() string {
fmt.Fprintf(&buf, "~")
} else {
fmt.Fprintf(&buf, "%d", r.Until.CreateTXG)
if err := r.Until.Inclusive.Validate(); err != nil {
if err := r.Until.Inclusive.ValidateNoDefault(); err != nil {
fmt.Fprintf(&buf, "?")
} else if r.Until.Inclusive.B {
fmt.Fprintf(&buf, "]")
Expand Down Expand Up @@ -829,14 +830,14 @@ func listStaleFiltering(abs []Abstraction, sinceBound *CreateTXGRangeBound) *Sta
untilBound = &CreateTXGRangeBound{
CreateTXG: (*sfnsc.cursor).GetCreateTXG(),
// if we have a cursor, can throw away step hold on both From and To
Inclusive: &zfs.NilBool{B: true},
Inclusive: &nodefault.Bool{B: true},
}
} else if sfnsc.step != nil {
untilBound = &CreateTXGRangeBound{
CreateTXG: (*sfnsc.step).GetCreateTXG(),
// if we don't have a cursor, the step most recent step hold is our
// initial replication cursor and it's possibly still live (interrupted initial replication)
Inclusive: &zfs.NilBool{B: false},
Inclusive: &nodefault.Bool{B: false},
}
} else {
untilBound = nil // consider everything stale
Expand Down
36 changes: 18 additions & 18 deletions endpoint/endpoint_zfs_abstraction_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

"github.com/zrepl/zrepl/zfs"
"github.com/zrepl/zrepl/util/nodefault"
)

func TestCreateTXGRange(t *testing.T) {
Expand Down Expand Up @@ -47,35 +47,35 @@ func TestCreateTXGRange(t *testing.T) {
name: "wrong order obvious",
expectInvalid: true,
config: &CreateTXGRange{
Since: &CreateTXGRangeBound{23, &zfs.NilBool{B: true}},
Until: &CreateTXGRangeBound{20, &zfs.NilBool{B: true}},
Since: &CreateTXGRangeBound{23, &nodefault.Bool{B: true}},
Until: &CreateTXGRangeBound{20, &nodefault.Bool{B: true}},
},
expectString: "[23,20]",
},
{
name: "wrong order edge-case could also be empty",
expectInvalid: true,
config: &CreateTXGRange{
Since: &CreateTXGRangeBound{23, &zfs.NilBool{B: false}},
Until: &CreateTXGRangeBound{22, &zfs.NilBool{B: true}},
Since: &CreateTXGRangeBound{23, &nodefault.Bool{B: false}},
Until: &CreateTXGRangeBound{22, &nodefault.Bool{B: true}},
},
expectString: "(23,22]",
},
{
name: "empty",
expectInvalid: true,
config: &CreateTXGRange{
Since: &CreateTXGRangeBound{2, &zfs.NilBool{B: false}},
Until: &CreateTXGRangeBound{2, &zfs.NilBool{B: false}},
Since: &CreateTXGRangeBound{2, &nodefault.Bool{B: false}},
Until: &CreateTXGRangeBound{2, &nodefault.Bool{B: false}},
},
expectString: "(2,2)",
},
{
name: "inclusive-since-exclusive-until",
expectInvalid: false,
config: &CreateTXGRange{
Since: &CreateTXGRangeBound{2, &zfs.NilBool{B: true}},
Until: &CreateTXGRangeBound{5, &zfs.NilBool{B: false}},
Since: &CreateTXGRangeBound{2, &nodefault.Bool{B: true}},
Until: &CreateTXGRangeBound{5, &nodefault.Bool{B: false}},
},
expectString: "[2,5)",
expect: []testCaseExpectation{
Expand All @@ -92,8 +92,8 @@ func TestCreateTXGRange(t *testing.T) {
name: "exclusive-since-inclusive-until",
expectInvalid: false,
config: &CreateTXGRange{
Since: &CreateTXGRangeBound{2, &zfs.NilBool{B: false}},
Until: &CreateTXGRangeBound{5, &zfs.NilBool{B: true}},
Since: &CreateTXGRangeBound{2, &nodefault.Bool{B: false}},
Until: &CreateTXGRangeBound{5, &nodefault.Bool{B: true}},
},
expectString: "(2,5]",
expect: []testCaseExpectation{
Expand All @@ -111,15 +111,15 @@ func TestCreateTXGRange(t *testing.T) {
expectInvalid: true,
config: &CreateTXGRange{
Since: nil,
Until: &CreateTXGRangeBound{0, &zfs.NilBool{B: true}},
Until: &CreateTXGRangeBound{0, &nodefault.Bool{B: true}},
},
expectString: "~,0]",
},
{
name: "half-open-no-until",
expectInvalid: false,
config: &CreateTXGRange{
Since: &CreateTXGRangeBound{2, &zfs.NilBool{B: false}},
Since: &CreateTXGRangeBound{2, &nodefault.Bool{B: false}},
Until: nil,
},
expectString: "(2,~",
Expand All @@ -138,7 +138,7 @@ func TestCreateTXGRange(t *testing.T) {
expectInvalid: false,
config: &CreateTXGRange{
Since: nil,
Until: &CreateTXGRangeBound{4, &zfs.NilBool{B: true}},
Until: &CreateTXGRangeBound{4, &nodefault.Bool{B: true}},
},
expectString: "~,4]",
expect: []testCaseExpectation{
Expand All @@ -154,7 +154,7 @@ func TestCreateTXGRange(t *testing.T) {
name: "edgeSince",
expectInvalid: false,
config: &CreateTXGRange{
Since: &CreateTXGRangeBound{math.MaxUint64, &zfs.NilBool{B: true}},
Since: &CreateTXGRangeBound{math.MaxUint64, &nodefault.Bool{B: true}},
Until: nil,
},
expectString: "[18446744073709551615,~",
Expand All @@ -169,7 +169,7 @@ func TestCreateTXGRange(t *testing.T) {
name: "edgeSinceNegative",
expectInvalid: true,
config: &CreateTXGRange{
Since: &CreateTXGRangeBound{math.MaxUint64, &zfs.NilBool{B: false}},
Since: &CreateTXGRangeBound{math.MaxUint64, &nodefault.Bool{B: false}},
Until: nil,
},
expectString: "(18446744073709551615,~",
Expand All @@ -178,7 +178,7 @@ func TestCreateTXGRange(t *testing.T) {
name: "edgeUntil",
expectInvalid: false,
config: &CreateTXGRange{
Until: &CreateTXGRangeBound{0, &zfs.NilBool{B: true}},
Until: &CreateTXGRangeBound{0, &nodefault.Bool{B: true}},
},
configAllowZeroCreateTXG: true,
expectString: "~,0]",
Expand All @@ -193,7 +193,7 @@ func TestCreateTXGRange(t *testing.T) {
expectInvalid: true,
configAllowZeroCreateTXG: true,
config: &CreateTXGRange{
Until: &CreateTXGRangeBound{0, &zfs.NilBool{B: false}},
Until: &CreateTXGRangeBound{0, &nodefault.Bool{B: false}},
},
expectString: "~,0)",
},
Expand Down
3 changes: 2 additions & 1 deletion platformtest/tests/recvForceIntoEncryptedErr.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"github.com/stretchr/testify/require"

"github.com/zrepl/zrepl/platformtest"
"github.com/zrepl/zrepl/util/nodefault"
"github.com/zrepl/zrepl/zfs"
)

Expand All @@ -32,7 +33,7 @@ func ReceiveForceIntoEncryptedErr(ctx *platformtest.Context) {

sendArgs, err := zfs.ZFSSendArgsUnvalidated{
FS: sfs,
Encrypted: &zfs.NilBool{B: false},
Encrypted: &nodefault.Bool{B: false},
From: nil,
To: &sfsSnap1,
ResumeToken: "",
Expand Down
3 changes: 2 additions & 1 deletion platformtest/tests/recvRollback.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"github.com/stretchr/testify/require"

"github.com/zrepl/zrepl/platformtest"
"github.com/zrepl/zrepl/util/nodefault"
"github.com/zrepl/zrepl/zfs"
)

Expand All @@ -28,7 +29,7 @@ func ReceiveForceRollbackWorksUnencrypted(ctx *platformtest.Context) {

sendArgs, err := zfs.ZFSSendArgsUnvalidated{
FS: sfs,
Encrypted: &zfs.NilBool{B: false},
Encrypted: &nodefault.Bool{B: false},
From: nil,
To: &sfsSnap1,
ResumeToken: "",
Expand Down
3 changes: 2 additions & 1 deletion platformtest/tests/replication.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"github.com/zrepl/zrepl/replication/logic/pdu"
"github.com/zrepl/zrepl/replication/report"
"github.com/zrepl/zrepl/util/limitio"
"github.com/zrepl/zrepl/util/nodefault"
"github.com/zrepl/zrepl/zfs"
)

Expand Down Expand Up @@ -57,7 +58,7 @@ func (i replicationInvocation) Do(ctx *platformtest.Context) *report.Report {
}
sender := i.interceptSender(endpoint.NewSender(endpoint.SenderConfig{
FSF: i.sfilter.AsFilter(),
Encrypt: &zfs.NilBool{B: false},
Encrypt: &nodefault.Bool{B: false},
JobID: i.sjid,
}))
receiver := i.interceptReceiver(endpoint.NewReceiver(endpoint.ReceiverConfig{
Expand Down
3 changes: 2 additions & 1 deletion platformtest/tests/resumableRecvAndTokenHandling.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"github.com/stretchr/testify/require"

"github.com/zrepl/zrepl/platformtest"
"github.com/zrepl/zrepl/util/nodefault"
"github.com/zrepl/zrepl/zfs"
)

Expand All @@ -28,7 +29,7 @@ func ResumableRecvAndTokenHandling(ctx *platformtest.Context) {
s := makeResumeSituation(ctx, src, recvFS, zfs.ZFSSendArgsUnvalidated{
FS: sendFS,
To: src.snapA,
Encrypted: &zfs.NilBool{B: false},
Encrypted: &nodefault.Bool{B: false},
ResumeToken: "",
}, zfs.RecvOptions{
RollbackAndForceRecv: false, // doesnt' exist yet
Expand Down
11 changes: 6 additions & 5 deletions platformtest/tests/sendArgsValidation.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"github.com/stretchr/testify/require"

"github.com/zrepl/zrepl/platformtest"
"github.com/zrepl/zrepl/util/nodefault"
"github.com/zrepl/zrepl/zfs"
)

Expand Down Expand Up @@ -42,7 +43,7 @@ func sendArgsValidationEncryptedSendOfUnencryptedDatasetForbidden_impl(ctx *plat
RelName: "@a snap",
GUID: props.Guid,
},
Encrypted: &zfs.NilBool{B: true},
Encrypted: &nodefault.Bool{B: true},
ResumeToken: "",
}.Validate(ctx)

Expand Down Expand Up @@ -97,7 +98,7 @@ func SendArgsValidationResumeTokenEncryptionMismatchForbidden(ctx *platformtest.
unencS := makeResumeSituation(ctx, src, unencRecvFS, zfs.ZFSSendArgsUnvalidated{
FS: sendFS,
To: src.snapA,
Encrypted: &zfs.NilBool{B: false}, // !
Encrypted: &nodefault.Bool{B: false}, // !
}, zfs.RecvOptions{
RollbackAndForceRecv: false,
SavePartialRecvState: true,
Expand All @@ -106,7 +107,7 @@ func SendArgsValidationResumeTokenEncryptionMismatchForbidden(ctx *platformtest.
encS := makeResumeSituation(ctx, src, encRecvFS, zfs.ZFSSendArgsUnvalidated{
FS: sendFS,
To: src.snapA,
Encrypted: &zfs.NilBool{B: true}, // !
Encrypted: &nodefault.Bool{B: true}, // !
}, zfs.RecvOptions{
RollbackAndForceRecv: false,
SavePartialRecvState: true,
Expand Down Expand Up @@ -174,7 +175,7 @@ func SendArgsValidationResumeTokenDifferentFilesystemForbidden(ctx *platformtest
rs := makeResumeSituation(ctx, src1, recvFS, zfs.ZFSSendArgsUnvalidated{
FS: sendFS1,
To: src1.snapA,
Encrypted: &zfs.NilBool{B: false},
Encrypted: &nodefault.Bool{B: false},
}, zfs.RecvOptions{
RollbackAndForceRecv: false,
SavePartialRecvState: true,
Expand All @@ -188,7 +189,7 @@ func SendArgsValidationResumeTokenDifferentFilesystemForbidden(ctx *platformtest
RelName: src2.snapA.RelName,
GUID: src2.snapA.GUID,
},
Encrypted: &zfs.NilBool{B: false},
Encrypted: &nodefault.Bool{B: false},
ResumeToken: rs.recvErrDecoded.ResumeTokenRaw,
}
_, err = maliciousSend.Validate(ctx)
Expand Down

0 comments on commit 1c937e5

Please sign in to comment.