Uploaded image for project: 'Ruby Driver'
  1. Ruby Driver
  2. RUBY-2220

Move find command construction code into operations layer

    • Fully Compatible

      The driver currently has an operations layer that handles command construction for most commands. It appears that for find commands, some of the construction is done by code under collection/ and specifically collection/view/builder/

      {find_command,op_query}

      . There are two issues with this:

      1. The operations layer code isn't actually confined to the operations layer - some of it exists in collection code which is generally much higher level.
      2. Collection code doesn't have a connection on which a command would be executed, since this connection is acquired later in the execution flow. Because of this the command constructed by the collection code has to use server features (rather than connection features) and thus can be incorrect if a server is upgraded/downgraded between command construction and when it's dispatched.

      The second issue is a long-standing one in the driver but it is exacerbated by the work done in https://jira.mongodb.org/browse/RUBY-2110. With 2110, more commands are constructed based on the connection attributes rather than server (monitor) attributes, which specifically causes wrong command construction for the case when a server is unknown - for find commands, the collection code assumes legacy operations will be used, but when the command is sent it is constructed partially for the actual connection which could be to a modern server and the result could be a non-functioning command (op_query payload in an op_msg message).

      The workaround added in 2110 is to obtain a connection to the server in collection code when the first part of find command construction is done, and use the information from that connection to construct the command. This workaround fixes the case when a server is persistently Unknown (such as because it doesn't have a monitor due to forking) and is being queried, but does not help with the case of a server changing versions. Note that the case of server changing versions wasn't correctly handled before 2110 either, and is one of the reasons for the operations layer work in the first place.

      This ticket covers moving all wire protocol-specific command construction for find commands into the operations layer. Roughly the expected changes are:

      • Existing Find operation classes augmented or new classes created to encapsulate all data that collection code needs to specify for an operation. These should be similar to the existing top-level operation classes.
      • Wire protocol branching logic moved from collection code to operation layer. This is the logic that decides whether to construct op_query or find command, for example.
      • The workarounds added in 2110 to obtain connections to servers in collection code to construct the commands removed.

            Assignee:
            oleg.pudeyev@mongodb.com Oleg Pudeyev (Inactive)
            Reporter:
            oleg.pudeyev@mongodb.com Oleg Pudeyev (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: