Skip to content

Commit a0030c0

Browse files
committed
feedback
1 parent 6bc69f6 commit a0030c0

File tree

3 files changed

+9
-11
lines changed

3 files changed

+9
-11
lines changed

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

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@
5353
import org.elasticsearch.discovery.Discovery;
5454
import org.elasticsearch.cluster.coordination.FailedToCommitClusterStateException;
5555
import org.elasticsearch.threadpool.ThreadPool;
56-
import org.elasticsearch.transport.Transports;
5756

5857
import java.util.Arrays;
5958
import java.util.Collections;
@@ -173,14 +172,17 @@ ClusterState state() {
173172
return clusterStateSupplier.get();
174173
}
175174

175+
private static boolean isMasterUpdateThread() {
176+
return Thread.currentThread().getName().contains(MASTER_UPDATE_THREAD_NAME);
177+
}
178+
176179
public static boolean assertMasterUpdateThread() {
177-
assert Thread.currentThread().getName().contains(MASTER_UPDATE_THREAD_NAME) :
178-
"not called from the master service thread";
180+
assert isMasterUpdateThread() : "not called from the master service thread";
179181
return true;
180182
}
181183

182184
public static boolean assertNotMasterUpdateThread(String reason) {
183-
assert Thread.currentThread().getName().contains(MASTER_UPDATE_THREAD_NAME) == false :
185+
assert isMasterUpdateThread() == false :
184186
"Expected current thread [" + Thread.currentThread() + "] to not be the master service thread. Reason: [" + reason + "]";
185187
return true;
186188
}
@@ -240,10 +242,7 @@ protected void publish(ClusterChangedEvent clusterChangedEvent, TaskOutputs task
240242
final PlainActionFuture<Void> fut = new PlainActionFuture<Void>() {
241243
@Override
242244
protected boolean blockingAllowed() {
243-
// allow this one to block on the MasterServiceUpdateThread
244-
return Transports.assertNotTransportThread(BLOCKING_OP_REASON) &&
245-
ThreadPool.assertNotScheduleThread(BLOCKING_OP_REASON) &&
246-
ClusterApplierService.assertNotClusterStateUpdateThread(BLOCKING_OP_REASON);
245+
return isMasterUpdateThread() || super.blockingAllowed();
247246
}
248247
};
249248
clusterStatePublisher.publish(clusterChangedEvent, fut, taskOutputs.createAckListener(threadPool, clusterChangedEvent.state()));

server/src/main/java/org/elasticsearch/common/util/concurrent/BaseFuture.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535

3636
public abstract class BaseFuture<V> implements Future<V> {
3737

38-
protected static final String BLOCKING_OP_REASON = "Blocking operation";
38+
private static final String BLOCKING_OP_REASON = "Blocking operation";
3939

4040
/**
4141
* Synchronization control for AbstractFutures.

server/src/test/java/org/elasticsearch/ExceptionSerializationTests.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,6 @@
5757
import org.elasticsearch.common.xcontent.UnknownNamedObjectException;
5858
import org.elasticsearch.common.xcontent.XContentLocation;
5959
import org.elasticsearch.discovery.DiscoverySettings;
60-
import org.elasticsearch.cluster.coordination.FailedToCommitClusterStateException;
6160
import org.elasticsearch.env.ShardLockObtainFailedException;
6261
import org.elasticsearch.index.Index;
6362
import org.elasticsearch.index.engine.RecoveryEngineException;
@@ -802,7 +801,7 @@ public void testIds() {
802801
ids.put(137, org.elasticsearch.indices.TypeMissingException.class);
803802
ids.put(138, null);
804803
ids.put(139, null);
805-
ids.put(140, FailedToCommitClusterStateException.class);
804+
ids.put(140, org.elasticsearch.cluster.coordination.FailedToCommitClusterStateException.class);
806805
ids.put(141, org.elasticsearch.index.query.QueryShardException.class);
807806
ids.put(142, ShardStateAction.NoLongerPrimaryShardException.class);
808807
ids.put(143, org.elasticsearch.script.ScriptException.class);

0 commit comments

Comments
 (0)