marsadm: add new command 'set-replay'

This commit is contained in:
Thomas Schoebel-Theuer 2013-04-18 10:37:14 +02:00
parent 22f75b9d71
commit 8d93439dcb
2 changed files with 38 additions and 2 deletions

View File

@ -815,8 +815,23 @@ int _update_version_link(struct mars_rotate *rot, struct trans_logger_info *inf)
if (unlikely((inf->inf_sequence < rot->inf_prev_sequence ||
inf->inf_sequence > rot->inf_prev_sequence + 1) &&
rot->inf_prev_sequence != 0)) {
MARS_ERR_TO(rot->log_say, "SKIP in sequence numbers detected: %d != %d + 1\n", inf->inf_sequence, rot->inf_prev_sequence);
goto out;
char *skip_path = path_make("%s/skip-check-%s", rot->parent_path, my_id());
char *skip_link = mars_readlink(skip_path);
int skip_nr = -1;
if (skip_link) {
(void)sscanf(skip_link, "%d", &skip_nr);
brick_string_free(skip_link);
}
brick_string_free(skip_path);
if (likely(skip_nr != inf->inf_sequence)) {
MARS_ERR_TO(rot->log_say, "SKIP in sequence numbers detected: %d != %d + 1\n", inf->inf_sequence, rot->inf_prev_sequence);
goto out;
}
MARS_WRN_TO(rot->log_say,
"you explicitly requested to SKIP sequence numbers from %d to %d"
"-- THIS IS EXTREMELY RISKY"
"-- any inconsistencies are on your own!\n",
rot->inf_prev_sequence, inf->inf_sequence);
}
prev = path_make("%s/version-%09d-%s", rot->parent_path, inf->inf_sequence - 1, my_id());
if (unlikely(!prev)) {

View File

@ -929,6 +929,26 @@ sub up_res {
}
}
sub set_replay_res {
my ($cmd, $res, $new_nr) = @_;
if (!$new_nr || $new_nr <= 0) {
ldie "you must supply a numeric logfile number as third argument.\n";
}
check_not_primary(@_);
check_todo($cmd, $res, "allow-replay", 0, 0);
my $replaylink = "$mars/resource-$res/replay-$host";
my $old_val = get_link($replaylink);
my $old_nr = $old_val;
$old_nr =~ s/log-([0-9]+)-.*/$1/;
ldie "old log number '$old_nr' is wrong\n" unless $old_nr > 0;
if ($new_nr > $old_nr) {
lwarn "you try to skip logfile numbers from $old_nr to $new_nr, are you sure?\n";
ldie "you would need --force if you really know what you are doing.\n" unless $force;
}
_set_replaylink("$mars/resource-$res", $new_nr, "");
symlink("$new_nr", "$mars/resource-$res/skip-check-$host");
}
sub fake_local_res {
my ($cmd, $res) = @_;
my $path = "$mars/resource-$res/todo-$host/sync";
@ -1193,6 +1213,7 @@ my %cmd_table =
"resume-replay" => \&pause_replay_res,
"pause-replay-local" => \&pause_replay_local_res,
"resume-replay-local" => \&pause_replay_local_res,
"set-replay" => \&set_replay_res,
# compatible keywords (or their derivatives)
"attach" => \&attach_res,