(generic family): journal support move command (#708)

Signed-off-by: adi_holden <adi@dragonflydb.io>
This commit is contained in:
adiholden 2023-01-19 13:19:27 +02:00 committed by GitHub
parent 45162b5c0a
commit 160aeaa2d8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -1060,9 +1060,10 @@ void GenericFamily::Restore(CmdArgList args, ConnectionContext* cntx) {
void GenericFamily::Move(CmdArgList args, ConnectionContext* cntx) {
string_view key = ArgS(args, 1);
string_view target_db_sv = ArgS(args, 2);
int64_t target_db;
if (!absl::SimpleAtoi(ArgS(args, 2), &target_db)) {
if (!absl::SimpleAtoi(target_db_sv, &target_db)) {
return (*cntx)->SendError(kInvalidIntErr);
}
@ -1079,7 +1080,13 @@ void GenericFamily::Move(CmdArgList args, ConnectionContext* cntx) {
auto cb = [&](Transaction* t, EngineShard* shard) {
// MOVE runs as a global transaction and is therefore scheduled on every shard.
if (target_shard == shard->shard_id()) {
res = OpMove(t->GetOpArgs(shard), key, target_db);
auto op_args = t->GetOpArgs(shard);
res = OpMove(op_args, key, target_db);
// MOVE runs as global command but we want to write the
// command to only one journal.
if (op_args.shard->journal()) {
RecordJournal(op_args, "MOVE"sv, ArgSlice{key, target_db_sv});
}
}
return OpStatus::OK;
};
@ -1456,7 +1463,7 @@ void GenericFamily::Register(CommandRegistry* registry) {
<< CI{"UNLINK", CO::WRITE, -2, 1, -1, 1}.HFUNC(Del)
<< CI{"STICK", CO::WRITE, -2, 1, -1, 1}.HFUNC(Stick)
<< CI{"SORT", CO::READONLY, -2, 1, 1, 1}.HFUNC(Sort)
<< CI{"MOVE", CO::WRITE | CO::GLOBAL_TRANS, 3, 1, 1, 1}.HFUNC(Move)
<< CI{"MOVE", CO::WRITE | CO::GLOBAL_TRANS | CO::NO_AUTOJOURNAL, 3, 1, 1, 1}.HFUNC(Move)
<< CI{"RESTORE", CO::WRITE, -4, 1, 1, 1}.HFUNC(Restore);
}