Skip to content

REP-6000 Add a “Detail” column to the worker-thread table. #110

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Apr 29, 2025
Merged
Show file tree
Hide file tree
Changes from all 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
12 changes: 12 additions & 0 deletions internal/verifier/compare.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@ package verifier
import (
"bytes"
"context"
"fmt"
"time"

"github.com/10gen/migration-verifier/contextplus"
"github.com/10gen/migration-verifier/internal/reportutils"
"github.com/10gen/migration-verifier/internal/retry"
"github.com/10gen/migration-verifier/internal/types"
"github.com/10gen/migration-verifier/internal/util"
Expand All @@ -19,6 +21,7 @@ const readTimeout = 10 * time.Minute

func (verifier *Verifier) FetchAndCompareDocuments(
givenCtx context.Context,
workerNum int,
task *VerificationTask,
) (
[]VerificationResult,
Expand Down Expand Up @@ -61,6 +64,7 @@ func (verifier *Verifier) FetchAndCompareDocuments(
var err error
results, docCount, byteCount, err = verifier.compareDocsFromChannels(
ctx,
workerNum,
fi,
task,
srcChannel,
Expand All @@ -77,6 +81,7 @@ func (verifier *Verifier) FetchAndCompareDocuments(

func (verifier *Verifier) compareDocsFromChannels(
ctx context.Context,
workerNum int,
fi *retry.FuncInfo,
task *VerificationTask,
srcChannel, dstChannel <-chan bson.Raw,
Expand Down Expand Up @@ -196,6 +201,13 @@ func (verifier *Verifier) compareDocsFromChannels(

srcDocCount++
srcByteCount += types.ByteCount(len(srcDoc))
verifier.workerTracker.SetDetail(
workerNum,
fmt.Sprintf(
"read %s documents",
reportutils.FmtReal(srcDocCount),
),
)
}

return nil
Expand Down
1 change: 1 addition & 0 deletions internal/verifier/compare_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ func (s *IntegrationTestSuite) TestFetchAndCompareDocuments_Context() {
go func() {
_, _, _, err := verifier.FetchAndCompareDocuments(
cancelableCtx,
0,
&task,
)
if err != nil {
Expand Down
2 changes: 2 additions & 0 deletions internal/verifier/migration_verifier.go
Original file line number Diff line number Diff line change
Expand Up @@ -640,6 +640,7 @@ func (verifier *Verifier) ProcessVerifyTask(ctx context.Context, workerNum int,
var curBytesCount types.ByteCount
curProblems, curDocsCount, curBytesCount, err = verifier.FetchAndCompareDocuments(
ctx,
workerNum,
&miniTask,
)

Expand All @@ -654,6 +655,7 @@ func (verifier *Verifier) ProcessVerifyTask(ctx context.Context, workerNum int,
} else {
problems, docsCount, bytesCount, err = verifier.FetchAndCompareDocuments(
ctx,
workerNum,
task,
)
}
Expand Down
2 changes: 1 addition & 1 deletion internal/verifier/migration_verifier_bench_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ func BenchmarkGeneric(t *testing.B) {
qfilter := QueryFilter{Namespace: namespace}
task := VerificationTask{QueryFilter: qfilter}
// TODO: is this safe?
mismatchedIds, docsCount, bytesCount, err := verifier.FetchAndCompareDocuments(context.Background(), &task)
mismatchedIds, docsCount, bytesCount, err := verifier.FetchAndCompareDocuments(context.Background(), 0, &task)
if err != nil {
t.Fatal(err)
}
Expand Down
7 changes: 4 additions & 3 deletions internal/verifier/migration_verifier_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ func (suite *IntegrationTestSuite) TestVerifierFetchDocuments() {

// Test fetchDocuments without global filter.
verifier.globalFilter = nil
results, docCount, byteCount, err := verifier.FetchAndCompareDocuments(ctx, task)
results, docCount, byteCount, err := verifier.FetchAndCompareDocuments(ctx, 0, task)
suite.Require().NoError(err)
suite.Assert().EqualValues(2, docCount, "should find source docs")
suite.Assert().NotZero(byteCount, "should tally docs' size")
Expand All @@ -112,7 +112,7 @@ func (suite *IntegrationTestSuite) TestVerifierFetchDocuments() {
// Test fetchDocuments for ids with a global filter.

verifier.globalFilter = map[string]any{"num": map[string]any{"$lt": 100}}
results, docCount, byteCount, err = verifier.FetchAndCompareDocuments(ctx, task)
results, docCount, byteCount, err = verifier.FetchAndCompareDocuments(ctx, 0, task)
suite.Require().NoError(err)
suite.Assert().EqualValues(1, docCount, "should find source docs")
suite.Assert().NotZero(byteCount, "should tally docs' size")
Expand All @@ -129,7 +129,7 @@ func (suite *IntegrationTestSuite) TestVerifierFetchDocuments() {
Ns: &partitions.Namespace{DB: "keyhole", Coll: "dealers"},
}
verifier.globalFilter = map[string]any{"num": map[string]any{"$lt": 100}}
results, docCount, byteCount, err = verifier.FetchAndCompareDocuments(ctx, task)
results, docCount, byteCount, err = verifier.FetchAndCompareDocuments(ctx, 0, task)
suite.Require().NoError(err)
suite.Assert().EqualValues(1, docCount, "should find source docs")
suite.Assert().NotZero(byteCount, "should tally docs' size")
Expand Down Expand Up @@ -655,6 +655,7 @@ func TestVerifierCompareDocs(t *testing.T) {

results, docCount, byteCount, err = verifier.compareDocsFromChannels(
ctx,
0,
fi,
&fauxTask,
srcChannel,
Expand Down
3 changes: 2 additions & 1 deletion internal/verifier/summary.go
Original file line number Diff line number Diff line change
Expand Up @@ -483,7 +483,7 @@ func (verifier *Verifier) printChangeEventStatistics(builder *strings.Builder, n
func (verifier *Verifier) printWorkerStatus(builder *strings.Builder, now time.Time) {

table := tablewriter.NewWriter(builder)
table.SetHeader([]string{"Thread #", "Namespace", "Task", "Time Elapsed"})
table.SetHeader([]string{"Thread #", "Namespace", "Task", "Time Elapsed", "Detail"})

wsmap := verifier.workerTracker.Load()

Expand Down Expand Up @@ -512,6 +512,7 @@ func (verifier *Verifier) printWorkerStatus(builder *strings.Builder, now time.T
wsmap[w].Namespace,
taskIdStr,
reportutils.DurationToHMS(now.Sub(wsmap[w].StartTime)),
wsmap[w].Detail,
},
)
}
Expand Down
11 changes: 11 additions & 0 deletions internal/verifier/worker_tracker.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ type WorkerStatus struct {
TaskType verificationTaskType
Namespace string
StartTime time.Time
Detail string
}

// NewWorkerTracker creates and returns a WorkerTracker.
Expand Down Expand Up @@ -51,6 +52,16 @@ func (wt *WorkerTracker) Set(workerNum int, task VerificationTask) {
})
}

func (wt *WorkerTracker) SetDetail(workerNum int, detail string) {
wt.guard.Store(func(m WorkerStatusMap) WorkerStatusMap {
status := m[workerNum]
status.Detail = detail
m[workerNum] = status

return m
})
}

// Unset tells the WorkerTracker that the worker is now inactive.
func (wt *WorkerTracker) Unset(workerNum int) {
wt.guard.Store(func(m WorkerStatusMap) WorkerStatusMap {
Expand Down