Skip to content

Commit

Permalink
Remove unneeded "internal/util/nodefault"
Browse files Browse the repository at this point in the history
  • Loading branch information
dsh2dsh committed Nov 28, 2024
1 parent 22534ac commit b1de6b3
Show file tree
Hide file tree
Showing 10 changed files with 52 additions and 133 deletions.
3 changes: 1 addition & 2 deletions internal/daemon/job/build_jobs_sendrecvoptions.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"github.com/dsh2dsh/zrepl/internal/config"
"github.com/dsh2dsh/zrepl/internal/daemon/filters"
"github.com/dsh2dsh/zrepl/internal/endpoint"
"github.com/dsh2dsh/zrepl/internal/util/nodefault"
"github.com/dsh2dsh/zrepl/internal/zfs"
)

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

ListPlaceholders: sendOpts.ListPlaceholders,

Encrypt: &nodefault.Bool{B: sendOpts.Encrypted},
Encrypt: sendOpts.Encrypted,
SendRaw: sendOpts.Raw,
SendProperties: sendOpts.SendProperties,
SendBackupProperties: sendOpts.BackupProperties,
Expand Down
3 changes: 1 addition & 2 deletions internal/daemon/job/snapjob.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import (
"github.com/dsh2dsh/zrepl/internal/endpoint"
"github.com/dsh2dsh/zrepl/internal/logger"
"github.com/dsh2dsh/zrepl/internal/replication/logic/pdu"
"github.com/dsh2dsh/zrepl/internal/util/nodefault"
"github.com/dsh2dsh/zrepl/internal/zfs"
)

Expand Down Expand Up @@ -248,7 +247,7 @@ func (j *SnapJob) prune(ctx context.Context) {
// FIXME the following config fields are irrelevant for SnapJob
// because the endpoint is only used as pruner.Target.
// However, the implementation requires them to be set.
Encrypt: &nodefault.Bool{B: true},
Encrypt: true,
})

localSender := NewLocalSender(ctx, sender)
Expand Down
9 changes: 7 additions & 2 deletions internal/daemon/logging/slog.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"log"
"log/slog"
"sync"
"unicode"

"github.com/dsh2dsh/zrepl/internal/config"
)
Expand Down Expand Up @@ -145,8 +146,12 @@ func (self *SlogFormatter) format(r slog.Record) error {
if err := self.h.Handle(ctx, r); err != nil {
return fmt.Errorf("failed slog handler: %w", err)
}
// Discard last byte (\n), added by slog.TextHandler.
self.b.Truncate(self.b.Len() - 1)

// Discard trailing '\n', added by slog.TextHandler, and trailing ' ' added by
// formatStd.
b := self.b.Bytes()
b = bytes.TrimRightFunc(b, unicode.IsSpace)
self.b.Truncate(len(b))
return nil
}

Expand Down
6 changes: 1 addition & 5 deletions internal/endpoint/endpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import (
"github.com/dsh2dsh/zrepl/internal/logger"
"github.com/dsh2dsh/zrepl/internal/replication/logic/pdu"
"github.com/dsh2dsh/zrepl/internal/util/chainlock"
"github.com/dsh2dsh/zrepl/internal/util/nodefault"
"github.com/dsh2dsh/zrepl/internal/zfs"
zfsprop "github.com/dsh2dsh/zrepl/internal/zfs/property"
)
Expand All @@ -32,7 +31,7 @@ type SenderConfig struct {

ListPlaceholders bool

Encrypt *nodefault.Bool
Encrypt bool
SendRaw bool
SendProperties bool
SendBackupProperties bool
Expand All @@ -46,9 +45,6 @@ type SenderConfig struct {

func (c *SenderConfig) Validate() error {
c.JobID.MustValidate()
if err := c.Encrypt.ValidateNoDefault(); err != nil {
return fmt.Errorf("`Encrypt` field invalid: %w", err)
}
if _, err := StepHoldTag(c.JobID); err != nil {
return fmt.Errorf("JobID cannot be used for hold tag: %w", err)
}
Expand Down
22 changes: 7 additions & 15 deletions internal/endpoint/endpoint_zfs_abstraction.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import (
"golang.org/x/sync/errgroup"

"github.com/dsh2dsh/zrepl/internal/util/envconst"
"github.com/dsh2dsh/zrepl/internal/util/nodefault"
"github.com/dsh2dsh/zrepl/internal/zfs"
)

Expand Down Expand Up @@ -306,7 +305,7 @@ type ListZFSHoldsAndBookmarksQuery struct {

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

// A non-empty range of CreateTXGs
Expand Down Expand Up @@ -349,9 +348,6 @@ 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.ValidateNoDefault(); err != nil {
return fmt.Errorf("Inclusive: %w", err)
}
if i.CreateTXG == 0 && !createTXGRangeBoundAllowCreateTXG0 {
return errors.New("CreateTXG must be non-zero")
}
Expand Down Expand Up @@ -432,7 +428,7 @@ func (r *CreateTXGRange) effectiveBounds() (bounds effectiveBounds, err error) {

if r.Since != nil {
bounds.sinceInclusive = r.Since.CreateTXG
if !r.Since.Inclusive.B {
if !r.Since.Inclusive {
if r.Since.CreateTXG == math.MaxUint64 {
return bounds, fmt.Errorf("Since-exclusive (%v) must be less than math.MaxUint64 (%v)",
r.Since.CreateTXG, uint64(math.MaxUint64))
Expand All @@ -443,7 +439,7 @@ func (r *CreateTXGRange) effectiveBounds() (bounds effectiveBounds, err error) {

if r.Until != nil {
bounds.untilInclusive = r.Until.CreateTXG
if !r.Until.Inclusive.B {
if !r.Until.Inclusive {
if r.Until.CreateTXG == 0 {
return bounds, fmt.Errorf("Until-exclusive (%v) must be greater than 0", r.Until.CreateTXG)
}
Expand All @@ -466,9 +462,7 @@ func (r *CreateTXGRange) String() string {
if r.Since == nil {
fmt.Fprintf(&buf, "~")
} else {
if err := r.Since.Inclusive.ValidateNoDefault(); err != nil {
fmt.Fprintf(&buf, "?")
} else if r.Since.Inclusive.B {
if r.Since.Inclusive {
fmt.Fprintf(&buf, "[")
} else {
fmt.Fprintf(&buf, "(")
Expand All @@ -482,9 +476,7 @@ func (r *CreateTXGRange) String() string {
fmt.Fprintf(&buf, "~")
} else {
fmt.Fprintf(&buf, "%d", r.Until.CreateTXG)
if err := r.Until.Inclusive.ValidateNoDefault(); err != nil {
fmt.Fprintf(&buf, "?")
} else if r.Until.Inclusive.B {
if r.Until.Inclusive {
fmt.Fprintf(&buf, "]")
} else {
fmt.Fprintf(&buf, ")")
Expand Down Expand Up @@ -878,15 +870,15 @@ 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: &nodefault.Bool{B: true},
Inclusive: true,
}
case 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: &nodefault.Bool{B: false},
Inclusive: false,
}
default:
untilBound = nil // consider everything stale
Expand Down
36 changes: 17 additions & 19 deletions internal/endpoint/endpoint_zfs_abstraction_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ import (

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

"github.com/dsh2dsh/zrepl/internal/util/nodefault"
)

func TestCreateTXGRange(t *testing.T) {
Expand Down Expand Up @@ -46,35 +44,35 @@ func TestCreateTXGRange(t *testing.T) {
name: "wrong order obvious",
expectInvalid: true,
config: &CreateTXGRange{
Since: &CreateTXGRangeBound{23, &nodefault.Bool{B: true}},
Until: &CreateTXGRangeBound{20, &nodefault.Bool{B: true}},
Since: &CreateTXGRangeBound{23, true},
Until: &CreateTXGRangeBound{20, true},
},
expectString: "[23,20]",
},
{
name: "wrong order edge-case could also be empty",
expectInvalid: true,
config: &CreateTXGRange{
Since: &CreateTXGRangeBound{23, &nodefault.Bool{B: false}},
Until: &CreateTXGRangeBound{22, &nodefault.Bool{B: true}},
Since: &CreateTXGRangeBound{23, false},
Until: &CreateTXGRangeBound{22, true},
},
expectString: "(23,22]",
},
{
name: "empty",
expectInvalid: true,
config: &CreateTXGRange{
Since: &CreateTXGRangeBound{2, &nodefault.Bool{B: false}},
Until: &CreateTXGRangeBound{2, &nodefault.Bool{B: false}},
Since: &CreateTXGRangeBound{2, false},
Until: &CreateTXGRangeBound{2, false},
},
expectString: "(2,2)",
},
{
name: "inclusive-since-exclusive-until",
expectInvalid: false,
config: &CreateTXGRange{
Since: &CreateTXGRangeBound{2, &nodefault.Bool{B: true}},
Until: &CreateTXGRangeBound{5, &nodefault.Bool{B: false}},
Since: &CreateTXGRangeBound{2, true},
Until: &CreateTXGRangeBound{5, false},
},
expectString: "[2,5)",
expect: []testCaseExpectation{
Expand All @@ -91,8 +89,8 @@ func TestCreateTXGRange(t *testing.T) {
name: "exclusive-since-inclusive-until",
expectInvalid: false,
config: &CreateTXGRange{
Since: &CreateTXGRangeBound{2, &nodefault.Bool{B: false}},
Until: &CreateTXGRangeBound{5, &nodefault.Bool{B: true}},
Since: &CreateTXGRangeBound{2, false},
Until: &CreateTXGRangeBound{5, true},
},
expectString: "(2,5]",
expect: []testCaseExpectation{
Expand All @@ -110,15 +108,15 @@ func TestCreateTXGRange(t *testing.T) {
expectInvalid: true,
config: &CreateTXGRange{
Since: nil,
Until: &CreateTXGRangeBound{0, &nodefault.Bool{B: true}},
Until: &CreateTXGRangeBound{0, true},
},
expectString: "~,0]",
},
{
name: "half-open-no-until",
expectInvalid: false,
config: &CreateTXGRange{
Since: &CreateTXGRangeBound{2, &nodefault.Bool{B: false}},
Since: &CreateTXGRangeBound{2, false},
Until: nil,
},
expectString: "(2,~",
Expand All @@ -137,7 +135,7 @@ func TestCreateTXGRange(t *testing.T) {
expectInvalid: false,
config: &CreateTXGRange{
Since: nil,
Until: &CreateTXGRangeBound{4, &nodefault.Bool{B: true}},
Until: &CreateTXGRangeBound{4, true},
},
expectString: "~,4]",
expect: []testCaseExpectation{
Expand All @@ -153,7 +151,7 @@ func TestCreateTXGRange(t *testing.T) {
name: "edgeSince",
expectInvalid: false,
config: &CreateTXGRange{
Since: &CreateTXGRangeBound{math.MaxUint64, &nodefault.Bool{B: true}},
Since: &CreateTXGRangeBound{math.MaxUint64, true},
Until: nil,
},
expectString: "[18446744073709551615,~",
Expand All @@ -168,7 +166,7 @@ func TestCreateTXGRange(t *testing.T) {
name: "edgeSinceNegative",
expectInvalid: true,
config: &CreateTXGRange{
Since: &CreateTXGRangeBound{math.MaxUint64, &nodefault.Bool{B: false}},
Since: &CreateTXGRangeBound{math.MaxUint64, false},
Until: nil,
},
expectString: "(18446744073709551615,~",
Expand All @@ -177,7 +175,7 @@ func TestCreateTXGRange(t *testing.T) {
name: "edgeUntil",
expectInvalid: false,
config: &CreateTXGRange{
Until: &CreateTXGRangeBound{0, &nodefault.Bool{B: true}},
Until: &CreateTXGRangeBound{0, true},
},
configAllowZeroCreateTXG: true,
expectString: "~,0]",
Expand All @@ -192,7 +190,7 @@ func TestCreateTXGRange(t *testing.T) {
expectInvalid: true,
configAllowZeroCreateTXG: true,
config: &CreateTXGRange{
Until: &CreateTXGRangeBound{0, &nodefault.Bool{B: false}},
Until: &CreateTXGRangeBound{0, false},
},
expectString: "~,0)",
},
Expand Down
31 changes: 0 additions & 31 deletions internal/util/nodefault/nodefault.go

This file was deleted.

22 changes: 0 additions & 22 deletions internal/util/nodefault/nodefault_bool.go

This file was deleted.

Loading

0 comments on commit b1de6b3

Please sign in to comment.