Uploaded image for project: 'Solr'
  1. Solr
  2. SOLR-13439

Make collection properties easier and safer to use in code

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 9.0
    • 8.2
    • SolrCloud
    • None

    Description

      (breaking this out from SOLR-13420, please read there for further background)

      Before this patch the api is quite confusing (IMHO):

      1. any code that wanted to know what the properties for a collection are could call zkStateReader.getCollectionProperties(collection) but this was a dangerous and trappy API because that was a query to zookeeper every time. If a naive user auto-completed that in their IDE without investigating, heavy use of zookeeper would ensue.
      2. To "do it right" for any code that might get called on a per-doc or per request basis one had to cause caching by registering a watcher. At which point the getCollectionProperties(collection) magically becomes safe to use, but the watcher pattern probably looks famillar induces a user who hasn't read the solr code closely to create their own cache and update it when their watcher is notified. If the caching side effect of watches isn't understood this will lead to many in-memory copies of collection properties maintained in user code.
      3. This also creates a task to be scheduled on a thread (PropsNotification) and induces an extra thread-scheduling lag before the changes can be observed by user code.
      4. The code that cares about collection properties needs to have a lifecycle tied to either a collection or something other object with an even more ephemeral life cycle such as an URP. The user now also has to remember to ensure the watch is unregistered, or there is a leak.

      After this patch

      1. Calls to getCollectionProperties(collection) are always safe to use in any code anywhere. Caching and cleanup are automatic.
      2. Code that really actually wants to know if a collection property changes so it can wake up and do something (autoscaling?) still has the option of registering a watcher that will asynchronously send them a notification.
      3. Updates can be observed sooner via getCollectionProperties with no need to wait for a thread to run. (vs a cache held in user code)

      Attachments

        1. SOLR-13439.patch
          17 kB
          Gus Heck
        2. SOLR-13439.patch
          34 kB
          Gus Heck
        3. SOLR-13439.patch
          34 kB
          Gus Heck

        Issue Links

          Activity

            People

              gus Gus Heck
              gus Gus Heck
              Votes:
              0 Vote for this issue
              Watchers:
              7 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: