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

Optimize the map of registered operations in `MozJSScriptEngine`

    • Type: Icon: Improvement Improvement
    • Resolution: Fixed
    • Priority: Icon: Major - P3 Major - P3
    • 8.0.0-rc0
    • Affects Version/s: None
    • Component/s: Internal Code
    • None
    • Service Arch
    • Fully Compatible
    • Service Arch 2024-03-04, Service Arch 2024-03-18, Service Arch 2024-04-01

      The structure is used to map operation ids to MozJS scopes, and is modified to register and unregister operations:

      class MozJSScriptEngine final : public mongo::ScriptEngine {
          ...
          Mutex _globalInterruptLock = MONGO_MAKE_LATCH("MozJSScriptEngine::_globalInterruptLock");
      
          using OpIdToScopeMap = stdx::unordered_map<unsigned, MozJSImplScope*>;
          OpIdToScopeMap _opToScopeMap;
          ...
      };
      

      We can remove this map and instead, augment each operation with a decoration that holds the MozJS scope (if registered).

      const auto d = OperationContext::declareDecoration<MozJSImplScope*>();
      

      Depending on the read/write semantics for this decoration, we may choose one of the following:

      • If it's only set/unset on the Client thread that owns the operation, then we can use the Client lock for synchronization.
      • Otherwise, we can use synchronized_value<MozJSImplScope*> as the decoration type to ensure it's not modified while being accessed for interruption.

      We can use a LockedClientCursor to navigate through all clients and interrupt their operations if needed.

            Assignee:
            amirsaman.memaripour@mongodb.com Amirsaman Memaripour
            Reporter:
            amirsaman.memaripour@mongodb.com Amirsaman Memaripour
            Votes:
            0 Vote for this issue
            Watchers:
            6 Start watching this issue

              Created:
              Updated:
              Resolved: