This commit is contained in:
Christian Schwarz 2018-08-25 21:30:25 +02:00
parent e082816de5
commit e30ae972f4
27 changed files with 130 additions and 147 deletions

View File

@ -9,8 +9,8 @@ import (
"time"
"github.com/problame/go-streamrpc"
"github.com/zrepl/zrepl/util"
"github.com/zrepl/zrepl/logger"
"github.com/zrepl/zrepl/util"
)
type logNetConnConnecter struct {
@ -58,7 +58,6 @@ func (l logListener) Accept() (net.Conn, error) {
return util.NewNetConnLogger(conn, l.ReadDump, l.WriteDump)
}
type netsshAddr struct{}
func (netsshAddr) Network() string { return "netssh" }
@ -87,7 +86,7 @@ type twoClassLogAdaptor struct {
var _ streamrpc.Logger = twoClassLogAdaptor{}
func (a twoClassLogAdaptor) Errorf(fmtStr string, args... interface{}) {
func (a twoClassLogAdaptor) Errorf(fmtStr string, args ...interface{}) {
const errorSuffix = ": %s"
if len(args) == 1 {
if err, ok := args[0].(error); ok && strings.HasSuffix(fmtStr, errorSuffix) {
@ -99,7 +98,6 @@ func (a twoClassLogAdaptor) Errorf(fmtStr string, args... interface{}) {
a.Logger.Error(fmt.Sprintf(fmtStr, args...))
}
func (a twoClassLogAdaptor) Infof(fmtStr string, args... interface{}) {
func (a twoClassLogAdaptor) Infof(fmtStr string, args ...interface{}) {
a.Logger.Info(fmt.Sprintf(fmtStr, args...))
}

View File

@ -11,8 +11,8 @@ import (
"github.com/pkg/errors"
"github.com/problame/go-netssh"
"github.com/problame/go-streamrpc"
"time"
"github.com/zrepl/zrepl/cmd/tlsconf"
"time"
)
type SSHStdinserverConnecter struct {
@ -51,7 +51,7 @@ func parseSSHStdinserverConnecter(i map[string]interface{}) (c *SSHStdinserverCo
}
type netsshConnToConn struct { *netssh.SSHConn }
type netsshConnToConn struct{ *netssh.SSHConn }
var _ net.Conn = netsshConnToConn{}

View File

@ -5,10 +5,10 @@ import (
"context"
"encoding/json"
"github.com/pkg/errors"
"github.com/zrepl/zrepl/logger"
"io"
"net"
"net/http"
"github.com/zrepl/zrepl/logger"
)
type ControlJob struct {

View File

@ -6,10 +6,10 @@ import (
"context"
"github.com/mitchellh/mapstructure"
"github.com/pkg/errors"
"github.com/zrepl/zrepl/cmd/endpoint"
"github.com/zrepl/zrepl/replication"
"github.com/zrepl/zrepl/zfs"
"sync"
"github.com/zrepl/zrepl/replication"
"github.com/zrepl/zrepl/cmd/endpoint"
)
type LocalJob struct {

View File

@ -11,8 +11,8 @@ import (
"github.com/mitchellh/mapstructure"
"github.com/pkg/errors"
"github.com/problame/go-streamrpc"
"github.com/zrepl/zrepl/replication"
"github.com/zrepl/zrepl/cmd/endpoint"
"github.com/zrepl/zrepl/replication"
)
type PullJob struct {
@ -155,7 +155,6 @@ var STREAMRPC_CONFIG = &streamrpc.ConnConfig{ // FIXME oversight and configurabi
},
}
func (j *PullJob) doRun(ctx context.Context) {
j.task.Enter("run")

View File

@ -7,8 +7,8 @@ import (
"github.com/mitchellh/mapstructure"
"github.com/pkg/errors"
"github.com/problame/go-streamrpc"
"net"
"github.com/zrepl/zrepl/cmd/endpoint"
"net"
)
type SourceJob struct {
@ -160,7 +160,7 @@ func (j *SourceJob) serve(ctx context.Context, task *Task) {
connChan := make(chan connChanMsg)
// Serve connections until interrupted or error
outer:
outer:
for {
go func() {

View File

@ -1,15 +1,15 @@
package cmd
import (
"crypto/tls"
"crypto/x509"
"github.com/mattn/go-isatty"
"github.com/mitchellh/mapstructure"
"github.com/pkg/errors"
"github.com/zrepl/zrepl/cmd/tlsconf"
"github.com/zrepl/zrepl/logger"
"os"
"time"
"crypto/tls"
"crypto/x509"
"github.com/zrepl/zrepl/cmd/tlsconf"
)
type LoggingConfig struct {

View File

@ -6,8 +6,8 @@ import (
"github.com/mitchellh/mapstructure"
"github.com/pkg/errors"
"github.com/zrepl/zrepl/zfs"
"github.com/zrepl/zrepl/cmd/endpoint"
"github.com/zrepl/zrepl/zfs"
)
type DatasetMapFilter struct {

View File

@ -7,12 +7,12 @@ import (
yaml "github.com/go-yaml/yaml"
"github.com/mitchellh/mapstructure"
"github.com/pkg/errors"
"github.com/problame/go-streamrpc"
"github.com/zrepl/zrepl/replication"
"os"
"regexp"
"strconv"
"time"
"github.com/zrepl/zrepl/replication"
"github.com/problame/go-streamrpc"
)
var ConfigFileDefaultLocations []string = []string{

View File

@ -56,7 +56,7 @@ func parseTCPListenerFactory(c JobParsingContext, i map[string]interface{}) (*TC
lf.clientCA, err = tlsconf.ParseCAFile(in.CA)
if err != nil {
return errors.Wrap(err,"cannot parse ca file")
return errors.Wrap(err, "cannot parse ca file")
}
lf.serverCert, err = tls.LoadX509KeyPair(in.Cert, in.Key)

View File

@ -136,7 +136,7 @@ func TestDatasetMapFilter(t *testing.T) {
expectMapping(map1, "q/r", "root4/1/2/r")
map2 := map[string]string{ // identity mapping
"<":"",
"<": "",
}
expectMapping(map2, "foo/bar", "foo/bar")

View File

@ -2,15 +2,15 @@
package endpoint
import (
"github.com/zrepl/zrepl/replication/pdu"
"github.com/problame/go-streamrpc"
"github.com/zrepl/zrepl/zfs"
"io"
"github.com/pkg/errors"
"github.com/golang/protobuf/proto"
"bytes"
"context"
"github.com/golang/protobuf/proto"
"github.com/pkg/errors"
"github.com/problame/go-streamrpc"
"github.com/zrepl/zrepl/replication"
"github.com/zrepl/zrepl/replication/pdu"
"github.com/zrepl/zrepl/zfs"
"io"
)
// Sender implements replication.ReplicationEndpoint for a sending side
@ -87,9 +87,9 @@ type FSFilter interface {
// FIXME: can we get away without error types here?
type FSMap interface {
FSFilter
Map(path *zfs.DatasetPath) (*zfs.DatasetPath,error)
Invert() (FSMap,error)
AsFilter() (FSFilter)
Map(path *zfs.DatasetPath) (*zfs.DatasetPath, error)
Invert() (FSMap, error)
AsFilter() FSFilter
}
// Receiver implements replication.ReplicationEndpoint for a receiving side
@ -219,7 +219,6 @@ func (e *Receiver) Receive(ctx context.Context, req *pdu.ReceiveReq, sendStream
// RPC STUBS
// =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
const (
RPCListFilesystems = "ListFilesystems"
RPCListFilesystemVersions = "ListFilesystemVersions"
@ -301,7 +300,7 @@ func (s Remote) Send(ctx context.Context, r *pdu.SendReq) (*pdu.SendRes, io.Read
return &res, rs, nil
}
func (s Remote) Receive(ctx context.Context, r *pdu.ReceiveReq, sendStream io.ReadCloser) (error) {
func (s Remote) Receive(ctx context.Context, r *pdu.ReceiveReq, sendStream io.ReadCloser) error {
defer sendStream.Close()
b, err := proto.Marshal(r)
if err != nil {
@ -414,6 +413,6 @@ func (a *Handler) Handle(ctx context.Context, endpoint string, reqStructured *by
return bytes.NewBuffer(b), nil, err
}
Err:
Err:
return nil, nil, errors.New("no handler for given endpoint")
}

View File

@ -1,7 +1,6 @@
package logger
type nullLogger struct {}
type nullLogger struct{}
var _ Logger = nullLogger{}
@ -19,4 +18,3 @@ func (nullLogger) Info(msg string) {}
func (nullLogger) Warn(msg string) {}
func (nullLogger) Error(msg string) {}
func (nullLogger) Printf(format string, args ...interface{}) {}

View File

@ -1,8 +1,8 @@
package replication
import (
"github.com/zrepl/zrepl/logger"
"context"
"github.com/zrepl/zrepl/logger"
"github.com/zrepl/zrepl/replication/fsrep"
)
@ -27,4 +27,3 @@ func getLogger(ctx context.Context) Logger {
}
return l
}

View File

@ -12,8 +12,8 @@ import (
"sync"
"time"
"github.com/zrepl/zrepl/replication/pdu"
"github.com/zrepl/zrepl/logger"
"github.com/zrepl/zrepl/replication/pdu"
)
type contextKey int
@ -54,10 +54,9 @@ type Report struct {
Filesystem string
Status string
Problem string
Completed,Pending []*StepReport
Completed, Pending []*StepReport
}
//go:generate stringer -type=State
type State uint
@ -136,7 +135,6 @@ func NewReplicationWithPermanentError(fs string, err error) *Replication {
}
}
//go:generate stringer -type=StepState
type StepState uint
@ -387,4 +385,3 @@ func (step *ReplicationStep) Report() *StepReport {
}
return &rep
}

View File

@ -1,8 +1,8 @@
package queue
import (
"time"
"sort"
"time"
. "github.com/zrepl/zrepl/replication/fsrep"
)
@ -27,12 +27,12 @@ func NewReplicationQueue() *ReplicationQueue {
func (q ReplicationQueue) Len() int { return len(q) }
func (q ReplicationQueue) Swap(i, j int) { q[i], q[j] = q[j], q[i] }
type lessmapEntry struct{
type lessmapEntry struct {
prio int
less func(a,b *replicationQueueItem) bool
less func(a, b *replicationQueueItem) bool
}
var lessmap = map[State]lessmapEntry {
var lessmap = map[State]lessmapEntry{
Ready: {
prio: 0,
less: func(a, b *replicationQueueItem) bool {

View File

@ -10,10 +10,10 @@ import (
"sync"
"time"
"github.com/zrepl/zrepl/replication/pdu"
"github.com/zrepl/zrepl/replication/fsrep"
. "github.com/zrepl/zrepl/replication/internal/queue"
. "github.com/zrepl/zrepl/replication/internal/diff"
. "github.com/zrepl/zrepl/replication/internal/queue"
"github.com/zrepl/zrepl/replication/pdu"
)
//go:generate stringer -type=State
@ -77,7 +77,6 @@ type Report struct {
Active *fsrep.Report
}
func NewReplication() *Replication {
r := Replication{
state: Planning,
@ -101,7 +100,6 @@ type Receiver interface {
fsrep.Receiver
}
type FilteredError struct{ fs string }
func NewFilteredError(fs string) *FilteredError {
@ -110,7 +108,6 @@ func NewFilteredError(fs string) *FilteredError {
func (f FilteredError) Error() string { return "endpoint does not allow access to filesystem " + f.fs }
type updater func(func(*Replication)) (newState State)
type state func(ctx context.Context, sender Sender, receiver Receiver, u updater) state
@ -381,4 +378,3 @@ func (r *Replication) Report() *Report {
return &rep
}

View File

@ -1,8 +1,8 @@
package pdu
import (
"testing"
"github.com/stretchr/testify/assert"
"testing"
)
func TestFilesystemVersion_RelName(t *testing.T) {
@ -56,7 +56,7 @@ func TestFilesystemVersion_ZFSFilesystemVersion(t *testing.T) {
emptyZFS := empty.ZFSFilesystemVersion()
assert.Zero(t, emptyZFS.Creation)
dateInvalid := &FilesystemVersion{Creation:"foobar"}
dateInvalid := &FilesystemVersion{Creation: "foobar"}
assert.Panics(t, func() {
dateInvalid.ZFSFilesystemVersion()
})

View File

@ -9,4 +9,3 @@ const (
)
const DEFAULT_INITIAL_REPL_POLICY = InitialReplPolicyMostRecent

View File

@ -2,8 +2,8 @@ package util
import (
"context"
"time"
"sync"
"time"
)
type contextWithOptionalDeadline struct {
@ -28,7 +28,7 @@ func (c *contextWithOptionalDeadline) Err() error {
return c.err
}
func (c *contextWithOptionalDeadline) Done() (<-chan struct{}) {
func (c *contextWithOptionalDeadline) Done() <-chan struct{} {
return c.done
}

View File

@ -1,11 +1,11 @@
package util
import (
"testing"
"context"
"time"
"github.com/stretchr/testify/require"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"testing"
"time"
)
func TestContextWithOptionalDeadline(t *testing.T) {
@ -18,14 +18,14 @@ func TestContextWithOptionalDeadline(t *testing.T) {
var cancellationError error
go func() {
select {
case <- cctx.Done():
case <-cctx.Done():
receivedCancellation = time.Now()
cancellationError = cctx.Err()
case <- time.After(600*time.Millisecond):
case <-time.After(600 * time.Millisecond):
t.Fatalf("should have been cancelled by deadline")
}
}()
time.Sleep(100*time.Millisecond)
time.Sleep(100 * time.Millisecond)
if !receivedCancellation.IsZero() {
t.Fatalf("no enforcement means no cancellation")
}
@ -33,11 +33,11 @@ func TestContextWithOptionalDeadline(t *testing.T) {
dl, ok := cctx.Deadline()
require.False(t, ok)
require.Zero(t, dl)
enforceDeadline(begin.Add(200*time.Millisecond))
enforceDeadline(begin.Add(200 * time.Millisecond))
// second call must be ignored, i.e. we expect the deadline to be at begin+200ms, not begin+400ms
enforceDeadline(begin.Add(400*time.Millisecond))
enforceDeadline(begin.Add(400 * time.Millisecond))
time.Sleep(300*time.Millisecond) // 100ms margin for scheduler
time.Sleep(300 * time.Millisecond) // 100ms margin for scheduler
if receivedCancellation.Sub(begin) > 250*time.Millisecond {
t.Fatalf("cancellation is beyond acceptable scheduler latency")
}
@ -47,7 +47,7 @@ func TestContextWithOptionalDeadline(t *testing.T) {
func TestContextWithOptionalDeadlineNegativeDeadline(t *testing.T) {
ctx := context.Background()
cctx, enforceDeadline := ContextWithOptionalDeadline(ctx)
enforceDeadline(time.Now().Add(-10*time.Second))
enforceDeadline(time.Now().Add(-10 * time.Second))
select {
case <-cctx.Done():
default:
@ -62,10 +62,10 @@ func TestContextWithOptionalDeadlineParentCancellation(t *testing.T) {
// 0 ms
start := time.Now()
enforceDeadline(start.Add(400*time.Millisecond))
time.Sleep(100*time.Millisecond)
enforceDeadline(start.Add(400 * time.Millisecond))
time.Sleep(100 * time.Millisecond)
cancel() // cancel @ ~100ms
time.Sleep(100*time.Millisecond) // give 100ms time to propagate cancel
time.Sleep(100 * time.Millisecond) // give 100ms time to propagate cancel
// @ ~200ms
select {
case <-cctx.Done():

View File

@ -5,9 +5,9 @@ import (
"crypto/sha512"
"encoding/hex"
"fmt"
"io"
"os/exec"
"sort"
"io"
)
type fsbyCreateTXG []FilesystemVersion

View File

@ -39,7 +39,7 @@ func ZFSListMappingProperties(filter DatasetFilter, properties []string) (datase
panic("properties must not contain 'name'")
}
}
newProps := make([]string, len(properties) + 1)
newProps := make([]string, len(properties)+1)
newProps[0] = "name"
copy(newProps[1:], properties)
properties = newProps
@ -78,5 +78,3 @@ func ZFSListMappingProperties(filter DatasetFilter, properties []string) (datase
return
}

View File

@ -6,10 +6,10 @@ import (
"errors"
"fmt"
"github.com/prometheus/client_golang/prometheus"
"io"
"strconv"
"strings"
"time"
"io"
)
type VersionType string