You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@solr.apache.org by an...@apache.org on 2022/06/10 20:14:33 UTC

[solr-sandbox] branch crossdc-wip updated: Docs and enable flag. (#22)

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

anshum pushed a commit to branch crossdc-wip
in repository https://gitbox.apache.org/repos/asf/solr-sandbox.git


The following commit(s) were added to refs/heads/crossdc-wip by this push:
     new ba401a5  Docs and enable flag. (#22)
ba401a5 is described below

commit ba401a5fcc78512adb214bf1fecde560ffcbe696
Author: Mark Robert Miller <ma...@apache.org>
AuthorDate: Fri Jun 10 15:14:28 2022 -0500

    Docs and enable flag. (#22)
---
 CROSSDC.md                                         |  0
 .../MirroringUpdateRequestProcessorFactory.java    | 31 +++++++++++++++++++---
 .../configs/cloud-minimal/conf/solrconfig.xml      |  2 +-
 3 files changed, 29 insertions(+), 4 deletions(-)

diff --git a/CROSSDC.md b/CROSSDC.md
new file mode 100644
index 0000000..e69de29
diff --git a/crossdc-producer/src/main/java/org/apache/solr/update/processor/MirroringUpdateRequestProcessorFactory.java b/crossdc-producer/src/main/java/org/apache/solr/update/processor/MirroringUpdateRequestProcessorFactory.java
index 45d5e6b..b1b894e 100644
--- a/crossdc-producer/src/main/java/org/apache/solr/update/processor/MirroringUpdateRequestProcessorFactory.java
+++ b/crossdc-producer/src/main/java/org/apache/solr/update/processor/MirroringUpdateRequestProcessorFactory.java
@@ -58,6 +58,8 @@ public class MirroringUpdateRequestProcessorFactory extends UpdateRequestProcess
         implements SolrCoreAware, UpdateRequestProcessorFactory.RunAlways {
 
     private static final Logger log = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
+    public static final NoOpUpdateRequestProcessor NO_OP_UPDATE_REQUEST_PROCESSOR =
+        new NoOpUpdateRequestProcessor();
 
     // Flag for mirroring requests
     public static String SERVER_SHOULD_MIRROR = "shouldMirror";
@@ -67,9 +69,16 @@ public class MirroringUpdateRequestProcessorFactory extends UpdateRequestProcess
     private String topicName;
     private String bootstrapServers;
 
+    private boolean enabled = true;
+
     @Override
     public void init(final NamedList args) {
         super.init(args);
+        Boolean enabled = args.getBooleanArg("enabled");
+
+        if (enabled != null && !enabled) {
+            this.enabled = false;
+        }
 
         topicName = args._getStr("topicName", null);
         bootstrapServers = args._getStr("bootstrapServers", null);
@@ -94,10 +103,14 @@ public class MirroringUpdateRequestProcessorFactory extends UpdateRequestProcess
 
     @Override
     public void inform(SolrCore core) {
-        log.info("KafkaRequestMirroringHandler inform");
+        log.info("KafkaRequestMirroringHandler inform enabled={}", this.enabled);
+
+        if (!enabled) {
+            return;
+        }
 
         try {
-            if ((topicName == null || topicName.isBlank()) || (bootstrapServers == null || bootstrapServers.isBlank()) && core.getCoreContainer().getZkController()
+            if (((topicName == null || topicName.isBlank()) || (bootstrapServers == null || bootstrapServers.isBlank())) && core.getCoreContainer().getZkController()
                 .getZkClient().exists(CrossDcConf.CROSSDC_PROPERTIES, true)) {
                 byte[] data = core.getCoreContainer().getZkController().getZkClient().getData("/crossdc.properties", null, null, true);
                 Properties props = new Properties();
@@ -148,8 +161,13 @@ public class MirroringUpdateRequestProcessorFactory extends UpdateRequestProcess
     }
 
     @Override
-    public MirroringUpdateProcessor getInstance(final SolrQueryRequest req, final SolrQueryResponse rsp,
+    public UpdateRequestProcessor getInstance(final SolrQueryRequest req, final SolrQueryResponse rsp,
                                                 final UpdateRequestProcessor next) {
+
+        if (!enabled) {
+            return NO_OP_UPDATE_REQUEST_PROCESSOR;
+        }
+
         // if the class fails to initialize
         if (mirroringHandler == null) {
             throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, "mirroringHandler is null");
@@ -191,4 +209,11 @@ public class MirroringUpdateRequestProcessorFactory extends UpdateRequestProcess
                 DistribPhase.parseParam(req.getParams().get(DISTRIB_UPDATE_PARAM)), doMirroring ? mirroringHandler : null);
     }
 
+    private static class NoOpUpdateRequestProcessor extends UpdateRequestProcessor {
+        NoOpUpdateRequestProcessor() {
+            super(null);
+        }
+    }
+
+
 }
\ No newline at end of file
diff --git a/crossdc-producer/src/test/resources/configs/cloud-minimal/conf/solrconfig.xml b/crossdc-producer/src/test/resources/configs/cloud-minimal/conf/solrconfig.xml
index 6917e48..76e75ac 100644
--- a/crossdc-producer/src/test/resources/configs/cloud-minimal/conf/solrconfig.xml
+++ b/crossdc-producer/src/test/resources/configs/cloud-minimal/conf/solrconfig.xml
@@ -110,6 +110,7 @@
 
   <updateRequestProcessorChain  name="mirrorUpdateChain" default="true">
     <processor class="org.apache.solr.update.processor.MirroringUpdateRequestProcessorFactory">
+      <bool name="enabled">${enabled:true}</bool>
       <str name="bootstrapServers">${bootstrapServers:}</str>
       <str name="topicName">${topicName:}</str>
     </processor>
@@ -118,4 +119,3 @@
   </updateRequestProcessorChain>
 
 </config>
-