@@ -169,11 +169,18 @@ OpResult<int64_t> CountHllsSingle(const OpArgs& op_args, string_view key) {
169169 }
170170}
171171
172- OpResult<vector<string>> ReadValues (const OpArgs& op_args, const ShardArgs& keys) {
172+ OpResult<vector<string>> ReadValues (const OpArgs& op_args, const ShardArgs& keys,
173+ bool skip_dest_key) {
173174 try {
174175 vector<string> values;
175- for (string_view key : keys) {
176- auto it = op_args.GetDbSlice ().FindReadOnly (op_args.db_cntx , key, OBJ_STRING);
176+ ShardArgs::Iterator start_key = keys.begin (), end_key = keys.end ();
177+ if (skip_dest_key) {
178+ // If destkey is only found on this shard we can return
179+ if (++start_key == end_key)
180+ return OpStatus::OK;
181+ }
182+ for (; start_key != end_key; ++start_key) {
183+ auto it = op_args.GetDbSlice ().FindReadOnly (op_args.db_cntx , *start_key, OBJ_STRING);
177184 if (it.ok ()) {
178185 string hll;
179186 it.value ()->second .GetString (&hll);
@@ -211,7 +218,7 @@ OpResult<int64_t> PFCountMulti(CmdArgList args, const CommandContext& cmd_cntx)
211218 auto cb = [&](Transaction* t, EngineShard* shard) {
212219 ShardId sid = shard->shard_id ();
213220 ShardArgs shard_args = t->GetShardArgs (shard->shard_id ());
214- auto result = ReadValues (t->GetOpArgs (shard), shard_args);
221+ auto result = ReadValues (t->GetOpArgs (shard), shard_args, false /* no dest key */ );
215222 if (result.ok ()) {
216223 hlls[sid] = std::move (result.value ());
217224 }
@@ -246,12 +253,15 @@ void PFCount(CmdArgList args, const CommandContext& cmd_cntx) {
246253OpResult<int > PFMergeInternal (CmdArgList args, Transaction* tx, SinkReplyBuilder* builder) {
247254 vector<vector<string>> hlls;
248255 hlls.resize (shard_set->size ());
256+ const string_view dest_key = ArgS (args, 0 );
257+ const ShardId dest_shard = Shard (dest_key, shard_set->size ());
249258
250259 atomic_bool success = true ;
251260 auto cb = [&](Transaction* t, EngineShard* shard) {
252261 ShardId sid = shard->shard_id ();
262+ const bool skip_dest_key = sid == dest_shard;
253263 ShardArgs shard_args = t->GetShardArgs (shard->shard_id ());
254- auto result = ReadValues (t->GetOpArgs (shard), shard_args);
264+ auto result = ReadValues (t->GetOpArgs (shard), shard_args, skip_dest_key );
255265 if (result.ok ()) {
256266 hlls[sid] = std::move (result.value ());
257267 } else {
0 commit comments