Skip to content

Conversation

@lerouxb
Copy link
Contributor

@lerouxb lerouxb commented Mar 25, 2025

There's a bug https://jira.mongodb.org/browse/PRODTRIAGE-3102 where readPreferenceTags does not work with config servers. This means that if compass connects to a sharded cluster and then the user specifies something like readPreferenceTags=nodeType:ANALYTICS as part of the connection string, Compass won't be able to list the databases&collections which should appear in the sidebar.

The workaround here is to remove the tags for those commands IF we're connected to a sharded cluster AND readPreferenceTags is present.

To test this it is almost enough to just connect to any sharded cluster without any special node tags and then specify readPreferenceTags, but in that case no command will work because there aren't nodes for that cluster. If a node exists with the read preference tag then it would only be the database/collection lookups that don't work.

To test this manually, I used mongodb-runner:

(number of shards is probably irrelevant)

npx mongodb-runner start -t sharded --shards=2 --version=8.0.5

which prints the connection string, but then in order to configure sharding you have to connect to a shard manually (I found a port to connect to by just doing ps aux | grep mongos)

In my case something like mongosh "127.0.0.1:58109"

Then in mongosh:

conf = rs.conf();
conf.members[0].tags = { "nodeType": "ANALYTICS"};
rs.reconfig(conf);

Then connect to the URL you got from mongodb runner, but with some parameters added. In my case:

mongodb://127.0.0.1:21676/?retryWrites=true&readPreference=secondary&w=majority&readPreferenceTags=nodeType:ANALYTICS

Then on compass main you'll see that loading the databases/collections in the sidebar hangs until it times out.

With this branch you'll see that the collections load as expected.

@github-actions github-actions bot added the fix label Mar 25, 2025
@lerouxb lerouxb changed the title fix: set readPreference=secondaryPreferred for database&collection lookups if readPreferenceTags was set COMPASS-9111 fix: remove readPreferenceTags for database&collection lookups if the cluster is sharded and readPreferenceTags was set COMPASS-9111 Mar 25, 2025
Copy link
Collaborator

@addaleax addaleax left a comment

Choose a reason for hiding this comment

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

LGTM, only suggestion might be to add a comment referencing the COMPASS ticket just so if somebody in the future wonders why we do this, they have a way of reading the related conversations, but that's definitely optional

@lerouxb
Copy link
Contributor Author

lerouxb commented Mar 26, 2025

I added a comment near the code that references the ticket and I also added a test that uses an actual sharded database. It isn't exactly the same as the situation in the ticket since there are no secondaries and no nodes with the ANALYTICS tag in that setup, but it does recreate the situation where those database operations would timeout because it does not know about any nodes that match the tags.

@lerouxb lerouxb marked this pull request as ready for review March 26, 2025 11:17
@lerouxb
Copy link
Contributor Author

lerouxb commented Mar 26, 2025

Oh and if anyone ever wants to run the sharded docker image on an apple silicon mac:

~/test-envs % git diff
diff --git a/docker/sharded/docker-compose.yaml b/docker/sharded/docker-compose.yaml
index d5f50a7..d4e5041 100644
--- a/docker/sharded/docker-compose.yaml
+++ b/docker/sharded/docker-compose.yaml
@@ -1,9 +1,8 @@
-version: '2'
-
 services:
   mongodb-sharded:
+    platform: linux/amd64
     # TODO: https://jira.mongodb.org/browse/COMPASS-7265
-    image: 'docker.io/bitnami/mongodb-sharded:6.0.10'
+    image: 'docker.io/bitnami/mongodb-sharded:8.0.5'
     environment:
       - MONGODB_ADVERTISED_HOSTNAME=mongodb-sharded
       - MONGODB_SHARDING_MODE=mongos
@@ -11,12 +10,14 @@ services:
       - MONGODB_CFG_REPLICA_SET_NAME=cfgreplicaset
       - MONGODB_REPLICA_SET_KEY=replicasetkey123
       - MONGODB_ROOT_PASSWORD=password123
+      - EXPERIMENTAL_DOCKER_DESKTOP_FORCE_QEMU=1
     ports:
       - '28004:27017'

   mongodb-shard0:
+    platform: linux/amd64
     # TODO: https://jira.mongodb.org/browse/COMPASS-7265
-    image: 'docker.io/bitnami/mongodb-sharded:6.0.10'
+    image: 'docker.io/bitnami/mongodb-sharded:8.0.5'
     environment:
       - MONGODB_ADVERTISED_HOSTNAME=mongodb-shard0
       - MONGODB_SHARDING_MODE=shardsvr
@@ -25,10 +26,12 @@ services:
       - MONGODB_REPLICA_SET_MODE=primary
       - MONGODB_REPLICA_SET_KEY=replicasetkey123
       - MONGODB_REPLICA_SET_NAME=shard0
+      - EXPERIMENTAL_DOCKER_DESKTOP_FORCE_QEMU=1

   mongodb-cfg:
+    platform: linux/amd64
     # TODO: https://jira.mongodb.org/browse/COMPASS-7265
-    image: 'docker.io/bitnami/mongodb-sharded:6.0.10'
+    image: 'docker.io/bitnami/mongodb-sharded:8.0.5'
     environment:
       - MONGODB_ADVERTISED_HOSTNAME=mongodb-cfg
       - MONGODB_SHARDING_MODE=configsvr
@@ -36,3 +39,4 @@ services:
       - MONGODB_REPLICA_SET_MODE=primary
       - MONGODB_REPLICA_SET_KEY=replicasetkey123
       - MONGODB_REPLICA_SET_NAME=cfgreplicaset
+      - EXPERIMENTAL_DOCKER_DESKTOP_FORCE_QEMU=1

via bitnami/containers#40947 (comment)

@lerouxb lerouxb merged commit cdc93ca into main Mar 26, 2025
46 of 54 checks passed
@lerouxb lerouxb deleted the no-tags-dbs-collections branch March 26, 2025 13:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants