Introducing InternalMongoClientSettings to Reduce global mutable state

XMLWordPrintableJSON

    • Type: Task
    • Resolution: Unresolved
    • Priority: Minor - P4
    • None
    • Affects Version/s: None
    • Component/s: Internal
    • None
    • Java Drivers
    • None
    • None
    • None
    • None
    • None
    • None

      Following the discussion in https://github.com/mongodb/mongo-java-driver/pull/1852#discussion_r2658653809 and the upcoming work in backpressure, which requires another global variable to control jitter. It becomes necessary to provide a more Thread-safe and scoped per-client approach to group all internal settings.

      The introduced InternalMongoClientSettings should include existing InternalConnectionPoolSettings, remove the usage of InternalStreamConnection.setRecordEverything by adding a recordEverything setting as well as any upcoming internal settings we don't want to expose as public API or as global state.

      Usage example:

      // OLD WAY (deprecated):
      InternalStreamConnection.setRecordEverything(true);
      try (MongoClient client = MongoClients.create(settings)) {
        // test code
       } finally {
         InternalStreamConnection.setRecordEverything(false);
       }
      
      // NEW WAY (recommended)
      InternalMongoClientSettings internalSettings = InternalMongoClientSettings.builder()
              .recordEverything(true)
              .build();
       try (MongoClient client = InternalMongoClients.create(settings, internalSettings)) {
              // test code - no cleanup needed, setting is scoped to this client
       }
      

            Assignee:
            Nabil Hachicha
            Reporter:
            Nabil Hachicha
            None
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated: