mongo
mongo copied to clipboard
SERVER-41854 Add meta projection $shardName.
I have added a new stage called ShardNameStage
to add shard name to a $meta
projection. It made sense to meld the functionality of the existing stages ShardFilterStage
and TextOrStage
into ShardNameStage
and to modify it to output the current shard name. This might be an incorrect route for implementation, please provide guidance.
To start sharded instances:
mlaunch --replicaset --sharded tic tac toe --port 27027 --binarypath ~/src/mongo/
mlaunch start
mlaunch kill
use example;
sh.enableSharding("example");
db.items.ensureIndex({ a: "hashed" });
sh.shardCollection("example.items", { a: "hashed" });
for (var i = 0; i < 100; i++) db.items.insert({ a: i });
db.items.find({}, { shard: { $meta: "shardName" } }).sort({ a: 1 });
{ "_id" : 1, "a" : 1, "foo" : 1, "shard" : "toe" }
{ "_id" : 5, "a" : 5, "foo" : 5, "shard" : "toe" }
{ "_id" : 2, "a" : 2, "foo" : 2, "shard" : "tic" }
{ "_id" : 3, "a" : 3, "foo" : 3, "shard" : "tic" }
{ "_id" : 4, "a" : 4, "foo" : 4, "shard" : "tic" }
I have tested it locally with mlaunch. There are no unit tests in this PR as of now, as I might be completely lost while implementing it. If functionality is as expected and modifications fit or be made to fit the expected architecture, I can add some unit tests.
Thanks for the pull request! We'll look into it.
Hi @dstorch,
Thank you for the detailed and helpful review.
I am interested in making the necessary changes to this PR after the rewriting of the implementation of projection execution is complete. This PR was already created when you offered to suggest areas to work on in SERVER-14423.
I will try to get this mergeable if there are not too many conflicts. Otherwise, I would prefer to wait until the rewrite is complete.
Also, I am open to other mentored tasks that can be completed in less time than the current PR.
Cheers, Kerem
Merge conflicts are resolved now, without resolving any of your comments.
Hi @dstorch,
I have removed the ShardNameStage
and moved the functionality to the ShardFilterStage
. Now the ShardingFilterNode
constructor has a wantShardName
parameter - not sure if this is allowed.
The ShardNamer
interface and implementation are removed, new code does not use a ScopedCollectionMetadata
instance anymore.
In pipeline_d.cpp
, the createRandomCursorExecutor
function, I could not find an object that would give access to CanonicalQuery::metadataDeps
or ShardingFilterNode::wantShardName
so wantShardName
parameter is set to false
in ShardFilterStage
constructors.
It is not clear to me if ProjectionExec
code could be moved to ParsedAggregationProjection
now or only after the rewriting by the mongo team.
Also, if you could give some pointers on what kind of tests to write first, it would be very helpful.
Maybe this year this PR will get some love :) @dstorch