Uploaded image for project: 'Core Server'
  1. Core Server
  2. SERVER-48769

Shell does not respect read preference in connection string

    • Type: Icon: Bug Bug
    • Resolution: Gone away
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: 4.4.0-rc9
    • Component/s: Shell
    • Labels:
    • Server Tooling & Methods
    • ALL
    • Hide

      In on terminal, start a replset with 3 nodes.

      $ mongo-4.4.0 --nodb
      MongoDB shell version v4.4.0-rc9
      > var r = ReplSetTest({name: "TestRepl", nodes: 3}); r.startSet(); r.initiate();
      

      In another terminal, start a mongo shell with read preference secondary in the URI. The prompt shows it connects to the primary.

      $ mongo-4.4.0 --host "mongodb://localhost:20000,localhost:20001,localhost:20002/?replicaSet=TestRepl&readPreference=secondary"
      MongoDB shell version v4.4.0-rc9
      connecting to: mongodb://localhost:20000,localhost:20001,localhost:20002/?compressors=disabled&gssapiServiceName=mongodb&readPreference=secondary&replicaSet=TestRepl
      Implicit session: session { "id" : UUID("cd5cff0a-7690-4b46-b094-fa6e0be01e1b") }
      MongoDB server version: 0.0.0
      WARNING: shell and server versions do not match
      ---
      The server generated these startup warnings when booting:
              2020-06-11T19:32:29.034-04:00: Using the XFS filesystem is strongly recommended with the WiredTiger storage engine. See http://dochub.mongodb.org/core/prodnotes-filesystem
              2020-06-11T19:32:29.958-04:00: Access control is not enabled for the database. Read and write access to data and configuration is unrestricted
              2020-06-11T19:32:29.959-04:00: You are running on a NUMA machine. We suggest launching mongod like this to avoid performance problems: numactl --interleave=all mongod [other options]
              2020-06-11T19:32:29.960-04:00: Soft rlimits too low
              2020-06-11T19:32:29.960-04:00:         currentValue: 1024
              2020-06-11T19:32:29.960-04:00:         recommendedMinimum: 64000
      ---
      ---
              Enable MongoDB's free cloud-based monitoring service, which will then receive and display
              metrics about your deployment (disk utilization, CPU, operation statistics, etc).
      
              The monitoring data will be available on a MongoDB website with a unique URL accessible to you
              and anyone you share the URL with. MongoDB may use this information to make product
              improvements and to suggest MongoDB products and deployment options to you.
      
              To enable free monitoring, run the following command: db.enableFreeMonitoring()
              To permanently disable this reminder, run the following command: db.disableFreeMonitoring()
      ---
      TestRepl:PRIMARY>
      
      Show
      In on terminal, start a replset with 3 nodes. $ mongo-4.4.0 --nodb MongoDB shell version v4.4.0-rc9 > var r = ReplSetTest({name: "TestRepl", nodes: 3}); r.startSet(); r.initiate(); In another terminal, start a mongo shell with read preference secondary in the URI. The prompt shows it connects to the primary. $ mongo-4.4.0 --host "mongodb://localhost:20000,localhost:20001,localhost:20002/?replicaSet=TestRepl&readPreference=secondary" MongoDB shell version v4.4.0-rc9 connecting to: mongodb://localhost:20000,localhost:20001,localhost:20002/?compressors=disabled&gssapiServiceName=mongodb&readPreference=secondary&replicaSet=TestRepl Implicit session: session { "id" : UUID("cd5cff0a-7690-4b46-b094-fa6e0be01e1b") } MongoDB server version: 0.0.0 WARNING: shell and server versions do not match --- The server generated these startup warnings when booting: 2020-06-11T19:32:29.034-04:00: Using the XFS filesystem is strongly recommended with the WiredTiger storage engine. See http://dochub.mongodb.org/core/prodnotes-filesystem 2020-06-11T19:32:29.958-04:00: Access control is not enabled for the database. Read and write access to data and configuration is unrestricted 2020-06-11T19:32:29.959-04:00: You are running on a NUMA machine. We suggest launching mongod like this to avoid performance problems: numactl --interleave=all mongod [other options] 2020-06-11T19:32:29.960-04:00: Soft rlimits too low 2020-06-11T19:32:29.960-04:00: currentValue: 1024 2020-06-11T19:32:29.960-04:00: recommendedMinimum: 64000 --- --- Enable MongoDB's free cloud-based monitoring service, which will then receive and display metrics about your deployment (disk utilization, CPU, operation statistics, etc). The monitoring data will be available on a MongoDB website with a unique URL accessible to you and anyone you share the URL with. MongoDB may use this information to make product improvements and to suggest MongoDB products and deployment options to you. To enable free monitoring, run the following command: db.enableFreeMonitoring() To permanently disable this reminder, run the following command: db.disableFreeMonitoring() --- TestRepl:PRIMARY>

      As described in the steps to reproduce, the shell failed to connect to a secondary even though the connection string specifies read preference "secondary" according to the documentation.

      URI option support isn't consistent and user-friendly in the shell. Some URI options are supported. For example a wrong "replicaSet" option will be detected as it fails to connect. However read preference is ignored silently. Initially I thought my options were wrong or read preference has to be given together with "replicaSet" or the database was misconfigured when I tried to connect the data warehouse not owned by my team. Misspelling an option is also a silent error. For example, "replSet" option will be ignored silently.

      The shell seems the easiest way to try out read preferences settings, so I feel the lack of support is a bug. As least, the unsupported or unknown URI options should be an explicit error.

            Assignee:
            backlog-server-stm Backlog - Server Tooling and Methods (STM) (Inactive)
            Reporter:
            siyuan.zhou@mongodb.com Siyuan Zhou
            Votes:
            1 Vote for this issue
            Watchers:
            7 Start watching this issue

              Created:
              Updated:
              Resolved: