Enhance clarity of CSOT implementation within the driver

XMLWordPrintableJSON

    • Type: Improvement
    • Resolution: Unresolved
    • Priority: Unknown
    • None
    • Affects Version/s: None
    • Component/s: None
    • Java Drivers
    • Hide

      1. What would you like to communicate to the user about this feature?
      2. Would you like the user to see examples of the syntax and/or executable code and its output?
      3. Which versions of the driver/connector does this apply to?

      Show
      1. What would you like to communicate to the user about this feature? 2. Would you like the user to see examples of the syntax and/or executable code and its output? 3. Which versions of the driver/connector does this apply to?
    • None
    • None
    • None
    • None
    • None
    • None

      Description: Recent code walkthrough session has identified specific improvements to enhance the clarity and predictability of the Client-Side Operations Timeout (CSOT). This task will address naming inconsistencies and refine behavior across various components, improving readability and maintainability.

      Details of the enhancements:

      • Introduce copyAndReset() in TimeoutContext: This method will replace resetTimeoutIfPresent() to make the reset behavior more intuitive and clearer. Currently, TimeoutContext employs two approaches:
      • copy() creates a new TimeoutContext and then the timeout is reset using resetTimeoutIfPresent().
      • resetTimeoutIfPresent() is sometimes used alone without a prior copy, leading to mutable state changes. The new copyAndReset() method will create a copied context and reset the timeout in one immutable operation.
      • Rename TimeoutContext#disableMaxTimeOverride to disableMaxTime, accurately reflecting that it disables maxTime entirely for command currently being executed.
      • Modify operations to reset TimeoutContext:  operations should ensure that TimeoutContext is reverted to its initial state post-execution instead of relying on subsequent operations like in a situation when AbortTransactionOperation resets maxTimeMS on TimeoutContext after CommitTransactionOperation#execute. This adjustment will prevent confusing behavior.
      • Rename resetToDefaultMaxTime() to a name that more clearly describes its functionality.
      • We should pass TimeoutContext as method parameter instead of saving it in a field wherever it is possible (Cursor could be an exception). It is easier to reason about stateless code flow, where TimeoutContext limits the execution of particular method. 
      • We should consider creating specific subclasses of TimeoutContext, for example ServerSelectionTimeoutContext as it would give us better understanding of what this timeout caps.

      Expected Outcomes:

      • Clearer method names that directly convey their functionality.
      • Simplified and more predictable state management within CSOT.
      • Enhanced maintainability and readability of the codebase.

      Acceptance Criteria:

      • All mentioned methods are renamed and the new names are reflected across the codebase.
      • TimeoutContext adjustments are implemented, and their usage is standardized in relevant parts of the code.
      • Documentation and code comments are updated to reflect these changes.

              Assignee:
              Slav Babanin
              Reporter:
              Slav Babanin
              Ross Lawley
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

                Created:
                Updated: