Skip to content

Commit ed2bf22

Browse files
committed
[apache#2316] Move custom commit declaration into UpdateHandlerInfo
Also add tests for retrieving and selecting the commit interval
1 parent cda9cad commit ed2bf22

File tree

3 files changed

+43
-16
lines changed

3 files changed

+43
-16
lines changed

solr/core/src/java/org/apache/solr/cloud/ReplicateFromLeader.java

+9-8
Original file line numberDiff line numberDiff line change
@@ -77,16 +77,13 @@ public void startReplication(boolean switchTransactionLog) {
7777
}
7878

7979
SolrConfig.UpdateHandlerInfo uinfo = core.getSolrConfig().getUpdateHandlerInfo();
80-
String customPollInterval =
81-
core.getSolrConfig().get("updateHandler").get("commitPollInterval").txt();
8280
String pollIntervalStr = "00:00:03";
83-
String calculatedPollIntervalString = determinePollInterval(uinfo);
84-
8581
if (System.getProperty("jetty.testMode") != null) {
8682
pollIntervalStr = "00:00:01";
87-
} else if (customPollInterval != null) {
88-
pollIntervalStr = customPollInterval;
89-
} else if (calculatedPollIntervalString != null) {
83+
}
84+
85+
String calculatedPollIntervalString = determinePollInterval(uinfo);
86+
if (calculatedPollIntervalString != null) {
9087
pollIntervalStr = calculatedPollIntervalString;
9188
}
9289
log.info("Will start replication from leader with poll interval: {}", pollIntervalStr);
@@ -170,8 +167,12 @@ public static String determinePollInterval(SolrConfig.UpdateHandlerInfo uinfo) {
170167
int hardCommitMaxTime = uinfo.autoCommmitMaxTime;
171168
int softCommitMaxTime = uinfo.autoSoftCommmitMaxTime;
172169
boolean hardCommitNewSearcher = uinfo.openSearcher;
170+
String customCommitPollInterval = uinfo.commitPollInterval;
173171
String pollIntervalStr = null;
174-
if (hardCommitMaxTime != -1) {
172+
173+
if (customCommitPollInterval != null) {
174+
pollIntervalStr = customCommitPollInterval;
175+
} else if (hardCommitMaxTime != -1) {
175176
// configured hardCommit places a ceiling on the interval at which new segments will be
176177
// available to replicate
177178
if (softCommitMaxTime != -1

solr/core/src/java/org/apache/solr/core/SolrConfig.java

+7-1
Original file line numberDiff line numberDiff line change
@@ -818,6 +818,7 @@ public static class UpdateHandlerInfo implements MapSerializable {
818818
public final boolean openSearcher; // is opening a new searcher part of hard autocommit?
819819
public final boolean commitWithinSoftCommit;
820820
public final boolean aggregateNodeLevelMetricsEnabled;
821+
public final String commitPollInterval;
821822

822823
/**
823824
* @param autoCommmitMaxDocs set -1 as default
@@ -832,7 +833,8 @@ public UpdateHandlerInfo(
832833
boolean openSearcher,
833834
int autoSoftCommmitMaxDocs,
834835
int autoSoftCommmitMaxTime,
835-
boolean commitWithinSoftCommit) {
836+
boolean commitWithinSoftCommit,
837+
String commitPollInterval) {
836838
this.className = className;
837839
this.autoCommmitMaxDocs = autoCommmitMaxDocs;
838840
this.autoCommmitMaxTime = autoCommmitMaxTime;
@@ -844,6 +846,8 @@ public UpdateHandlerInfo(
844846

845847
this.commitWithinSoftCommit = commitWithinSoftCommit;
846848
this.aggregateNodeLevelMetricsEnabled = false;
849+
850+
this.commitPollInterval = commitPollInterval;
847851
}
848852

849853
public UpdateHandlerInfo(ConfigNode updateHandler) {
@@ -860,6 +864,7 @@ public UpdateHandlerInfo(ConfigNode updateHandler) {
860864
updateHandler.get("commitWithin").get("softCommit").boolVal(true);
861865
this.aggregateNodeLevelMetricsEnabled =
862866
updateHandler.boolAttr("aggregateNodeLevelMetricsEnabled", false);
867+
this.commitPollInterval = updateHandler.get("commitPollInterval").txt();
863868
}
864869

865870
@Override
@@ -874,6 +879,7 @@ public Map<String, Object> toMap(Map<String, Object> map) {
874879
map.put(
875880
"autoSoftCommit",
876881
Map.of("maxDocs", autoSoftCommmitMaxDocs, "maxTime", autoSoftCommmitMaxTime));
882+
map.put("commitPollInterval", commitPollInterval);
877883
return map;
878884
}
879885
}

solr/core/src/test/org/apache/solr/cloud/ReplicateFromLeaderTest.java

+27-7
Original file line numberDiff line numberDiff line change
@@ -28,44 +28,64 @@ public class ReplicateFromLeaderTest {
2828
public void determinePollIntervalString() {
2929
SolrConfig.UpdateHandlerInfo updateHandlerInfo =
3030
new SolrConfig.UpdateHandlerInfo(
31-
"solr.DirectUpdateHandler2", -1, 15000, -1, true, -1, 60000, false);
31+
"solr.DirectUpdateHandler2", -1, 15000, -1, true, -1, 60000, false, null);
3232
String pollInterval = ReplicateFromLeader.determinePollInterval(updateHandlerInfo);
3333
assertEquals("0:0:7", pollInterval);
3434

3535
updateHandlerInfo =
3636
new SolrConfig.UpdateHandlerInfo(
37-
"solr.DirectUpdateHandler2", -1, 60000, -1, true, -1, 15000, false);
37+
"solr.DirectUpdateHandler2", -1, 60000, -1, true, -1, 15000, false, null);
3838
pollInterval = ReplicateFromLeader.determinePollInterval(updateHandlerInfo);
3939
assertEquals("0:0:30", pollInterval);
4040

4141
updateHandlerInfo =
4242
new SolrConfig.UpdateHandlerInfo(
43-
"solr.DirectUpdateHandler2", -1, 15000, -1, false, -1, 60000, false);
43+
"solr.DirectUpdateHandler2", -1, 15000, -1, false, -1, 60000, false, null);
4444
pollInterval = ReplicateFromLeader.determinePollInterval(updateHandlerInfo);
4545
assertEquals("0:0:30", pollInterval);
4646

4747
updateHandlerInfo =
4848
new SolrConfig.UpdateHandlerInfo(
49-
"solr.DirectUpdateHandler2", -1, 60000, -1, false, -1, 15000, false);
49+
"solr.DirectUpdateHandler2", -1, 60000, -1, false, -1, 15000, false, null);
5050
pollInterval = ReplicateFromLeader.determinePollInterval(updateHandlerInfo);
5151
assertEquals("0:0:30", pollInterval);
5252

5353
updateHandlerInfo =
5454
new SolrConfig.UpdateHandlerInfo(
55-
"solr.DirectUpdateHandler2", -1, -1, -1, false, -1, 60000, false);
55+
"solr.DirectUpdateHandler2", -1, -1, -1, false, -1, 60000, false, null);
5656
pollInterval = ReplicateFromLeader.determinePollInterval(updateHandlerInfo);
5757
assertEquals("0:0:30", pollInterval);
5858

5959
updateHandlerInfo =
6060
new SolrConfig.UpdateHandlerInfo(
61-
"solr.DirectUpdateHandler2", -1, 15000, -1, false, -1, -1, false);
61+
"solr.DirectUpdateHandler2", -1, 15000, -1, false, -1, -1, false, null);
6262
pollInterval = ReplicateFromLeader.determinePollInterval(updateHandlerInfo);
6363
assertEquals("0:0:7", pollInterval);
6464

6565
updateHandlerInfo =
6666
new SolrConfig.UpdateHandlerInfo(
67-
"solr.DirectUpdateHandler2", -1, 60000, -1, true, -1, -1, false);
67+
"solr.DirectUpdateHandler2", -1, 60000, -1, true, -1, -1, false, null);
6868
pollInterval = ReplicateFromLeader.determinePollInterval(updateHandlerInfo);
6969
assertEquals("0:0:30", pollInterval);
70+
71+
updateHandlerInfo =
72+
new SolrConfig.UpdateHandlerInfo(
73+
"solr.DirectUpdateHandler2", -1, 60000, -1, true, -1, -1, false, "0:0:56");
74+
pollInterval = ReplicateFromLeader.determinePollInterval(updateHandlerInfo);
75+
assertEquals("0:0:56", pollInterval);
76+
77+
updateHandlerInfo =
78+
new SolrConfig.UpdateHandlerInfo(
79+
"solr.DirectUpdateHandler2",
80+
-1,
81+
60000,
82+
-1,
83+
true,
84+
-1,
85+
-1,
86+
false,
87+
"garbage-unfortunately");
88+
pollInterval = ReplicateFromLeader.determinePollInterval(updateHandlerInfo);
89+
assertEquals("garbage-unfortunately", pollInterval);
7090
}
7191
}

0 commit comments

Comments
 (0)