waitForStoppedInLogFile waits for the replication to stop by checking the log file.
(ctx context.Context)
| 342 | |
| 343 | // waitForStoppedInLogFile waits for the replication to stop by checking the log file. |
| 344 | func (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 | |
| 369 | var _ Manager = &couchbaseServerManager{} |
no test coverage detected