sonatype-lift[bot] commented on code in PR #1585:
URL: https://github.com/apache/solr/pull/1585#discussion_r1182303050


##########
solr/solrj-zookeeper/src/java/org/apache/solr/common/cloud/ZkStateReader.java:
##########
@@ -368,10 +368,136 @@ private StatefulCollectionWatch compute(
         BiFunction<String, StatefulCollectionWatch, StatefulCollectionWatch> 
remappingFunction) {
       return statefulWatchesByCollectionName.compute(collectionName, 
remappingFunction);
     }
+
+    public boolean isWatched(String coll) {
+      return statefulWatchesByCollectionName.containsKey(coll);
+    }
   }
 
-  private static class StatefulCollectionWatch extends 
CollectionWatch<DocCollectionWatcher> {
+  private class StatefulCollectionWatch extends 
CollectionWatch<DocCollectionWatcher> {
     private DocCollection currentState;
+
+    Watcher persistentWatcher;
+
+    final String coll;
+    private final String collectionPath;
+
+    private StatefulCollectionWatch(String coll) {
+      this.coll = coll;
+      this.collectionPath = DocCollection.getCollectionPath(coll);
+    }
+
+    public void handleWatch(WatchedEvent event) {
+      if (!collectionWatches.isWatched(coll)) {
+        return;
+      }
+      log.trace("an event happened for {}, event: {}", coll, event.toString());
+      DocCollection collectionState = getCollection(coll);
+      if (collectionPath.equals(event.getPath())) {
+        DocCollection newState = null;
+        try {
+          newState = fetchCollectionState(coll, null);
+        } catch (KeeperException.SessionExpiredException
+            | KeeperException.ConnectionLossException e) {
+          log.warn("ZooKeeper watch triggered, but Solr cannot talk to ZK: ", 
e);
+        } catch (KeeperException e) {
+          log.error("exception for collection: [{}]", coll, e);
+          throw new ZooKeeperException(ErrorCode.SERVER_ERROR, "A ZK error has 
occurred", e);
+        } catch (InterruptedException e) {
+          Thread.currentThread().interrupt();
+          log.error("exception for collection: [{}]", coll, e);
+        }
+        collectionWatches.updateDocCollection(coll, newState);
+        synchronized (getUpdateLock()) {
+          constructState(Collections.singleton(coll));
+        }
+      }
+      if (collectionState != null && collectionState.isPerReplicaState()) {
+        String path = event.getPath();
+        if ((event.getType() == EventType.NodeCreated || event.getType() == 
EventType.NodeDeleted)
+                && path.length() > collectionState.getZNode().length()
+                && path.startsWith(collectionPath)) {
+          log.debug("PRS node event : {}", event.getType());
+
+          PerReplicaStates prs = collectionState.getPerReplicaStates();
+          if (prs != null) {
+            String stateStr = path.substring(collectionPath.length() + 1);
+            PerReplicaStates.State newState = 
PerReplicaStates.State.parse(stateStr);
+            PerReplicaStates.State oldState = prs.states.get(newState.replica);

Review Comment:
   <picture><img alt="16% of developers fix this issue" 
src="https://lift.sonatype.com/api/commentimage/fixrate/16/display.svg";></picture>
   
   <b>*NULL_DEREFERENCE:</b>*  object `newState` last assigned on line 425 
could be null and is dereferenced at line 426.
   
   ---
   
   <details><summary>ℹ️ Expand to see all <b>@sonatype-lift</b> 
commands</summary>
   
   You can reply with the following commands. For example, reply with 
***@sonatype-lift ignoreall*** to leave out all findings.
   | **Command** | **Usage** |
   | ------------- | ------------- |
   | `@sonatype-lift ignore` | Leave out the above finding from this PR |
   | `@sonatype-lift ignoreall` | Leave out all the existing findings from this 
PR |
   | `@sonatype-lift exclude <file\|issue\|path\|tool>` | Exclude specified 
`file\|issue\|path\|tool` from Lift findings by updating your config.toml file |
   
   **Note:** When talking to LiftBot, you need to **refresh** the page to see 
its response.
   <sub>[Click here](https://github.com/apps/sonatype-lift/installations/new) 
to add LiftBot to another repo.</sub></details>
   
   



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscr...@solr.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscr...@solr.apache.org
For additional commands, e-mail: issues-h...@solr.apache.org

Reply via email to