Skip to content

Commit db6e8c7

Browse files
authored
Remove cluster state initial customs (#32501)
This infrastructure was introduced in #26144 and made obsolete in #30743
1 parent 097c428 commit db6e8c7

File tree

20 files changed

+75
-238
lines changed

20 files changed

+75
-238
lines changed

server/src/main/java/org/elasticsearch/cluster/ClusterModule.java

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -116,23 +116,6 @@ public ClusterModule(Settings settings, ClusterService clusterService, List<Clus
116116
this.allocationService = new AllocationService(settings, allocationDeciders, shardsAllocator, clusterInfoService);
117117
}
118118

119-
public static Map<String, Supplier<ClusterState.Custom>> getClusterStateCustomSuppliers(List<ClusterPlugin> clusterPlugins) {
120-
final Map<String, Supplier<ClusterState.Custom>> customSupplier = new HashMap<>();
121-
customSupplier.put(SnapshotDeletionsInProgress.TYPE, SnapshotDeletionsInProgress::new);
122-
customSupplier.put(RestoreInProgress.TYPE, RestoreInProgress::new);
123-
customSupplier.put(SnapshotsInProgress.TYPE, SnapshotsInProgress::new);
124-
for (ClusterPlugin plugin : clusterPlugins) {
125-
Map<String, Supplier<ClusterState.Custom>> initialCustomSupplier = plugin.getInitialClusterStateCustomSupplier();
126-
for (String key : initialCustomSupplier.keySet()) {
127-
if (customSupplier.containsKey(key)) {
128-
throw new IllegalStateException("custom supplier key [" + key + "] is registered more than once");
129-
}
130-
}
131-
customSupplier.putAll(initialCustomSupplier);
132-
}
133-
return Collections.unmodifiableMap(customSupplier);
134-
}
135-
136119
public static List<Entry> getNamedWriteables() {
137120
List<Entry> entries = new ArrayList<>();
138121
// Cluster State

server/src/main/java/org/elasticsearch/cluster/service/ClusterApplier.java

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,6 @@ public interface ClusterApplier {
3939
*/
4040
void onNewClusterState(String source, Supplier<ClusterState> clusterStateSupplier, ClusterApplyListener listener);
4141

42-
/**
43-
* Creates a new cluster state builder that is initialized with the cluster name and all initial cluster state customs.
44-
*/
45-
ClusterState.Builder newClusterStateBuilder();
46-
4742
/**
4843
* Listener for results of cluster state application
4944
*/

server/src/main/java/org/elasticsearch/cluster/service/ClusterApplierService.java

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -96,17 +96,14 @@ public class ClusterApplierService extends AbstractLifecycleComponent implements
9696
private final AtomicReference<ClusterState> state; // last applied state
9797

9898
private NodeConnectionsService nodeConnectionsService;
99-
private Supplier<ClusterState.Builder> stateBuilderSupplier;
10099

101-
public ClusterApplierService(Settings settings, ClusterSettings clusterSettings, ThreadPool threadPool, Supplier<ClusterState
102-
.Builder> stateBuilderSupplier) {
100+
public ClusterApplierService(Settings settings, ClusterSettings clusterSettings, ThreadPool threadPool) {
103101
super(settings);
104102
this.clusterSettings = clusterSettings;
105103
this.threadPool = threadPool;
106104
this.state = new AtomicReference<>();
107105
this.slowTaskLoggingThreshold = CLUSTER_SERVICE_SLOW_TASK_LOGGING_THRESHOLD_SETTING.get(settings);
108106
this.localNodeMasterListeners = new LocalNodeMasterListeners(threadPool);
109-
this.stateBuilderSupplier = stateBuilderSupplier;
110107
}
111108

112109
public void setSlowTaskLoggingThreshold(TimeValue slowTaskLoggingThreshold) {
@@ -652,8 +649,4 @@ protected long currentTimeInNanos() {
652649
return System.nanoTime();
653650
}
654651

655-
@Override
656-
public ClusterState.Builder newClusterStateBuilder() {
657-
return stateBuilderSupplier.get();
658-
}
659652
}

server/src/main/java/org/elasticsearch/cluster/service/ClusterService.java

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@
4242

4343
import java.util.Collections;
4444
import java.util.Map;
45-
import java.util.function.Supplier;
4645

4746
public class ClusterService extends AbstractLifecycleComponent {
4847

@@ -59,30 +58,16 @@ public class ClusterService extends AbstractLifecycleComponent {
5958
private final OperationRouting operationRouting;
6059

6160
private final ClusterSettings clusterSettings;
62-
private final Map<String, Supplier<ClusterState.Custom>> initialClusterStateCustoms;
6361

64-
public ClusterService(Settings settings, ClusterSettings clusterSettings, ThreadPool threadPool,
65-
Map<String, Supplier<ClusterState.Custom>> initialClusterStateCustoms) {
62+
public ClusterService(Settings settings, ClusterSettings clusterSettings, ThreadPool threadPool) {
6663
super(settings);
6764
this.masterService = new MasterService(settings, threadPool);
6865
this.operationRouting = new OperationRouting(settings, clusterSettings);
6966
this.clusterSettings = clusterSettings;
7067
this.clusterName = ClusterName.CLUSTER_NAME_SETTING.get(settings);
7168
this.clusterSettings.addSettingsUpdateConsumer(CLUSTER_SERVICE_SLOW_TASK_LOGGING_THRESHOLD_SETTING,
7269
this::setSlowTaskLoggingThreshold);
73-
this.initialClusterStateCustoms = initialClusterStateCustoms;
74-
this.clusterApplierService = new ClusterApplierService(settings, clusterSettings, threadPool, this::newClusterStateBuilder);
75-
}
76-
77-
/**
78-
* Creates a new cluster state builder that is initialized with the cluster name and all initial cluster state customs.
79-
*/
80-
public ClusterState.Builder newClusterStateBuilder() {
81-
ClusterState.Builder builder = ClusterState.builder(ClusterName.CLUSTER_NAME_SETTING.get(settings));
82-
for (Map.Entry<String, Supplier<ClusterState.Custom>> entry : initialClusterStateCustoms.entrySet()) {
83-
builder.putCustom(entry.getKey(), entry.getValue().get());
84-
}
85-
return builder;
70+
this.clusterApplierService = new ClusterApplierService(settings, clusterSettings, threadPool);
8671
}
8772

8873
private void setSlowTaskLoggingThreshold(TimeValue slowTaskLoggingThreshold) {

server/src/main/java/org/elasticsearch/discovery/single/SingleNodeDiscovery.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121

2222
import org.apache.logging.log4j.message.ParameterizedMessage;
2323
import org.elasticsearch.cluster.ClusterChangedEvent;
24+
import org.elasticsearch.cluster.ClusterName;
2425
import org.elasticsearch.cluster.ClusterState;
2526
import org.elasticsearch.cluster.block.ClusterBlocks;
2627
import org.elasticsearch.cluster.node.DiscoveryNode;
@@ -113,7 +114,7 @@ protected synchronized void doStart() {
113114
}
114115

115116
protected ClusterState createInitialState(DiscoveryNode localNode) {
116-
ClusterState.Builder builder = clusterApplier.newClusterStateBuilder();
117+
ClusterState.Builder builder = ClusterState.builder(ClusterName.CLUSTER_NAME_SETTING.get(settings));
117118
return builder.nodes(DiscoveryNodes.builder().add(localNode)
118119
.localNodeId(localNode.getId())
119120
.masterNodeId(localNode.getId())

server/src/main/java/org/elasticsearch/discovery/zen/ZenDiscovery.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ protected void doStart() {
252252
// set initial state
253253
assert committedState.get() == null;
254254
assert localNode != null;
255-
ClusterState.Builder builder = clusterApplier.newClusterStateBuilder();
255+
ClusterState.Builder builder = ClusterState.builder(ClusterName.CLUSTER_NAME_SETTING.get(settings));
256256
ClusterState initialState = builder
257257
.blocks(ClusterBlocks.builder()
258258
.addGlobalBlock(STATE_NOT_RECOVERED_BLOCK)

server/src/main/java/org/elasticsearch/gateway/Gateway.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import com.carrotsearch.hppc.cursors.ObjectCursor;
2424
import org.apache.logging.log4j.message.ParameterizedMessage;
2525
import org.elasticsearch.action.FailedNodeException;
26+
import org.elasticsearch.cluster.ClusterName;
2627
import org.elasticsearch.cluster.ClusterState;
2728
import org.elasticsearch.cluster.metadata.IndexMetaData;
2829
import org.elasticsearch.cluster.metadata.MetaData;
@@ -147,7 +148,7 @@ public void performStateRecovery(final GatewayStateRecoveredListener listener) t
147148
metaDataBuilder.transientSettings(),
148149
e -> logUnknownSetting("transient", e),
149150
(e, ex) -> logInvalidSetting("transient", e, ex)));
150-
ClusterState.Builder builder = clusterService.newClusterStateBuilder();
151+
ClusterState.Builder builder = ClusterState.builder(ClusterName.CLUSTER_NAME_SETTING.get(settings));
151152
builder.metaData(metaDataBuilder);
152153
listener.onSuccess(builder.build());
153154
}

server/src/main/java/org/elasticsearch/node/Node.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -349,8 +349,7 @@ protected Node(final Environment environment, Collection<Class<? extends Plugin>
349349
getCustomNameResolvers(pluginsService.filterPlugins(DiscoveryPlugin.class)));
350350

351351
List<ClusterPlugin> clusterPlugins = pluginsService.filterPlugins(ClusterPlugin.class);
352-
final ClusterService clusterService = new ClusterService(settings, settingsModule.getClusterSettings(), threadPool,
353-
ClusterModule.getClusterStateCustomSuppliers(clusterPlugins));
352+
final ClusterService clusterService = new ClusterService(settings, settingsModule.getClusterSettings(), threadPool);
354353
clusterService.addStateApplier(scriptModule.getScriptService());
355354
resourcesToClose.add(clusterService);
356355
final IngestService ingestService = new IngestService(settings, threadPool, this.environment,

server/src/main/java/org/elasticsearch/plugins/ClusterPlugin.java

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
import java.util.Map;
2525
import java.util.function.Supplier;
2626

27-
import org.elasticsearch.cluster.ClusterState;
2827
import org.elasticsearch.cluster.routing.allocation.allocator.ShardsAllocator;
2928
import org.elasticsearch.cluster.routing.allocation.decider.AllocationDecider;
3029
import org.elasticsearch.common.settings.ClusterSettings;
@@ -66,12 +65,4 @@ default Map<String, Supplier<ShardsAllocator>> getShardsAllocators(Settings sett
6665
default void onNodeStarted() {
6766
}
6867

69-
/**
70-
* Returns a map of {@link ClusterState.Custom} supplier that should be invoked to initialize the initial clusterstate.
71-
* This allows custom clusterstate extensions to be always present and prevents invariants where clusterstates are published
72-
* but customs are not initialized.
73-
*
74-
* TODO: Remove this whole concept of InitialClusterStateCustomSupplier, it's not used anymore
75-
*/
76-
default Map<String, Supplier<ClusterState.Custom>> getInitialClusterStateCustomSupplier() { return Collections.emptyMap(); }
7768
}

server/src/test/java/org/elasticsearch/cluster/ClusterModuleTests.java

Lines changed: 1 addition & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@
6363
public class ClusterModuleTests extends ModuleTestCase {
6464
private ClusterInfoService clusterInfoService = EmptyClusterInfoService.INSTANCE;
6565
private ClusterService clusterService = new ClusterService(Settings.EMPTY,
66-
new ClusterSettings(Settings.EMPTY, ClusterSettings.BUILT_IN_CLUSTER_SETTINGS), null, Collections.emptyMap());
66+
new ClusterSettings(Settings.EMPTY, ClusterSettings.BUILT_IN_CLUSTER_SETTINGS), null);
6767
static class FakeAllocationDecider extends AllocationDecider {
6868
protected FakeAllocationDecider(Settings settings) {
6969
super(settings);
@@ -202,57 +202,6 @@ public void testAllocationDeciderOrder() {
202202
}
203203
}
204204

205-
public void testCustomSuppliers() {
206-
Map<String, Supplier<ClusterState.Custom>> customSuppliers = ClusterModule.getClusterStateCustomSuppliers(Collections.emptyList());
207-
assertEquals(3, customSuppliers.size());
208-
assertTrue(customSuppliers.containsKey(SnapshotsInProgress.TYPE));
209-
assertTrue(customSuppliers.containsKey(SnapshotDeletionsInProgress.TYPE));
210-
assertTrue(customSuppliers.containsKey(RestoreInProgress.TYPE));
211-
212-
customSuppliers = ClusterModule.getClusterStateCustomSuppliers(Collections.singletonList(new ClusterPlugin() {
213-
@Override
214-
public Map<String, Supplier<ClusterState.Custom>> getInitialClusterStateCustomSupplier() {
215-
return Collections.singletonMap("foo", () -> null);
216-
}
217-
}));
218-
assertEquals(4, customSuppliers.size());
219-
assertTrue(customSuppliers.containsKey(SnapshotsInProgress.TYPE));
220-
assertTrue(customSuppliers.containsKey(SnapshotDeletionsInProgress.TYPE));
221-
assertTrue(customSuppliers.containsKey(RestoreInProgress.TYPE));
222-
assertTrue(customSuppliers.containsKey("foo"));
223-
224-
{
225-
// Eclipse Neon 2 didn't compile the plugins definition inside the lambda expression,
226-
// probably due to https://bugs.eclipse.org/bugs/show_bug.cgi?id=511750, which is
227-
// fixed in Eclipse Oxygon. Pulled out the plugins definition to make it work in older versions
228-
List<ClusterPlugin> plugins = Collections.singletonList(new ClusterPlugin() {
229-
@Override
230-
public Map<String, Supplier<ClusterState.Custom>> getInitialClusterStateCustomSupplier() {
231-
return Collections.singletonMap(SnapshotsInProgress.TYPE, () -> null);
232-
}
233-
});
234-
IllegalStateException ise = expectThrows(IllegalStateException.class,
235-
() -> ClusterModule.getClusterStateCustomSuppliers(plugins));
236-
assertEquals(ise.getMessage(), "custom supplier key [snapshots] is registered more than once");
237-
}
238-
{
239-
List<ClusterPlugin> plugins = Arrays.asList(new ClusterPlugin() {
240-
@Override
241-
public Map<String, Supplier<ClusterState.Custom>> getInitialClusterStateCustomSupplier() {
242-
return Collections.singletonMap("foo", () -> null);
243-
}
244-
}, new ClusterPlugin() {
245-
@Override
246-
public Map<String, Supplier<ClusterState.Custom>> getInitialClusterStateCustomSupplier() {
247-
return Collections.singletonMap("foo", () -> null);
248-
}
249-
});
250-
IllegalStateException ise = expectThrows(IllegalStateException.class,
251-
() -> ClusterModule.getClusterStateCustomSuppliers(plugins));
252-
assertEquals(ise.getMessage(), "custom supplier key [foo] is registered more than once");
253-
}
254-
}
255-
256205
public void testPre63CustomsFiltering() {
257206
final String whiteListedClusterCustom = randomFrom(ClusterModule.PRE_6_3_CLUSTER_CUSTOMS_WHITE_LIST);
258207
final String whiteListedMetaDataCustom = randomFrom(ClusterModule.PRE_6_3_METADATA_CUSTOMS_WHITE_LIST);

0 commit comments

Comments
 (0)