Skip to content

Commit

Permalink
refactor INITIAL_STATE_TIMEOUT_SETTING to Node.DiscoverySettings inte…
Browse files Browse the repository at this point in the history
…rnal class

Signed-off-by: Nicholas Walter Knize <nknize@apache.org>
  • Loading branch information
nknize committed Dec 3, 2021
1 parent 18324ac commit a6f36a2
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
import org.opensearch.gateway.GatewayMetaState;
import org.opensearch.gateway.PersistedClusterStateService;
import org.opensearch.indices.IndicesService;
import org.opensearch.node.Node;
import org.opensearch.node.Node.DiscoverySettings;
import org.opensearch.test.InternalTestCluster;
import org.opensearch.test.OpenSearchIntegTestCase;

Expand Down Expand Up @@ -209,7 +209,7 @@ public void testBootstrapNoNodeMetadata() {
public void testBootstrapNotBootstrappedCluster() throws Exception {
String node = internalCluster().startNode(
Settings.builder()
.put(Node.INITIAL_STATE_TIMEOUT_SETTING.getKey(), "0s") // to ensure quick node startup
.put(DiscoverySettings.INITIAL_STATE_TIMEOUT_SETTING.getKey(), "0s") // to ensure quick node startup
.build()
);
assertBusy(() -> {
Expand Down Expand Up @@ -289,12 +289,14 @@ public void test3MasterNodes2Failed() throws Exception {

logger.info("--> start 1st master-eligible node");
masterNodes.add(
internalCluster().startMasterOnlyNode(Settings.builder().put(Node.INITIAL_STATE_TIMEOUT_SETTING.getKey(), "0s").build())
internalCluster().startMasterOnlyNode(
Settings.builder().put(DiscoverySettings.INITIAL_STATE_TIMEOUT_SETTING.getKey(), "0s").build()
)
); // node ordinal 0

logger.info("--> start one data-only node");
String dataNode = internalCluster().startDataOnlyNode(
Settings.builder().put(Node.INITIAL_STATE_TIMEOUT_SETTING.getKey(), "0s").build()
Settings.builder().put(DiscoverySettings.INITIAL_STATE_TIMEOUT_SETTING.getKey(), "0s").build()
); // node ordinal 1

logger.info("--> start 2nd and 3rd master-eligible nodes and bootstrap");
Expand Down Expand Up @@ -489,7 +491,7 @@ public void testNoInitialBootstrapAfterDetach() throws Exception {
String node = internalCluster().startMasterOnlyNode(
Settings.builder()
// give the cluster 2 seconds to elect the master (it should not)
.put(Node.INITIAL_STATE_TIMEOUT_SETTING.getKey(), "2s")
.put(DiscoverySettings.INITIAL_STATE_TIMEOUT_SETTING.getKey(), "2s")
.put(masterNodeDataPathSettings)
.build()
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
import org.opensearch.cluster.service.ClusterService;
import org.opensearch.common.logging.Loggers;
import org.opensearch.common.settings.Settings;
import org.opensearch.node.Node;
import org.opensearch.node.Node.DiscoverySettings;
import org.opensearch.test.OpenSearchIntegTestCase;
import org.opensearch.test.InternalTestCluster;
import org.opensearch.test.MockHttpTransport;
Expand Down Expand Up @@ -145,7 +145,7 @@ public Settings nodeSettings(int nodeOrdinal) {
return Settings.builder()
.put("discovery.type", "zen")
.put("transport.type", getTestTransportType())
.put(Node.INITIAL_STATE_TIMEOUT_SETTING.getKey(), "0s")
.put(DiscoverySettings.INITIAL_STATE_TIMEOUT_SETTING.getKey(), "0s")
/*
* We align the port ranges of the two as then with zen discovery these two
* nodes would find each other.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@
import org.opensearch.monitor.os.OsService;
import org.opensearch.monitor.process.ProcessService;
import org.opensearch.node.Node;
import org.opensearch.node.Node.DiscoverySettings;
import org.opensearch.node.NodeRoleSettings;
import org.opensearch.persistent.PersistentTasksClusterService;
import org.opensearch.persistent.decider.EnableAssignmentDecider;
Expand Down Expand Up @@ -458,7 +459,7 @@ public void apply(Settings value, Settings current, Settings previous) {
Environment.PIDFILE_SETTING,
Environment.NODE_PIDFILE_SETTING,
NodeEnvironment.NODE_ID_SEED_SETTING,
Node.INITIAL_STATE_TIMEOUT_SETTING,
DiscoverySettings.INITIAL_STATE_TIMEOUT_SETTING,
DiscoveryModule.DISCOVERY_TYPE_SETTING,
DiscoveryModule.DISCOVERY_SEED_PROVIDERS_SETTING,
DiscoveryModule.LEGACY_DISCOVERY_HOSTS_PROVIDER_SETTING,
Expand Down
15 changes: 9 additions & 6 deletions server/src/main/java/org/opensearch/node/Node.java
Original file line number Diff line number Diff line change
Expand Up @@ -292,11 +292,14 @@ public class Node implements Closeable {
}, Setting.Property.NodeScope);

private static final String CLIENT_TYPE = "node";
public static final Setting<TimeValue> INITIAL_STATE_TIMEOUT_SETTING = Setting.positiveTimeSetting(
"discovery.initial_state_timeout",
TimeValue.timeValueSeconds(30),
Property.NodeScope
);

public static class DiscoverySettings {
public static final Setting<TimeValue> INITIAL_STATE_TIMEOUT_SETTING = Setting.positiveTimeSetting(
"discovery.initial_state_timeout",
TimeValue.timeValueSeconds(30),
Property.NodeScope
);
}

private final Lifecycle lifecycle = new Lifecycle();

Expand Down Expand Up @@ -1103,7 +1106,7 @@ public Node start() throws NodeValidationException {
.equals(localNodeFactory.getNode()) : "clusterService has a different local node than the factory provided";
transportService.acceptIncomingRequests();
discovery.startInitialJoin();
final TimeValue initialStateTimeout = INITIAL_STATE_TIMEOUT_SETTING.get(settings());
final TimeValue initialStateTimeout = DiscoverySettings.INITIAL_STATE_TIMEOUT_SETTING.get(settings());
configureNodeAndClusterIdStateListener(clusterService);

if (initialStateTimeout.millis() > 0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@
import org.opensearch.indices.recovery.RecoverySettings;
import org.opensearch.node.MockNode;
import org.opensearch.node.Node;
import org.opensearch.node.Node.DiscoverySettings;
import org.opensearch.node.NodeRoleSettings;
import org.opensearch.node.NodeService;
import org.opensearch.node.NodeValidationException;
Expand Down Expand Up @@ -729,7 +730,7 @@ private Settings getNodeSettings(final int nodeId, final long seed, final Settin
if (autoManageMasterNodes) {
assertThat(
"if master nodes are automatically managed then nodes must complete a join cycle when starting",
updatedSettings.get(Node.INITIAL_STATE_TIMEOUT_SETTING.getKey()),
updatedSettings.get(DiscoverySettings.INITIAL_STATE_TIMEOUT_SETTING.getKey()),
nullValue()
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
import org.opensearch.discovery.SettingsBasedSeedHostsProvider;
import org.opensearch.env.Environment;
import org.opensearch.env.NodeEnvironment;
import org.opensearch.node.Node;
import org.opensearch.node.Node.DiscoverySettings;
import org.opensearch.plugins.Plugin;
import org.opensearch.test.OpenSearchTestCase;
import org.opensearch.test.InternalTestCluster;
Expand Down Expand Up @@ -394,7 +394,7 @@ public void testDifferentRolesMaintainPathOnRestart() throws Exception {
public Settings nodeSettings(int nodeOrdinal) {
return Settings.builder()
.put(NetworkModule.TRANSPORT_TYPE_KEY, getTestTransportType())
.put(Node.INITIAL_STATE_TIMEOUT_SETTING.getKey(), 0)
.put(DiscoverySettings.INITIAL_STATE_TIMEOUT_SETTING.getKey(), 0)
.putList(DISCOVERY_SEED_PROVIDERS_SETTING.getKey(), "file")
.putList(SettingsBasedSeedHostsProvider.DISCOVERY_SEED_HOSTS_SETTING.getKey())
.build();
Expand Down

0 comments on commit a6f36a2

Please sign in to comment.