-
Notifications
You must be signed in to change notification settings - Fork 1.1k
chore(string_family): Refactor to prep for adding the GAT command #5289
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
A couple of functions are extracted from the MGet command. The reason for this is that in a follow up PR, the GAT command will be added which will reuse some of the functions: A function to collect keys is extracted. This takes a function as input which will return an iterator for one key. The iterator can be mutable or immutable, for MGet it is immutable. For GAT it will be mutable. A check is added such that a read-only command does not use a function returning a mutable iterator. Another function is created to reorder collected results based on the shards of the keys and the original order of the keys in the command. Signed-off-by: Abhijat Malviya <[email protected]>
Signed-off-by: Abhijat Malviya <[email protected]>
const auto cid = t->GetCId(); | ||
constexpr bool is_mut_iter = std::is_same_v<Iter, DbSlice::Iterator>; | ||
DCHECK(!(cid->IsReadOnly() && is_mut_iter)) | ||
<< "mutable iterator used with read-only command " << cid->name(); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
const auto cid = t->GetCId(); | |
constexpr bool is_mut_iter = std::is_same_v<Iter, DbSlice::Iterator>; | |
DCHECK(!(cid->IsReadOnly() && is_mut_iter)) | |
<< "mutable iterator used with read-only command " << cid->name(); | |
constexpr bool is_mut_iter = std::is_same_v<Iter, DbSlice::Iterator>; | |
if constexpr (is_mut_iter) { | |
const auto* cid = t->GetCId(); | |
DCHECK(!cid->IsReadOnly()) << "mutable iterator used with read-only command " << cid->name(); | |
} |
|
||
template <typename Iter> | ||
MGetResponse CollectKeys(BlockingCounter wait_bc, uint8_t fetch_mask, const Transaction* t, | ||
EngineShard* shard, SearchKey<Iter> find_op) { | ||
ShardArgs keys = t->GetShardArgs(shard->shard_id()); | ||
DCHECK(!keys.Empty()); | ||
|
||
auto& db_slice = t->GetDbSlice(shard->shard_id()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
move db_slice
to the block where you use it
@@ -1294,12 +1319,41 @@ void StringFamily::DecrBy(CmdArgList args, const CommandContext& cmnd_cntx) { | |||
return IncrByGeneric(key, -val, cmnd_cntx.tx, cmnd_cntx.rb); | |||
} | |||
|
|||
absl::FixedArray<optional<GetResp>, 8> ReorderShardResults( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
absl::FixedArray<optional<GetResp>, 8>
is more than 512 bytes - and it's not moveable, meaning that now we always have to copy at least 512 bytes.
Instead, I suggest the following signature:
void ReorderShardResults(const std::vector<MGetResponse>& mget_resp, const Transaction* t, absl::FixedArray<optional<GetResp>, 8>* dest);
and define res out side of the function.
A couple of functions are extracted from the MGet command. In a follow up PR, the GAT command will be added which
will reuse some of the functions:
For context, the original PR is #5257