Skip to content
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
1 change: 1 addition & 0 deletions internal/verifier/check.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ func (verifier *Verifier) Check(ctx context.Context, filter map[string]any) {
verifier.logger.Fatal().Err(err).Msgf("Fatal error in generation %d", verifier.generation)
}
}()
verifier.MaybeStartPeriodicHeapProfileCollection(ctx)
}

func (verifier *Verifier) waitForChangeStream() error {
Expand Down
16 changes: 16 additions & 0 deletions internal/verifier/migration_verifier.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,8 @@ type Verifier struct {
// The filter is applied to all namespaces in both initial checking and iterative checking.
// The verifier only checks documents within the filter.
globalFilter map[string]any

pprofInterval time.Duration
}

// VerificationStatus holds the Verification Status
Expand Down Expand Up @@ -360,6 +362,20 @@ func (verifier *Verifier) SetReadPreference(arg string) error {
return err
}

func (verifier *Verifier) SetPprofInterval(arg string) error {
if arg == "" {
return nil
}

interval, err := time.ParseDuration(arg)
if err != nil {
return err
}

verifier.pprofInterval = interval
return nil
}

// DocumentStats gets various stats (TODO clarify)
func DocumentStats(ctx context.Context, client *mongo.Client, namespaces []string) {

Expand Down
45 changes: 45 additions & 0 deletions internal/verifier/pprof.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package verifier

import (
"context"
"fmt"
"os"
"runtime/pprof"
"time"
)

func (verifier *Verifier) MaybeStartPeriodicHeapProfileCollection(ctx context.Context) {
if verifier.pprofInterval == 0 {
return
}

go func() {
ticker := time.NewTicker(verifier.pprofInterval)
defer ticker.Stop()

for {
select {
case <-ctx.Done():
return
case <-ticker.C:
collectHeapUsage()
}
}
}()

}

func collectHeapUsage() {
heapFileName := fmt.Sprintf("heap-%s.out", time.Now().UTC().Format("20060102T150405Z"))
heapFile, err := os.Create(heapFileName)
defer heapFile.Close()

if err != nil {
panic(err)
}

err = pprof.Lookup("heap").WriteTo(heapFile, 0)
if err != nil {
panic(err)
}
}
6 changes: 6 additions & 0 deletions main/migration_verifier.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ const (
failureDisplaySize = "failureDisplaySize"
ignoreReadConcernFlag = "ignoreReadConcern"
configFileFlag = "configFile"
pprofInterval = "pprofInterval"
)

func main() {
Expand Down Expand Up @@ -146,6 +147,10 @@ func main() {
Name: ignoreReadConcernFlag,
Usage: "Use connection-default read concerns rather than setting majority read concern. This option may degrade consistency, so only enable it if majority read concern (the default) doesn’t work.",
}),
altsrc.NewStringFlag(cli.StringFlag{
Name: pprofInterval,
Usage: "Interval to periodically collect pprof profiles (e.g. --pprofInterval=\"5m\")",
}),
}

app := &cli.App{
Expand Down Expand Up @@ -207,6 +212,7 @@ func handleArgs(ctx context.Context, cCtx *cli.Context) (*verifier.Verifier, err
v.SetNumWorkers(cCtx.Int(numWorkers))
v.SetGenerationPauseDelayMillis(time.Duration(cCtx.Int64(generationPauseDelay)))
v.SetWorkerSleepDelayMillis(time.Duration(cCtx.Int64(workerSleepDelay)))
v.SetPprofInterval(cCtx.String(pprofInterval))

partitionSizeMB := cCtx.Uint64(partitionSizeMB)
if partitionSizeMB != 0 {
Expand Down