opt(lua): Avoid separate hops for lock & unlock on single shard execution (#1900)

This commit is contained in:
Shahar Mike 2023-09-22 14:09:17 +03:00 committed by GitHub
parent 8cc448f6b4
commit 2091f53777
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 78 additions and 44 deletions

View file

@ -54,7 +54,12 @@ Transaction::Transaction(const CommandId* cid) : cid_{cid} {
Transaction::Transaction(const Transaction* parent)
: multi_{make_unique<MultiData>()}, txid_{parent->txid()} {
multi_->mode = parent->multi_->mode;
if (parent->multi_) {
multi_->mode = parent->multi_->mode;
} else {
// Use squashing mechanism for inline execution of single-shard EVAL
multi_->mode = LOCK_AHEAD;
}
multi_->role = SQUASHED_STUB;
time_now_ms_ = parent->time_now_ms_;
@ -405,6 +410,15 @@ string Transaction::DebugId() const {
return StrCat(Name(), "@", txid_, "/", unique_shard_cnt_, " (", trans_id(this), ")");
}
void Transaction::PrepareMultiForScheduleSingleHop(ShardId sid, DbIndex db, CmdArgList args) {
multi_.reset();
InitBase(db, args);
EnableShard(sid);
OpResult<KeyIndex> key_index = DetermineKeys(cid_, args);
CHECK(key_index);
StoreKeysInArgs(*key_index, false);
}
// Runs in the dbslice thread. Returns true if the transaction continues running in the thread.
bool Transaction::RunInShard(EngineShard* shard, bool txq_ooo) {
DCHECK_GT(run_count_.load(memory_order_relaxed), 0u);