Skip to content

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

abhijat
Copy link
Contributor

@abhijat abhijat commented Jun 13, 2025

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:

  • 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.

For context, the original PR is #5257

abhijat added 2 commits June 13, 2025 09:51
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]>
Comment on lines +556 to +560
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();

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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());
Copy link
Collaborator

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(
Copy link
Collaborator

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants