-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
baaf843
commit 700802b
Showing
4 changed files
with
58 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import time | ||
|
||
from click import command, option, pass_context | ||
|
||
from ch_tools.common.result import Result | ||
from ch_tools.monrun_checks.ch_replication_lag import estimate_replication_lag | ||
|
||
|
||
@command("wait-replication-sync") | ||
@option( | ||
"-s", | ||
"--status", | ||
type=int, | ||
default=0, | ||
help="Wait until returned status is no worse than given, 0 = OK (default), 1 = WARN, 2 = CRIT.", | ||
) | ||
@option( | ||
"-p", | ||
"--pause", | ||
type=int, | ||
default=30, | ||
help="Pause between request in seconds, default is 30 seconds.", | ||
) | ||
@option( | ||
"-t", | ||
"--timeout", | ||
type=int, | ||
default=3 * 24 * 60 * 60, | ||
help="Max amount of time to wait, in seconds. Default is 30 days.", | ||
) | ||
@pass_context | ||
def wait_replication_sync_command(ctx, status, pause, timeout): | ||
"""Wait for ClickHouse server to sync replication with other replicas.""" | ||
|
||
deadline = time.time() + timeout | ||
while time.time() < deadline: | ||
res = estimate_replication_lag(ctx) | ||
if res.code <= status: | ||
return Result(code=0) | ||
time.sleep(pause) | ||
|
||
return Result(code=2, message=f"ClickHouse can\'t sync replica for {timeout} seconds") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters