diff --git a/solr/CHANGES.txt b/solr/CHANGES.txt index 56a5f3b3e83..c9506f91a11 100644 --- a/solr/CHANGES.txt +++ b/solr/CHANGES.txt @@ -168,6 +168,8 @@ Other Changes * SOLR-8929: Add an idea module for solr/server to enable launching start.jar (Scott Blum, Steve Rowe) +* SOLR-9037: Replace multiple "/replication" strings with one static constant. (Christine Poerschke) + ================== 6.0.0 ================== Consult the LUCENE_CHANGES.txt file for additional, low level, changes in this release diff --git a/solr/core/src/java/org/apache/solr/cloud/RecoveryStrategy.java b/solr/core/src/java/org/apache/solr/cloud/RecoveryStrategy.java index 61b3f90b839..abd00aef19a 100644 --- a/solr/core/src/java/org/apache/solr/cloud/RecoveryStrategy.java +++ b/solr/core/src/java/org/apache/solr/cloud/RecoveryStrategy.java @@ -72,8 +72,6 @@ public class RecoveryStrategy extends Thread implements Closeable { private static final int WAIT_FOR_UPDATES_WITH_STALE_STATE_PAUSE = Integer.getInteger("solr.cloud.wait-for-updates-with-stale-state-pause", 7000); private static final int MAX_RETRIES = 500; private static final int STARTING_RECOVERY_DELAY = 5000; - - private static final String REPLICATION_HANDLER = "/replication"; public static interface RecoveryListener { public void recovered(); @@ -143,12 +141,12 @@ public class RecoveryStrategy extends Thread implements Closeable { commitOnLeader(leaderUrl); // use rep handler directly, so we can do this sync rather than async - SolrRequestHandler handler = core.getRequestHandler(REPLICATION_HANDLER); + SolrRequestHandler handler = core.getRequestHandler(ReplicationHandler.PATH); ReplicationHandler replicationHandler = (ReplicationHandler) handler; if (replicationHandler == null) { throw new SolrException(ErrorCode.SERVICE_UNAVAILABLE, - "Skipping recovery, no " + REPLICATION_HANDLER + " handler found"); + "Skipping recovery, no " + ReplicationHandler.PATH + " handler found"); } ModifiableSolrParams solrParams = new ModifiableSolrParams(); diff --git a/solr/core/src/java/org/apache/solr/handler/IndexFetcher.java b/solr/core/src/java/org/apache/solr/handler/IndexFetcher.java index 0686f5ba696..4687b7207ec 100644 --- a/solr/core/src/java/org/apache/solr/handler/IndexFetcher.java +++ b/solr/core/src/java/org/apache/solr/handler/IndexFetcher.java @@ -189,9 +189,9 @@ public class IndexFetcher { if (masterUrl == null) throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, "'masterUrl' is required for a slave"); - if (masterUrl.endsWith("/replication")) { + if (masterUrl.endsWith(ReplicationHandler.PATH)) { masterUrl = masterUrl.substring(0, masterUrl.length()-12); - LOG.warn("'masterUrl' must be specified without the /replication suffix"); + LOG.warn("'masterUrl' must be specified without the "+ReplicationHandler.PATH+" suffix"); } this.masterUrl = masterUrl; @@ -214,7 +214,7 @@ public class IndexFetcher { ModifiableSolrParams params = new ModifiableSolrParams(); params.set(COMMAND, CMD_INDEX_VERSION); params.set(CommonParams.WT, JAVABIN); - params.set(CommonParams.QT, "/replication"); + params.set(CommonParams.QT, ReplicationHandler.PATH); QueryRequest req = new QueryRequest(params); // TODO modify to use shardhandler @@ -236,7 +236,7 @@ public class IndexFetcher { params.set(COMMAND, CMD_GET_FILE_LIST); params.set(GENERATION, String.valueOf(gen)); params.set(CommonParams.WT, JAVABIN); - params.set(CommonParams.QT, "/replication"); + params.set(CommonParams.QT, ReplicationHandler.PATH); QueryRequest req = new QueryRequest(params); // TODO modify to use shardhandler @@ -1583,7 +1583,7 @@ public class IndexFetcher { // //the method is command=filecontent params.set(COMMAND, CMD_GET_FILE); params.set(GENERATION, Long.toString(indexGen)); - params.set(CommonParams.QT, "/replication"); + params.set(CommonParams.QT, ReplicationHandler.PATH); //add the version to download. This is used to reserve the download params.set(solrParamOutput, fileName); if (useInternalCompression) { @@ -1716,7 +1716,7 @@ public class IndexFetcher { ModifiableSolrParams params = new ModifiableSolrParams(); params.set(COMMAND, CMD_DETAILS); params.set("slave", false); - params.set(CommonParams.QT, "/replication"); + params.set(CommonParams.QT, ReplicationHandler.PATH); // TODO use shardhandler try (HttpSolrClient client = new HttpSolrClient.Builder(masterUrl).withHttpClient(myHttpClient).build()) { diff --git a/solr/core/src/java/org/apache/solr/handler/ReplicationHandler.java b/solr/core/src/java/org/apache/solr/handler/ReplicationHandler.java index b8c9692d2c9..4a4b7ba78f5 100644 --- a/solr/core/src/java/org/apache/solr/handler/ReplicationHandler.java +++ b/solr/core/src/java/org/apache/solr/handler/ReplicationHandler.java @@ -117,6 +117,8 @@ import static org.apache.solr.common.params.CommonParams.NAME; */ public class ReplicationHandler extends RequestHandlerBase implements SolrCoreAware { + public static final String PATH = "/replication"; + private static final Logger LOG = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass()); SolrCore core; diff --git a/solr/core/src/test/org/apache/solr/cloud/BasicDistributedZk2Test.java b/solr/core/src/test/org/apache/solr/cloud/BasicDistributedZk2Test.java index 61b9901f946..47d8212e045 100644 --- a/solr/core/src/test/org/apache/solr/cloud/BasicDistributedZk2Test.java +++ b/solr/core/src/test/org/apache/solr/cloud/BasicDistributedZk2Test.java @@ -42,6 +42,7 @@ import org.apache.solr.common.cloud.ZkStateReader; import org.apache.solr.common.params.CommonParams; import org.apache.solr.common.params.ModifiableSolrParams; import org.apache.solr.handler.CheckBackupStatus; +import org.apache.solr.handler.ReplicationHandler; import org.junit.Test; /** @@ -400,7 +401,7 @@ public class BasicDistributedZk2Test extends AbstractFullDistribZkTestBase { // try a backup command final HttpSolrClient client = (HttpSolrClient) shardToJetty.get(SHARD2).get(0).client.solrClient; ModifiableSolrParams params = new ModifiableSolrParams(); - params.set("qt", "/replication"); + params.set("qt", ReplicationHandler.PATH); params.set("command", "backup"); Path location = createTempDir(); location = FilterPath.unwrap(location).toRealPath(); diff --git a/solr/core/src/test/org/apache/solr/cloud/DistribDocExpirationUpdateProcessorTest.java b/solr/core/src/test/org/apache/solr/cloud/DistribDocExpirationUpdateProcessorTest.java index 6be317fd0d9..eaf2460ccd6 100644 --- a/solr/core/src/test/org/apache/solr/cloud/DistribDocExpirationUpdateProcessorTest.java +++ b/solr/core/src/test/org/apache/solr/cloud/DistribDocExpirationUpdateProcessorTest.java @@ -20,6 +20,7 @@ import org.apache.lucene.util.LuceneTestCase.Slow; import org.apache.solr.client.solrj.SolrServerException; import org.apache.solr.client.solrj.request.QueryRequest; import org.apache.solr.common.util.NamedList; +import org.apache.solr.handler.ReplicationHandler; import org.apache.solr.common.params.SolrParams; import org.apache.solr.common.params.ModifiableSolrParams; @@ -140,7 +141,7 @@ public class DistribDocExpirationUpdateProcessorTest extends AbstractFullDistrib ModifiableSolrParams params = new ModifiableSolrParams(); params.set("command","indexversion"); params.set("_trace","getIndexVersion"); - params.set("qt","/replication"); + params.set("qt",ReplicationHandler.PATH); QueryRequest req = new QueryRequest(params); NamedList res = replicaRunner.client.solrClient.request(req); diff --git a/solr/core/src/test/org/apache/solr/core/SolrCoreTest.java b/solr/core/src/test/org/apache/solr/core/SolrCoreTest.java index 200935a107c..9e6029abe4b 100644 --- a/solr/core/src/test/org/apache/solr/core/SolrCoreTest.java +++ b/solr/core/src/test/org/apache/solr/core/SolrCoreTest.java @@ -18,6 +18,7 @@ package org.apache.solr.core; import org.apache.solr.SolrTestCaseJ4; import org.apache.solr.common.util.ExecutorUtil; +import org.apache.solr.handler.ReplicationHandler; import org.apache.solr.handler.RequestHandlerBase; import org.apache.solr.handler.component.QueryComponent; import org.apache.solr.handler.component.SpellCheckComponent; @@ -96,7 +97,7 @@ public class SolrCoreTest extends SolrTestCaseJ4 { ++ihCount; assertEquals(pathToClassMap.get("/config"), "solr.SolrConfigHandler"); ++ihCount; assertEquals(pathToClassMap.get("/export"), "solr.SearchHandler"); ++ihCount; assertEquals(pathToClassMap.get("/get"), "solr.RealTimeGetHandler"); - ++ihCount; assertEquals(pathToClassMap.get("/replication"), "solr.ReplicationHandler"); + ++ihCount; assertEquals(pathToClassMap.get(ReplicationHandler.PATH), "solr.ReplicationHandler"); ++ihCount; assertEquals(pathToClassMap.get("/schema"), "solr.SchemaHandler"); ++ihCount; assertEquals(pathToClassMap.get("/sql"), "solr.SQLHandler"); ++ihCount; assertEquals(pathToClassMap.get("/stream"), "solr.StreamHandler"); diff --git a/solr/core/src/test/org/apache/solr/handler/CheckBackupStatus.java b/solr/core/src/test/org/apache/solr/handler/CheckBackupStatus.java index ab1d553abcd..706a2fe554a 100644 --- a/solr/core/src/test/org/apache/solr/handler/CheckBackupStatus.java +++ b/solr/core/src/test/org/apache/solr/handler/CheckBackupStatus.java @@ -44,7 +44,7 @@ public class CheckBackupStatus extends SolrTestCaseJ4 { } public void fetchStatus() throws IOException { - String masterUrl = client.getBaseURL() + "/replication?command=" + ReplicationHandler.CMD_DETAILS; + String masterUrl = client.getBaseURL() + ReplicationHandler.PATH + "?command=" + ReplicationHandler.CMD_DETAILS; response = client.getHttpClient().execute(new HttpGet(masterUrl), new BasicResponseHandler()); if(pException.matcher(response).find()) { fail("Failed to create backup"); diff --git a/solr/core/src/test/org/apache/solr/handler/TestReplicationHandler.java b/solr/core/src/test/org/apache/solr/handler/TestReplicationHandler.java index ec5280c73e7..c7ef546180c 100644 --- a/solr/core/src/test/org/apache/solr/handler/TestReplicationHandler.java +++ b/solr/core/src/test/org/apache/solr/handler/TestReplicationHandler.java @@ -212,7 +212,7 @@ public class TestReplicationHandler extends SolrTestCaseJ4 { ModifiableSolrParams params = new ModifiableSolrParams(); params.set("command","details"); params.set("_trace","getDetails"); - params.set("qt","/replication"); + params.set("qt",ReplicationHandler.PATH); QueryRequest req = new QueryRequest(params); NamedList res = s.request(req); @@ -233,7 +233,7 @@ public class TestReplicationHandler extends SolrTestCaseJ4 { ModifiableSolrParams params = new ModifiableSolrParams(); params.set("command","commits"); params.set("_trace","getCommits"); - params.set("qt","/replication"); + params.set("qt",ReplicationHandler.PATH); QueryRequest req = new QueryRequest(params); NamedList res = s.request(req); @@ -249,7 +249,7 @@ public class TestReplicationHandler extends SolrTestCaseJ4 { ModifiableSolrParams params = new ModifiableSolrParams(); params.set("command","indexversion"); params.set("_trace","getIndexVersion"); - params.set("qt","/replication"); + params.set("qt",ReplicationHandler.PATH); QueryRequest req = new QueryRequest(params); NamedList res = s.request(req); @@ -281,6 +281,11 @@ public class TestReplicationHandler extends SolrTestCaseJ4 { return getHttpSolrClient(adminUrl); } + @Test + public void doTestHandlerPathUnchanged() throws Exception { + assertEquals("/replication", ReplicationHandler.PATH); + } + @Test public void doTestDetails() throws Exception { clearIndexWithReplication(); @@ -453,7 +458,7 @@ public class TestReplicationHandler extends SolrTestCaseJ4 { //jetty servers. private void invokeReplicationCommand(int pJettyPort, String pCommand) throws IOException { - String masterUrl = buildUrl(pJettyPort) + "/" + DEFAULT_TEST_CORENAME + "/replication?command=" + pCommand; + String masterUrl = buildUrl(pJettyPort) + "/" + DEFAULT_TEST_CORENAME + ReplicationHandler.PATH+"?command=" + pCommand; URL u = new URL(masterUrl); InputStream stream = u.openStream(); stream.close(); @@ -612,8 +617,8 @@ public class TestReplicationHandler extends SolrTestCaseJ4 { assertEquals(nDocs, masterQueryResult.getNumFound()); // index fetch - String masterUrl = buildUrl(slaveJetty.getLocalPort()) + "/" + DEFAULT_TEST_CORENAME + "/replication?command=fetchindex&masterUrl="; - masterUrl += buildUrl(masterJetty.getLocalPort()) + "/" + DEFAULT_TEST_CORENAME + "/replication"; + String masterUrl = buildUrl(slaveJetty.getLocalPort()) + "/" + DEFAULT_TEST_CORENAME + ReplicationHandler.PATH+"?command=fetchindex&masterUrl="; + masterUrl += buildUrl(masterJetty.getLocalPort()) + "/" + DEFAULT_TEST_CORENAME + ReplicationHandler.PATH; URL url = new URL(masterUrl); InputStream stream = url.openStream(); stream.close(); @@ -927,7 +932,7 @@ public class TestReplicationHandler extends SolrTestCaseJ4 { // check vs /replication?command=indexversion call ModifiableSolrParams params = new ModifiableSolrParams(); - params.set("qt", "/replication"); + params.set("qt", ReplicationHandler.PATH); params.set("_trace", "assertVersions"); params.set("command", "indexversion"); QueryRequest req = new QueryRequest(params); @@ -966,9 +971,9 @@ public class TestReplicationHandler extends SolrTestCaseJ4 { InputStream stream; masterUrl = buildUrl(to.getLocalPort()) + "/" + DEFAULT_TEST_CORENAME - + "/replication?wait=true&command=fetchindex&masterUrl=" + + ReplicationHandler.PATH+"?wait=true&command=fetchindex&masterUrl=" + buildUrl(from.getLocalPort()) - + "/" + DEFAULT_TEST_CORENAME + "/replication"; + + "/" + DEFAULT_TEST_CORENAME + ReplicationHandler.PATH; url = new URL(masterUrl); stream = url.openStream(); stream.close(); diff --git a/solr/core/src/test/org/apache/solr/handler/TestReplicationHandlerBackup.java b/solr/core/src/test/org/apache/solr/handler/TestReplicationHandlerBackup.java index 3ef6259babe..64e5796580a 100644 --- a/solr/core/src/test/org/apache/solr/handler/TestReplicationHandlerBackup.java +++ b/solr/core/src/test/org/apache/solr/handler/TestReplicationHandlerBackup.java @@ -274,7 +274,7 @@ public class TestReplicationHandlerBackup extends SolrJettyTestBase { public static void runBackupCommand(JettySolrRunner masterJetty, String cmd, String params) throws IOException { String masterUrl = buildUrl(masterJetty.getLocalPort(), context) + "/" + DEFAULT_TEST_CORENAME - + "/replication?command=" + cmd + params; + + ReplicationHandler.PATH+"?command=" + cmd + params; InputStream stream = null; try { URL url = new URL(masterUrl); @@ -297,7 +297,7 @@ public class TestReplicationHandlerBackup extends SolrJettyTestBase { } public boolean fetchStatus() throws IOException { - String masterUrl = buildUrl(masterJetty.getLocalPort(), context) + "/" + DEFAULT_TEST_CORENAME + "/replication?command=" + ReplicationHandler.CMD_DETAILS; + String masterUrl = buildUrl(masterJetty.getLocalPort(), context) + "/" + DEFAULT_TEST_CORENAME + ReplicationHandler.PATH + "?command=" + ReplicationHandler.CMD_DETAILS; URL url; InputStream stream = null; try { diff --git a/solr/core/src/test/org/apache/solr/handler/TestRestoreCore.java b/solr/core/src/test/org/apache/solr/handler/TestRestoreCore.java index a39a57e4be6..ef05798584a 100644 --- a/solr/core/src/test/org/apache/solr/handler/TestRestoreCore.java +++ b/solr/core/src/test/org/apache/solr/handler/TestRestoreCore.java @@ -232,7 +232,7 @@ public class TestRestoreCore extends SolrJettyTestBase { private boolean fetchRestoreStatus() throws IOException { String masterUrl = buildUrl(masterJetty.getLocalPort(), context) + "/" + DEFAULT_TEST_CORENAME + - "/replication?command=" + ReplicationHandler.CMD_RESTORE_STATUS; + ReplicationHandler.PATH + "?command=" + ReplicationHandler.CMD_RESTORE_STATUS; final Pattern pException = Pattern.compile("(.*?)"); InputStream stream = null; diff --git a/solr/core/src/test/org/apache/solr/security/TestRuleBasedAuthorizationPlugin.java b/solr/core/src/test/org/apache/solr/security/TestRuleBasedAuthorizationPlugin.java index 5abf21c78f8..628b4a80032 100644 --- a/solr/core/src/test/org/apache/solr/security/TestRuleBasedAuthorizationPlugin.java +++ b/solr/core/src/test/org/apache/solr/security/TestRuleBasedAuthorizationPlugin.java @@ -190,14 +190,14 @@ public class TestRuleBasedAuthorizationPlugin extends SolrTestCaseJ4 { ((Map)rules.get("user-role")).put("cio","su"); ((List)rules.get("permissions")).add( makeMap("name", "all", "role", "su")); - checkRules(makeMap("resource", "/replication", + checkRules(makeMap("resource", ReplicationHandler.PATH, "httpMethod", "POST", "userPrincipal", "tim", "handler", new ReplicationHandler(), "collectionRequests", singletonList(new CollectionRequest("mycoll")) ) , FORBIDDEN, rules); - checkRules(makeMap("resource", "/replication", + checkRules(makeMap("resource", ReplicationHandler.PATH, "httpMethod", "POST", "userPrincipal", "cio", "handler", new ReplicationHandler(),