mirror of
https://github.com/dragonflydb/dragonfly.git
synced 2025-05-10 18:05:44 +02:00
opt(server): Execute lua on target shard, if it's 1 (#1639)
* opt(server): Execute lua on target shard, if it's 1 This will save hops by short-circuiting execution of commands. * Reuse unique shard id from tx Only switch threads for LOCK_AHEAD * Signedness
This commit is contained in:
parent
6d84515e08
commit
734401098c
3 changed files with 18 additions and 3 deletions
|
@ -1438,15 +1438,22 @@ void Service::EvalInternal(const EvalArgs& eval_args, Interpreter* interpreter,
|
||||||
sinfo->keys.insert(KeyLockArgs::GetLockKey(ArgS(eval_args.keys, i)));
|
sinfo->keys.insert(KeyLockArgs::GetLockKey(ArgS(eval_args.keys, i)));
|
||||||
}
|
}
|
||||||
sinfo->async_cmds_heap_limit = absl::GetFlag(FLAGS_multi_eval_squash_buffer);
|
sinfo->async_cmds_heap_limit = absl::GetFlag(FLAGS_multi_eval_squash_buffer);
|
||||||
DCHECK(cntx->transaction);
|
Transaction* tx = cntx->transaction;
|
||||||
|
CHECK(tx != nullptr);
|
||||||
|
|
||||||
bool scheduled = StartMultiEval(cntx->db_index(), eval_args.keys, *params, cntx->transaction);
|
bool scheduled = StartMultiEval(cntx->db_index(), eval_args.keys, *params, tx);
|
||||||
|
|
||||||
interpreter->SetGlobalArray("KEYS", eval_args.keys);
|
interpreter->SetGlobalArray("KEYS", eval_args.keys);
|
||||||
interpreter->SetGlobalArray("ARGV", eval_args.args);
|
interpreter->SetGlobalArray("ARGV", eval_args.args);
|
||||||
interpreter->SetRedisFunc([cntx, this](auto args) { CallFromScript(cntx, args); });
|
interpreter->SetRedisFunc([cntx, this](auto args) { CallFromScript(cntx, args); });
|
||||||
|
|
||||||
Interpreter::RunResult result = interpreter->RunFunction(eval_args.sha, &error);
|
Interpreter::RunResult result;
|
||||||
|
if (tx->GetMultiMode() == Transaction::LOCK_AHEAD && tx->GetUniqueShardCnt() == 1) {
|
||||||
|
ShardId sid = tx->GetUniqueShard();
|
||||||
|
pp_.at(sid)->Await([&]() { result = interpreter->RunFunction(eval_args.sha, &error); });
|
||||||
|
} else {
|
||||||
|
result = interpreter->RunFunction(eval_args.sha, &error);
|
||||||
|
}
|
||||||
absl::Cleanup clean = [interpreter]() { interpreter->ResetStack(); };
|
absl::Cleanup clean = [interpreter]() { interpreter->ResetStack(); };
|
||||||
|
|
||||||
if (auto err = FlushEvalAsyncCmds(cntx, true); err) {
|
if (auto err = FlushEvalAsyncCmds(cntx, true); err) {
|
||||||
|
|
|
@ -946,6 +946,11 @@ string_view Transaction::Name() const {
|
||||||
return cid_->name();
|
return cid_->name();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ShardId Transaction::GetUniqueShard() const {
|
||||||
|
DCHECK_EQ(GetUniqueShardCnt(), 1U);
|
||||||
|
return unique_shard_id_;
|
||||||
|
}
|
||||||
|
|
||||||
KeyLockArgs Transaction::GetLockArgs(ShardId sid) const {
|
KeyLockArgs Transaction::GetLockArgs(ShardId sid) const {
|
||||||
KeyLockArgs res;
|
KeyLockArgs res;
|
||||||
res.db_index = db_index_;
|
res.db_index = db_index_;
|
||||||
|
|
|
@ -263,6 +263,9 @@ class Transaction {
|
||||||
return unique_shard_cnt_;
|
return unique_shard_cnt_;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// This method is meaningless if GetUniqueShardCnt() != 1.
|
||||||
|
ShardId GetUniqueShard() const;
|
||||||
|
|
||||||
bool IsMulti() const {
|
bool IsMulti() const {
|
||||||
return bool(multi_);
|
return bool(multi_);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue