Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
101 changes: 101 additions & 0 deletions internal/verifier/migration_verifier_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -567,6 +567,107 @@ func (suite *IntegrationTestSuite) TestVerifierFetchDocuments() {
)
}

func (suite *IntegrationTestSuite) TestGetPersistedNamespaceStatistics_Metadata() {
ctx := suite.Context()
verifier := suite.BuildVerifier()
verifier.SetVerifyAll(true)

dbName := suite.DBNameForTest()

err := verifier.srcClient.Database(dbName).CreateCollection(
ctx,
"foo",
)
suite.Require().NoError(err)

runner := RunVerifierCheck(ctx, suite.T(), verifier)
suite.Require().NoError(runner.AwaitGenerationEnd())

stats, err := verifier.GetPersistedNamespaceStatistics(ctx)
suite.Require().NoError(err)

suite.Assert().Equal(
mslices.Of(NamespaceStats{
Namespace: dbName + ".foo",
}),
stats,
"stats should be as expected",
)

suite.Require().NoError(runner.StartNextGeneration())
suite.Require().NoError(runner.AwaitGenerationEnd())

stats, err = verifier.GetPersistedNamespaceStatistics(ctx)
suite.Require().NoError(err)

suite.Assert().Equal(
mslices.Of(NamespaceStats{
Namespace: dbName + ".foo",
}),
stats,
"stats should be as expected",
)
}

func (suite *IntegrationTestSuite) TestGetPersistedNamespaceStatistics_OneDoc() {
ctx := suite.Context()
verifier := suite.BuildVerifier()
verifier.SetVerifyAll(true)

bsonDoc := lo.Must(bson.Marshal(bson.D{{"_id", "foo"}}))

dbName := suite.DBNameForTest()
_, err := verifier.srcClient.Database(dbName).Collection("foo").
InsertOne(ctx, bsonDoc)
suite.Require().NoError(err)

err = verifier.dstClient.Database(dbName).CreateCollection(
ctx,
"foo",
)
suite.Require().NoError(err)

runner := RunVerifierCheck(ctx, suite.T(), verifier)
suite.Require().NoError(runner.AwaitGenerationEnd())

stats, err := verifier.GetPersistedNamespaceStatistics(ctx)
suite.Require().NoError(err)

suite.Assert().Equal(
mslices.Of(NamespaceStats{
Namespace: dbName + ".foo",
DocsCompared: 1,
TotalDocs: 1,
BytesCompared: types.ByteCount(len(bsonDoc)),
TotalBytes: types.ByteCount(len(bsonDoc)),
PartitionsDone: 1,
}),
stats,
"stats should be as expected",
)

suite.Require().NoError(runner.StartNextGeneration())
suite.Require().NoError(runner.AwaitGenerationEnd())

stats, err = verifier.GetPersistedNamespaceStatistics(ctx)
suite.Require().NoError(err)

suite.Assert().Equal(
mslices.Of(NamespaceStats{
Namespace: dbName + ".foo",
DocsCompared: 1,
TotalDocs: 1,
BytesCompared: types.ByteCount(len(bsonDoc)),
PartitionsDone: 1,

// NB: TotalBytes is 0 because we can’t compute that from the
// change stream.
}),
stats,
"stats should be as expected",
)
}

func (suite *IntegrationTestSuite) TestGetPersistedNamespaceStatistics_Recheck() {
ctx := suite.Context()
verifier := suite.BuildVerifier()
Expand Down
30 changes: 14 additions & 16 deletions internal/verifier/statistics.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,28 +114,26 @@ const perNsStatsPipelineTemplate = `[
In generation 0 we can get the total docs from the
verify-collection tasks.

In later generations we don’t have verify-collection tasks,
In later generations we may not have verify-collection tasks,
so we add up the individual recheck batch tasks. Note that,
in these tasks source_documents_count refers to the actual
number of docs found on the source, not all the documents
checked.
*/}}
"totalDocs": {
"$cond": [
{ "$or": [
{ "$eq": [ "$type", "{{.VerifyCollType}}" ] },
{ "$and": [
{ "$eq": [ "$type", "{{.VerifyDocsType}}" ] },
{ "$ne": [ "$generation", 0 ] }
] }
] },
{ "$cond": [
{"$eq": [ "$generation", 0 ]},
"$source_documents_count",
{ "$size": "$_ids" }
] },
0
]
"$cond": {
"if": {"$eq": [ "$generation", 0 ]},
"then": { "$cond": {
"if": { "$eq": [ "$type", "{{.VerifyCollType}}" ] },
"then": "$source_documents_count",
"else": 0
} },
"else": { "$cond": {
"if": { "$eq": [ "$type", "{{.VerifyDocsType}}" ] },
"then": { "$size": "$_ids" },
"else": 0
} }
}
},

{{/*
Expand Down
Loading