-
Notifications
You must be signed in to change notification settings - Fork 24.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Apply cluster states in system context #53785
Changes from 7 commits
8e51526
848fae5
7f8c33e
52163d6
e98b2cf
561a7f8
897a0a1
31c29ef
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1163,15 +1163,15 @@ private final class TestClusterNode { | |
TestClusterNode(DiscoveryNode node) throws IOException { | ||
this.node = node; | ||
final Environment environment = createEnvironment(node.getName()); | ||
masterService = new FakeThreadPoolMasterService(node.getName(), "test", deterministicTaskQueue::scheduleNow); | ||
threadPool = deterministicTaskQueue.getThreadPool(runnable -> CoordinatorTests.onNodeLog(node, runnable)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Many of the rest of the changes, like this one, are to ensure that we use the same |
||
masterService = new FakeThreadPoolMasterService(node.getName(), "test", threadPool, deterministicTaskQueue::scheduleNow); | ||
final Settings settings = environment.settings(); | ||
final ClusterSettings clusterSettings = new ClusterSettings(settings, ClusterSettings.BUILT_IN_CLUSTER_SETTINGS); | ||
threadPool = deterministicTaskQueue.getThreadPool(); | ||
clusterService = new ClusterService(settings, clusterSettings, masterService, | ||
new ClusterApplierService(node.getName(), settings, clusterSettings, threadPool) { | ||
@Override | ||
protected PrioritizedEsThreadPoolExecutor createThreadPoolExecutor() { | ||
return new MockSinglePrioritizingExecutor(node.getName(), deterministicTaskQueue); | ||
return new MockSinglePrioritizingExecutor(node.getName(), deterministicTaskQueue, threadPool); | ||
} | ||
|
||
@Override | ||
|
@@ -1211,7 +1211,7 @@ protected NamedWriteableRegistry writeableRegistry() { | |
} | ||
}; | ||
transportService = mockTransport.createTransportService( | ||
settings, deterministicTaskQueue.getThreadPool(runnable -> CoordinatorTests.onNodeLog(node, runnable)), | ||
settings, threadPool, | ||
new TransportInterceptor() { | ||
@Override | ||
public <T extends TransportRequest> TransportRequestHandler<T> interceptHandler(String action, String executor, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
/* | ||
* Licensed to Elasticsearch under one or more contributor | ||
* license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright | ||
* ownership. Elasticsearch licenses this file to you under | ||
* the Apache License, Version 2.0 (the "License"); you may | ||
* not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
package org.elasticsearch.cluster.service; | ||
|
||
import org.elasticsearch.client.Client; | ||
import org.elasticsearch.cluster.metadata.IndexNameExpressionResolver; | ||
import org.elasticsearch.common.io.stream.NamedWriteableRegistry; | ||
import org.elasticsearch.common.xcontent.NamedXContentRegistry; | ||
import org.elasticsearch.env.Environment; | ||
import org.elasticsearch.env.NodeEnvironment; | ||
import org.elasticsearch.plugins.Plugin; | ||
import org.elasticsearch.script.ScriptService; | ||
import org.elasticsearch.threadpool.ThreadPool; | ||
import org.elasticsearch.watcher.ResourceWatcherService; | ||
|
||
import java.util.Collection; | ||
import java.util.Collections; | ||
|
||
public class ClusterApplierAssertionPlugin extends Plugin { | ||
@Override | ||
public Collection<Object> createComponents(Client client, ClusterService clusterService, ThreadPool threadPool, | ||
ResourceWatcherService resourceWatcherService, ScriptService scriptService, | ||
NamedXContentRegistry xContentRegistry, Environment environment, | ||
NodeEnvironment nodeEnvironment, NamedWriteableRegistry namedWriteableRegistry, | ||
IndexNameExpressionResolver indexNameExpressionResolver) { | ||
clusterService.addStateApplier(event -> { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These are the key assertions. It seemed a bit vacuous to put them directly in the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is good. |
||
assert threadPool.getThreadContext().isSystemContext(); | ||
}); | ||
clusterService.addListener(event -> { | ||
assert threadPool.getThreadContext().isSystemContext(); | ||
}); | ||
return Collections.emptyList(); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the key change. I would have preferred to avoid an explicit
markAsSystemContext
and instead to start everything in the system context and then preserve the context everywhere. It all fell to pieces a bit since system context is not propagated across transport messages and I timed out while trying to come up with a reliable way to assert that things are happening in the right context.