MCPcopy Create free account
hub / github.com/couchbase/sync_gateway / waitForStoppedInLogFile

Method waitForStoppedInLogFile

xdcr/cbs_xdcr.go:344–367  ·  view source on GitHub ↗

waitForStoppedInLogFile waits for the replication to stop by checking the log file.

(ctx context.Context)

Source from the content-addressed store, hash-verified

342
343// waitForStoppedInLogFile waits for the replication to stop by checking the log file.
344func (x *couchbaseServerManager) waitForStoppedInLogFile(ctx context.Context) error {
345 // magic string to indicate that the replication has stopped
346 grepStr := fmt.Sprintf("%s status is finished shutting down", x.replicationID)
347 logFile := x.xdcrLogFilePath()
348 // look for log files that are goxcdr.log[.[0-9]][.gz], the message may be in a rotated log
349 cmdLine := fmt.Sprintf(`zgrep --no-filename "%s" "%s"*`, grepStr, logFile)
350 err, _ := base.RetryLoop(ctx, "ReadLogFileUntilStopped", func() (shouldRetry bool, err error, value any) {
351 output, err := x.runCommandOnCBS(cmdLine)
352 if err != nil {
353 return true, err, nil
354 }
355 for _, line := range strings.Split(strings.TrimSpace(output), "\n") {
356 timestamp := strings.Split(line, " ")[0]
357 if timestamp > x.startingTimestamp {
358 return false, nil, nil
359 }
360 }
361 return true, fmt.Errorf("Could not find line newer than %s in %s", x.startingTimestamp, output), nil
362 }, base.CreateLinearSleeperFunc(5*time.Minute, 1*time.Second))
363 if err != nil {
364 return fmt.Errorf("Could not find %s in %s. %w", grepStr, logFile, err)
365 }
366 return nil
367}
368
369var _ Manager = &couchbaseServerManager{}

Callers 1

StopMethod · 0.95

Calls 5

xdcrLogFilePathMethod · 0.95
runCommandOnCBSMethod · 0.95
RetryLoopFunction · 0.92
CreateLinearSleeperFuncFunction · 0.92
ErrorfMethod · 0.80

Tested by

no test coverage detected