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

Correctly routed realtime-get through CloudSolrServer

    XMLWordPrintableJSON

Details

    • New Feature
    • Status: Open
    • Major
    • Resolution: Unresolved
    • 4.5
    • 4.9, 6.0
    • SolrCloud

    Description

      Today you cannot do realtime-gets through CloudSolrServer, because it will not route the request to the correct replica (the leader-replica of the shard where the document to be fetched lives according to routing rules)

      Doing realtime-gets from clients are important in several scenarios. For example in common optimistic locking scenario. Pseudo-code:

      public void createOrUpdateDoc(String id, ChangeInfo changes) {
          outherLoop: while(true) {
              try {
                  // Assume that document with id does not exist already
                  // Just try to store it as a new document
                  SolrInputDocument newDoc = createNewSolrInputDocument(id, changes); 
                  sendUpdateRequestToSolr(newDoc);
                  return;
              } catch (DocumentAlreadyExists e) {
                  // Ok the document already existed
                  while(true) {
                      // Fetch the existing document - realtime-get so that you do not
                      // have to wait until next commit to be able to fetch it, if the document
                      // was created/updated after last commit
                      SolrDocument fetchedDoc = realTimeGet(id);
                      // Merge the changes into the existing document
                      // Including copy of _version_ from fetchedDoc to updatedDoc
                      SolrInputDocument updatedDoc = merge(fetchedDoc, changes);
                      // Try to store the updated document
                      try {
                          sendUpdateRequestToSolr(updatedDoc);
                          return;
                      } catch (VersionConflict e) {
                          // Someone updated the doc, between my fetch and update
                          // Ignore, just take another round in the inner while(true)-loop
                      } catch (DocumentDoesNotExist e) {
                          // Someone deleted the document since when I tried to
                          // create it as a new document the first time
                          // Will create it again by taking another round in outher
                          // while(true)-loop
                          continue outherLoop;
                      }
                  }
              }
          }
      }
      

      Sorry if the code is not perfect, but I just wrote it directly here - I sure you get the idea.

      I would like to enable realtime-get through CloudSolrServer in order to be able to do scenarios as e.g. the one shown above

      Attachments

        1. SOLR-5360.patch
          14 kB
          Per Steffensen

        Activity

          People

            steff1193 Per Steffensen
            steff1193 Per Steffensen
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

              Created:
              Updated: