You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by ma...@apache.org on 2020/09/02 19:39:46 UTC

[lucene-solr] branch reference_impl_dev updated: @714 One more try to beat this stop watching collection we want to use race.

This is an automated email from the ASF dual-hosted git repository.

markrmiller pushed a commit to branch reference_impl_dev
in repository https://gitbox.apache.org/repos/asf/lucene-solr.git


The following commit(s) were added to refs/heads/reference_impl_dev by this push:
     new 96d682b  @714 One more try to beat this stop watching collection we want to use race.
96d682b is described below

commit 96d682b143c72bf09c28d2addacb86f717b61ad4
Author: markrmiller@gmail.com <ma...@gmail.com>
AuthorDate: Wed Sep 2 14:38:52 2020 -0500

    @714 One more try to beat this stop watching collection we want to use race.
---
 .../java/org/apache/solr/cloud/ZkController.java   | 12 +++++-------
 .../src/java/org/apache/solr/core/SolrCore.java    | 22 ++++++++++++++++------
 2 files changed, 21 insertions(+), 13 deletions(-)

diff --git a/solr/core/src/java/org/apache/solr/cloud/ZkController.java b/solr/core/src/java/org/apache/solr/cloud/ZkController.java
index fe8ca82..82d1df3 100644
--- a/solr/core/src/java/org/apache/solr/cloud/ZkController.java
+++ b/solr/core/src/java/org/apache/solr/cloud/ZkController.java
@@ -1448,6 +1448,10 @@ public class ZkController implements Closeable {
     return zkClient.exists(path);
   }
 
+  public void registerUnloadWatcher(String collection, String shardId, String coreNodeName, String name) {
+    zkStateReader.registerDocCollectionWatcher(collection,
+        new UnloadCoreOnDeletedWatcher(coreNodeName, shardId, name));
+  }
 
   /**
    * Register shard with ZooKeeper.
@@ -2112,12 +2116,6 @@ public class ZkController implements Closeable {
 
     String coreNodeName = getCoreNodeName(cd);
 
-    // the watcher is added to a set so multiple calls of this method will left only one watcher
-    zkStateReader.registerCore(cloudDesc.getCollectionName());
-    // the watcher is added to a set so multiple calls of this method will left only one watcher
-    zkStateReader.registerDocCollectionWatcher(cloudDesc.getCollectionName(),
-        new UnloadCoreOnDeletedWatcher(coreNodeName, cloudDesc.getShardId(), cd.getName()));
-
     // before becoming available, make sure we are not live and active
     // this also gets us our assigned shard id if it was not specified
     try {
@@ -2785,7 +2783,7 @@ public class ZkController implements Closeable {
   }
 
   /** @lucene.internal */
-  class UnloadCoreOnDeletedWatcher implements DocCollectionWatcher {
+  public class UnloadCoreOnDeletedWatcher implements DocCollectionWatcher {
     String coreNodeName;
     String shard;
     String coreName;
diff --git a/solr/core/src/java/org/apache/solr/core/SolrCore.java b/solr/core/src/java/org/apache/solr/core/SolrCore.java
index cee80a0..1c3205a 100644
--- a/solr/core/src/java/org/apache/solr/core/SolrCore.java
+++ b/solr/core/src/java/org/apache/solr/core/SolrCore.java
@@ -79,6 +79,7 @@ import org.apache.lucene.store.LockObtainFailedException;
 import org.apache.solr.client.solrj.impl.BinaryResponseParser;
 import org.apache.solr.cloud.CloudDescriptor;
 import org.apache.solr.cloud.RecoveryStrategy;
+import org.apache.solr.cloud.ZkController;
 import org.apache.solr.cloud.ZkSolrResourceLoader;
 import org.apache.solr.common.AlreadyClosedException;
 import org.apache.solr.common.ParWork;
@@ -1082,6 +1083,13 @@ public final class SolrCore implements SolrInfoBean, Closeable {
       if (coreContainer.isZooKeeperAware()) {
         // make sure we see our shard first - these tries to cover a surprising race where we don't find our shard in the clusterstate
         // in the below bufferUpdatesIfConstructing call
+        // make sure we don't stop watching our own collection after a collection delete -> create
+        CloudDescriptor cloudDesc = coreDescriptor.getCloudDescriptor();
+        // the watcher is added to a set so multiple calls of this method will left only one watcher
+        coreContainer.getZkController().getZkStateReader().registerCore(cloudDesc.getCollectionName());
+        // the watcher is added to a set so multiple calls of this method will left only one watcher
+        coreContainer.getZkController().registerUnloadWatcher(cloudDesc.getCollectionName(), cloudDesc.getShardId(), cloudDesc.getCoreNodeName(), cd.getName());
+
         coreContainer.getZkController().getZkStateReader().waitForState(coreDescriptor.getCollectionName(),
             5, TimeUnit.SECONDS, (l,c) -> c != null && c.getSlice(coreDescriptor.getCloudDescriptor().getShardId()) != null);
       }
@@ -1433,12 +1441,7 @@ public final class SolrCore implements SolrInfoBean, Closeable {
       factory = resourceLoader.newInstance(info.className, CodecFactory.class, Utils.getSolrSubPackage(CodecFactory.class.getPackageName()));
       factory.init(info.initArgs);
     } else {
-      factory = new CodecFactory() {
-        @Override
-        public Codec getCodec() {
-          return Codec.getDefault();
-        }
-      };
+      factory = new MyCodecFactory();
     }
     if (factory instanceof SolrCoreAware) {
       // CodecFactory needs SolrCore before inform() is called on all registered
@@ -3351,4 +3354,11 @@ public final class SolrCore implements SolrInfoBean, Closeable {
       }
     }
   }
+
+  private static class MyCodecFactory extends CodecFactory {
+    @Override
+    public Codec getCodec() {
+      return Codec.getDefault();
+    }
+  }
 }