Skip to content

Commit 4f3d3aa

Browse files
authored
REP-5324 Normalize error handling. (#59)
In certain cases migration-verifier would log on fatal errors rather than propagating them back up the call stack. This has led to failures to compare documents that were effectively ignored save for being noted in the log. This changeset fixes that so that such exceptional cases will halt the verification. Broadly speaking, this changeset: a) brings idiomatic Context propagation in places where context.Background() was used b) converts Error() logs and “failed” task statuses to returned errors As of this changeset, any task in “failed” indicates a mismatch rather than a failure to complete the check. A separate changeset will introduce a retryer to FetchAndCompareDocuments. Other, specific changes: - CheckWorker() is rewritten to use an errgroup, which automatically cancels context if a thread fails. - CheckDriver() now returns errors rather than Error() logging them. - A few places’ direct checks for ctx.Done() are removed. (They’re superfluous.) - TestGenerationalRechecking and TestPartitionWithFilter no longer use constant DB names. - RunForUUIDErrorOnly() now takes a context. (NB: This method is currently unused.) - Most uses of context.Background() in tests are now suite.Context(). - The unused RecheckTasks is removed from VerificationStatus.
1 parent d077573 commit 4f3d3aa

File tree

11 files changed

+457
-313
lines changed

11 files changed

+457
-313
lines changed

internal/retry/retry.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,12 +59,12 @@ func (r *Retryer) RunForUUIDAndTransientErrors(
5959
//
6060
// RunForUUIDErrorOnly returns the collection's current name in all cases.
6161
func (r *Retryer) RunForUUIDErrorOnly(
62-
logger *logger.Logger, expectedCollName string, f func(*Info, string) error,
62+
ctx context.Context, logger *logger.Logger, expectedCollName string, f func(*Info, string) error,
6363
) (string, error) {
6464
// Since we're not actually sleeping when checking for UUID/name mismatch
6565
// errors, we don't need to provide a real context to handle
6666
// cancellations.
67-
return r.runRetryLoop(context.Background(), logger, expectedCollName, f, false, true)
67+
return r.runRetryLoop(ctx, logger, expectedCollName, f, false, true)
6868
}
6969

7070
// RunForTransientErrorsOnly retries f() for transient errors only, and

internal/retry/retryer_test.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ func (suite *UnitTestSuite) TestRetryer() {
2626
suite.NoError(err)
2727
suite.Equal(0, attemptNumber)
2828

29-
_, err = retryer.RunForUUIDErrorOnly(logger, "foo", f)
29+
_, err = retryer.RunForUUIDErrorOnly(suite.Context(), logger, "foo", f)
3030
suite.NoError(err)
3131
suite.Equal(0, attemptNumber)
3232

@@ -92,7 +92,7 @@ func (suite *UnitTestSuite) TestRetryer() {
9292
}
9393
return nil
9494
}
95-
_, err := retryer.RunForUUIDErrorOnly(logger, "bar", f)
95+
_, err := retryer.RunForUUIDErrorOnly(suite.Context(), logger, "bar", f)
9696
suite.NoError(err)
9797
suite.Equal(attemptLimit/2, attemptNumber)
9898
})
@@ -109,7 +109,7 @@ func (suite *UnitTestSuite) TestRetryer() {
109109
Raw: bson.Raw(raw),
110110
}
111111
}
112-
_, err := retryer.RunForUUIDErrorOnly(logger, "bar", f)
112+
_, err := retryer.RunForUUIDErrorOnly(suite.Context(), logger, "bar", f)
113113
suite.NoError(err)
114114
// We only did one retry because the actual collection name matched the
115115
// previous attempt.
@@ -130,7 +130,7 @@ func (suite *UnitTestSuite) TestRetryerDurationLimitIsZero() {
130130
return cmdErr
131131
}
132132

133-
_, err := retryer.RunForUUIDErrorOnly(suite.Logger(), "bar", f)
133+
_, err := retryer.RunForUUIDErrorOnly(suite.Context(), suite.Logger(), "bar", f)
134134
suite.Equal(cmdErr, err)
135135
suite.Equal(0, attemptNumber)
136136
}
@@ -280,7 +280,7 @@ func (suite *UnitTestSuite) TestRetryerWithEmptyCollectionName() {
280280
return nil
281281
}
282282

283-
name, err := retryer.RunForUUIDErrorOnly(suite.Logger(), "", f)
283+
name, err := retryer.RunForUUIDErrorOnly(suite.Context(), suite.Logger(), "", f)
284284
suite.NoError(err)
285285
suite.Equal("", name)
286286
}

internal/verifier/change_stream_test.go

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ func (suite *IntegrationTestSuite) TestChangeStreamResumability() {
5555

5656
func() {
5757
verifier1 := suite.BuildVerifier()
58-
ctx, cancel := context.WithCancel(context.Background())
58+
ctx, cancel := context.WithCancel(suite.Context())
5959
defer cancel()
6060
err := verifier1.StartChangeStream(ctx)
6161
suite.Require().NoError(err)
@@ -147,8 +147,7 @@ func (suite *IntegrationTestSuite) fetchVerifierRechecks(ctx context.Context, ve
147147

148148
func (suite *IntegrationTestSuite) TestStartAtTimeNoChanges() {
149149
verifier := suite.BuildVerifier()
150-
ctx, cancel := context.WithCancel(context.Background())
151-
defer cancel()
150+
ctx := suite.Context()
152151
sess, err := suite.srcMongoClient.StartSession()
153152
suite.Require().NoError(err)
154153
sctx := mongo.NewSessionContext(ctx, sess)
@@ -167,8 +166,7 @@ func (suite *IntegrationTestSuite) TestStartAtTimeNoChanges() {
167166

168167
func (suite *IntegrationTestSuite) TestStartAtTimeWithChanges() {
169168
verifier := suite.BuildVerifier()
170-
ctx, cancel := context.WithCancel(context.Background())
171-
defer cancel()
169+
ctx := suite.Context()
172170
sess, err := suite.srcMongoClient.StartSession()
173171
suite.Require().NoError(err)
174172
sctx := mongo.NewSessionContext(ctx, sess)
@@ -220,8 +218,7 @@ func (suite *IntegrationTestSuite) TestStartAtTimeWithChanges() {
220218

221219
func (suite *IntegrationTestSuite) TestNoStartAtTime() {
222220
verifier := suite.BuildVerifier()
223-
ctx, cancel := context.WithCancel(context.Background())
224-
defer cancel()
221+
ctx := suite.Context()
225222
sess, err := suite.srcMongoClient.StartSession()
226223
suite.Require().NoError(err)
227224
sctx := mongo.NewSessionContext(ctx, sess)

0 commit comments

Comments
 (0)