Skip to content

Commit

Permalink
SOLR-17576: Remove deprecated master/slave support in ReplicationHand…
Browse files Browse the repository at this point in the history
…ler (apache#2887)
  • Loading branch information
epugh authored Dec 2, 2024
1 parent 5f888e5 commit f9f4a07
Show file tree
Hide file tree
Showing 7 changed files with 15 additions and 223 deletions.
2 changes: 2 additions & 0 deletions solr/CHANGES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,8 @@ Deprecation Removals

* SOLR-17564: Remove code in Assign used for backwards compatibility with Collections created prior to 7.0 (Paul McArthur)

* SOLR-17576: Remove deprecated master/slave option language from ReplicationHandler. (Eric Pugh)

Dependency Upgrades
---------------------
(No changes)
Expand Down
12 changes: 2 additions & 10 deletions solr/core/src/java/org/apache/solr/handler/IndexFetcher.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@
import static org.apache.solr.handler.ReplicationHandler.CONF_FILES;
import static org.apache.solr.handler.ReplicationHandler.FETCH_FROM_LEADER;
import static org.apache.solr.handler.ReplicationHandler.LEADER_URL;
import static org.apache.solr.handler.ReplicationHandler.LEGACY_LEADER_URL;
import static org.apache.solr.handler.ReplicationHandler.LEGACY_SKIP_COMMIT_ON_LEADER_VERSION_ZERO;
import static org.apache.solr.handler.ReplicationHandler.SIZE;
import static org.apache.solr.handler.ReplicationHandler.SKIP_COMMIT_ON_LEADER_VERSION_ZERO;
import static org.apache.solr.handler.admin.api.ReplicationAPIBase.CHECKSUM;
Expand Down Expand Up @@ -279,17 +277,11 @@ public IndexFetcher(
if (fetchFromLeader != null && fetchFromLeader instanceof Boolean) {
this.fetchFromLeader = (boolean) fetchFromLeader;
}
Object skipCommitOnLeaderVersionZero =
ReplicationHandler.getObjectWithBackwardCompatibility(
initArgs,
SKIP_COMMIT_ON_LEADER_VERSION_ZERO,
LEGACY_SKIP_COMMIT_ON_LEADER_VERSION_ZERO);
Object skipCommitOnLeaderVersionZero = initArgs.get(SKIP_COMMIT_ON_LEADER_VERSION_ZERO);
if (skipCommitOnLeaderVersionZero != null && skipCommitOnLeaderVersionZero instanceof Boolean) {
this.skipCommitOnLeaderVersionZero = (boolean) skipCommitOnLeaderVersionZero;
}
String leaderUrl =
ReplicationHandler.getObjectWithBackwardCompatibility(
initArgs, LEADER_URL, LEGACY_LEADER_URL);
String leaderUrl = (String) initArgs.get(LEADER_URL);
if (leaderUrl == null && !this.fetchFromLeader)
throw new SolrException(
SolrException.ErrorCode.SERVER_ERROR, "'leaderUrl' is required for a follower");
Expand Down
62 changes: 5 additions & 57 deletions solr/core/src/java/org/apache/solr/handler/ReplicationHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -307,8 +307,7 @@ public void handleRequestBody(SolrQueryRequest req, SolrQueryResponse rsp) throw
} else if (command.equals(CMD_SHOW_COMMITS)) {
populateCommitInfo(rsp);
} else if (command.equals(CMD_DETAILS)) {
getReplicationDetails(
rsp, getBoolWithBackwardCompatibility(solrParams, "follower", "slave", true));
getReplicationDetails(rsp, solrParams.getBool("follower", true));
} else if (CMD_ENABLE_REPL.equalsIgnoreCase(command)) {
replicationEnabled.set(true);
rsp.add(STATUS, OK_STATUS);
Expand Down Expand Up @@ -367,39 +366,6 @@ private void getFileStream(SolrParams solrParams, SolrQueryResponse rsp, SolrQue
solrParams.getLong(GENERATION));
}

static boolean getBoolWithBackwardCompatibility(
SolrParams params, String preferredKey, String alternativeKey, boolean defaultValue) {
Boolean value = params.getBool(preferredKey);
if (value != null) {
return value;
}
return params.getBool(alternativeKey, defaultValue);
}

@SuppressWarnings("unchecked")
static <T> T getObjectWithBackwardCompatibility(
SolrParams params, String preferredKey, String alternativeKey, T defaultValue) {
Object value = params.get(preferredKey);
if (value != null) {
return (T) value;
}
value = params.get(alternativeKey);
if (value != null) {
return (T) value;
}
return defaultValue;
}

@SuppressWarnings("unchecked")
public static <T> T getObjectWithBackwardCompatibility(
NamedList<?> params, String preferredKey, String alternativeKey) {
Object value = params.get(preferredKey);
if (value != null) {
return (T) value;
}
return (T) params.get(alternativeKey);
}

private void reportErrorOnResponse(SolrQueryResponse response, String message, Exception e) {
response.add(STATUS, ERR_STATUS);
response.add(MESSAGE, message);
Expand Down Expand Up @@ -432,8 +398,7 @@ private void deleteSnapshot(ModifiableSolrParams params, SolrQueryResponse rsp)

private void fetchIndex(SolrParams solrParams, SolrQueryResponse rsp)
throws InterruptedException {
String leaderUrl =
getObjectWithBackwardCompatibility(solrParams, LEADER_URL, LEGACY_LEADER_URL, null);
String leaderUrl = solrParams.get(LEADER_URL, null);
if (!isFollower && leaderUrl == null) {
reportErrorOnResponse(rsp, "No follower configured or no 'leaderUrl' specified", null);
return;
Expand Down Expand Up @@ -500,11 +465,7 @@ static Long getCheckSum(Checksum checksum, Path f) {
private volatile IndexFetcher currentIndexFetcher;

public IndexFetchResult doFetch(SolrParams solrParams, boolean forceReplication) {
String leaderUrl =
solrParams == null
? null
: ReplicationHandler.getObjectWithBackwardCompatibility(
solrParams, LEADER_URL, LEGACY_LEADER_URL, null);
String leaderUrl = solrParams == null ? null : solrParams.get(LEADER_URL, null);
if (!indexFetchLock.tryLock()) return IndexFetchResult.LOCK_OBTAIN_FAILED;
if (core.getCoreContainer().isShutDown()) {
log.warn("I was asked to replicate but CoreContainer is shutting down");
Expand Down Expand Up @@ -1290,14 +1251,14 @@ public void inform(SolrCore core) {
} else {
replicationHandlerConfig.numberBackupsToKeep = 0;
}
NamedList<?> follower = getObjectWithBackwardCompatibility(initArgs, "follower", "slave");
NamedList<?> follower = (NamedList<?>) initArgs.get("follower");
boolean enableFollower = isEnabled(follower);
if (enableFollower) {
currentIndexFetcher = pollingIndexFetcher = new IndexFetcher(follower, this, core);
setupPolling((String) follower.get(ReplicationAPIBase.POLL_INTERVAL));
isFollower = true;
}
NamedList<?> leader = getObjectWithBackwardCompatibility(initArgs, "leader", "master");
NamedList<?> leader = (NamedList<?>) initArgs.get("leader");
boolean enableLeader = isEnabled(leader);

if (enableLeader || (enableFollower && !currentIndexFetcher.fetchFromLeader)) {
Expand Down Expand Up @@ -1577,11 +1538,6 @@ private Long readIntervalNs(String interval) {

public static final String LEADER_URL = "leaderUrl";

/**
* @deprecated Only used for backwards compatibility. Use {@link #LEADER_URL}
*/
@Deprecated public static final String LEGACY_LEADER_URL = "masterUrl";

public static final String FETCH_FROM_LEADER = "fetchFromLeader";

// in case of TLOG replica, if leaderVersion = zero, don't do commit
Expand All @@ -1591,14 +1547,6 @@ private Long readIntervalNs(String interval) {
// state from leader
public static final String SKIP_COMMIT_ON_LEADER_VERSION_ZERO = "skipCommitOnLeaderVersionZero";

/**
* @deprecated Only used for backwards compatibility. Use {@link
* #SKIP_COMMIT_ON_LEADER_VERSION_ZERO}
*/
@Deprecated
public static final String LEGACY_SKIP_COMMIT_ON_LEADER_VERSION_ZERO =
"skipCommitOnMasterVersionZero";

public static final String MESSAGE = "message";

public static final String COMMAND = "command";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -243,9 +243,8 @@ private boolean isWithinGenerationLag(
IndexFetcher indexFetcher = null;
try {
// may not be the best way to get leader's replicableCommit
NamedList<?> follower =
ReplicationHandler.getObjectWithBackwardCompatibility(
replicationHandler.getInitArgs(), "follower", "slave");
NamedList<?> follower = (NamedList<?>) replicationHandler.getInitArgs().get("follower");

indexFetcher = new IndexFetcher(follower, replicationHandler, core);

NamedList<?> replicableCommitOnLeader = indexFetcher.getLatestVersion();
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@
import org.apache.solr.util.TimeOut;
import org.junit.After;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand All @@ -103,14 +102,6 @@ public class TestReplicationHandler extends SolrTestCaseJ4 {
// index from previous test method
static int nDocs = 500;

/* For testing backward compatibility, remove for 10.x */
private static boolean useLegacyParams = false;

@BeforeClass
public static void beforeClass() {
useLegacyParams = rarely();
}

@Override
@Before
public void setUp() throws Exception {
Expand Down Expand Up @@ -388,38 +379,6 @@ public void doTestDetails() throws Exception {
}
}

@Test
public void testLegacyConfiguration() throws Exception {
SolrInstance solrInstance = null;
JettySolrRunner instanceJetty = null;
SolrClient client = null;
try {
solrInstance =
new SolrInstance(
createTempDir("solr-instance").toFile(),
"replication-legacy",
leaderJetty.getLocalPort());
solrInstance.setUp();
instanceJetty = createAndStartJetty(solrInstance);
client =
ReplicationTestHelper.createNewSolrClient(
buildUrl(instanceJetty.getLocalPort()), DEFAULT_TEST_CORENAME);

NamedList<Object> details = getDetails(client);

assertEquals("repeater isLeader?", "true", details.get("isLeader"));
assertEquals("repeater isFollower?", "true", details.get("isFollower"));
assertNotNull("repeater has leader section", details.get("leader"));
assertNotNull("repeater has follower section", details.get("follower"));

} finally {
if (instanceJetty != null) {
instanceJetty.stop();
}
if (client != null) client.close();
}
}

/**
* Verify that empty commits and/or commits with openSearcher=false on the leader do not cause
* subsequent replication problems on the follower
Expand Down Expand Up @@ -779,11 +738,8 @@ private NamedList<Object> getFollowerDetails() throws SolrServerException, IOExc
ModifiableSolrParams params = new ModifiableSolrParams();
params.set(CommonParams.QT, "/replication");
params.set("command", "details");
if (useLegacyParams) {
params.set("slave", "true");
} else {
params.set("follower", "true");
}
params.set("follower", "true");

QueryResponse response = followerClient.query(params);

// details/follower/timesIndexReplicated
Expand Down Expand Up @@ -825,9 +781,6 @@ public void doTestIndexFetchWithLeaderUrl() throws Exception {
assertEquals(nDocs, leaderQueryResult.getNumFound());

String urlKey = "leaderUrl";
if (useLegacyParams) {
urlKey = "masterUrl";
}

// index fetch
String leaderUrl =
Expand Down Expand Up @@ -1667,48 +1620,6 @@ public void testEmptyBackups() throws Exception {
}
}

public void testGetBoolWithBackwardCompatibility() {
assertTrue(ReplicationHandler.getBoolWithBackwardCompatibility(params(), "foo", "bar", true));
assertFalse(ReplicationHandler.getBoolWithBackwardCompatibility(params(), "foo", "bar", false));
assertTrue(
ReplicationHandler.getBoolWithBackwardCompatibility(
params("foo", "true"), "foo", "bar", false));
assertTrue(
ReplicationHandler.getBoolWithBackwardCompatibility(
params("bar", "true"), "foo", "bar", false));
assertTrue(
ReplicationHandler.getBoolWithBackwardCompatibility(
params("foo", "true", "bar", "false"), "foo", "bar", false));
}

public void testGetObjectWithBackwardCompatibility() {
assertEquals(
"aaa",
ReplicationHandler.getObjectWithBackwardCompatibility(params(), "foo", "bar", "aaa"));
assertEquals(
"bbb",
ReplicationHandler.getObjectWithBackwardCompatibility(
params("foo", "bbb"), "foo", "bar", "aaa"));
assertEquals(
"bbb",
ReplicationHandler.getObjectWithBackwardCompatibility(
params("bar", "bbb"), "foo", "bar", "aaa"));
assertEquals(
"bbb",
ReplicationHandler.getObjectWithBackwardCompatibility(
params("foo", "bbb", "bar", "aaa"), "foo", "bar", "aaa"));
assertNull(ReplicationHandler.getObjectWithBackwardCompatibility(params(), "foo", "bar", null));
}

public void testGetObjectWithBackwardCompatibilityFromNL() {
NamedList<Object> nl = new NamedList<>();
assertNull(ReplicationHandler.getObjectWithBackwardCompatibility(nl, "foo", "bar"));
nl.add("bar", "bbb");
assertEquals("bbb", ReplicationHandler.getObjectWithBackwardCompatibility(nl, "foo", "bar"));
nl.add("foo", "aaa");
assertEquals("aaa", ReplicationHandler.getObjectWithBackwardCompatibility(nl, "foo", "bar"));
}

private static class AddExtraDocs implements Runnable {

SolrClient leaderClient;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,3 +85,5 @@ Please note this also removes the ability to share resource intensive objects ac

* The language specific Response Writers, which were deprecated in 9.8 in favour of more widely used formats like JSON have been removed.
The removed writer types (invoked as part of the `wt` parameter) include `python`, `ruby`, `php`, and `phps`.

* The deprecated support for configuring replication using master/slave terminology is removed. Use leader/follower.

0 comments on commit f9f4a07

Please sign in to comment.