Uploaded image for project: 'C Driver'
  1. C Driver
  2. CDRIVER-3633

read pref with max_staleness_seconds may not be sent

    • Type: Icon: Bug Bug
    • Resolution: Fixed
    • Priority: Icon: Major - P3 Major - P3
    • 1.17.0-beta2, 1.17.0
    • Affects Version/s: 1.4.1
    • Component/s: libmongoc
    • Labels:
      None

      While inspecting mongoc-read-prefs.c during implementation of hedged reads, it was discovered that the C driver does not properly handle sending read preference to mongos for secondary preferred mode with a specified max_staleness_seconds.

      Prior to the hedged reads change, the server selection spec stated:

        - For mode 'secondaryPreferred', drivers MUST set the ``slaveOK`` wire protocol flag.
          If the read preference contains a non-empty ``tag_sets`` parameter,
          or ``maxStalenessSeconds`` is a positive integer, drivers MUST
          use ``$readPreference``; otherwise, drivers MUST NOT use ``$readPreference``
      

      However, the logic in the _apply_read_preferences_mongos function was never updated for the implementation of the max_staleness_seconds option.

      The logic is currently:

         if (mode == MONGOC_READ_SECONDARY_PREFERRED && bson_empty0 (tags)) {
             result->flags |= MONGOC_QUERY_SLAVE_OK;
       
          } else if (mode != MONGOC_READ_PRIMARY) {
      

      Therefore, a read preference of mode MONGOC_READ_SECONDARY_PREFERRED with a positive integer value for max_staleness_seconds will NOT be communicated to mongos as required by the spec. However, if the read preference happens to have specified the tags parameter, then correct behavior will be observed.

            Assignee:
            roberto.sanchez@mongodb.com Roberto Sanchez
            Reporter:
            roberto.sanchez@mongodb.com Roberto Sanchez
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: