From 0f75677e591d99c0695dc6dd9a8b520558ec47ed Mon Sep 17 00:00:00 2001 From: Christian Schwarz Date: Wed, 5 Sep 2018 21:47:44 -0700 Subject: [PATCH] daemon/pruner: fix exercise (don't call it test) --- daemon/pruner/pruner.go | 27 +++++++++++++++++++-------- daemon/pruner/pruner_test.go | 12 +++++++++--- 2 files changed, 28 insertions(+), 11 deletions(-) diff --git a/daemon/pruner/pruner.go b/daemon/pruner/pruner.go index e3d5c8c..64e6487 100644 --- a/daemon/pruner/pruner.go +++ b/daemon/pruner/pruner.go @@ -270,11 +270,22 @@ fsloop: l := GetLogger(ctx).WithField("fs", tfs.Path) l.Debug("plan filesystem") + + pfs := &fs{ + path: tfs.Path, + } + pfss[i] = pfs + tfsvs, err := target.ListFilesystemVersions(ctx, tfs.Path) if err != nil { l.WithError(err).Error("cannot list filesystem versions") - return onErr(u, err) + if shouldRetry(err) { + return onErr(u, err) + } + pfs.err = err + continue fsloop } + pfs.snaps = make([]pruning.Snapshot, 0, len(tfsvs)) rcReq := &pdu.ReplicationCursorReq{ Filesystem: tfs.Path, @@ -283,18 +294,18 @@ fsloop: rc, err := receiver.ReplicationCursor(ctx, rcReq) if err != nil { l.WithError(err).Error("cannot get replication cursor") - return onErr(u, err) + if shouldRetry(err) { + return onErr(u, err) + } + pfs.err = err + continue fsloop } if rc.GetError() != "" { l.WithField("reqErr", rc.GetError()).Error("cannot get replication cursor") - return onErr(u, fmt.Errorf("%s", rc.GetError())) + pfs.err = fmt.Errorf("%s", rc.GetError()) + continue fsloop } - pfs := &fs{ - path: tfs.Path, - snaps: make([]pruning.Snapshot, 0, len(tfsvs)), - } - pfss[i] = pfs // scan from older to newer, all snapshots older than cursor are interpreted as replicated sort.Slice(tfsvs, func(i, j int) bool { diff --git a/daemon/pruner/pruner_test.go b/daemon/pruner/pruner_test.go index dea3d5f..a3e1656 100644 --- a/daemon/pruner/pruner_test.go +++ b/daemon/pruner/pruner_test.go @@ -30,6 +30,7 @@ func (m *mockFS) FilesystemVersions() []*pdu.FilesystemVersion { Type: pdu.FilesystemVersion_Snapshot, Name: v, Creation: pdu.FilesystemVersionCreation(time.Unix(0, 0)), + Guid: uint64(i), } } return versions @@ -89,18 +90,23 @@ func (t *mockTarget) DestroySnapshots(ctx context.Context, req *pdu.DestroySnaps return &pdu.DestroySnapshotsRes{Results: res}, nil } +type mockCursor struct { + snapname string + guid uint64 +} type mockHistory struct { errs map[string][]error + cursors map[string]*mockCursor } -func (r *mockHistory) SnapshotReplicationStatus(ctx context.Context, req *pdu.SnapshotReplicationStatusReq) (*pdu.SnapshotReplicationStatusRes, error) { +func (r *mockHistory) ReplicationCursor(ctx context.Context, req *pdu.ReplicationCursorReq) (*pdu.ReplicationCursorRes, error) { fs := req.Filesystem if len(r.errs[fs]) > 0 { e := r.errs[fs][0] r.errs[fs] = r.errs[fs][1:] return nil, e } - return &pdu.SnapshotReplicationStatusRes{Status: pdu.SnapshotReplicationStatusRes_Nonexistent}, nil + return &pdu.ReplicationCursorRes{Result: &pdu.ReplicationCursorRes_Guid{Guid: 0}}, nil } type stubNetErr struct { @@ -195,7 +201,7 @@ func TestPruner_Prune(t *testing.T) { exp := map[string][]string{ "zroot/bar": {"drop_g"}, // drop_c is prohibited by failing destroy - // drop_i is prohibiteed by failing WasSnapshotReplicated call + // drop_i is prohibiteed by failing ReplicationCursor call } assert.Equal(t, exp, target.destroyed)