Skip to content

Commit d6b38f6

Browse files
authored
Extract utility for asserting current thread pool (elastic#88383)
It's useful to assert we're running on a particular thread pool. Today we do this by checking the current thread's name, but the actual implementation of this check varies quite a bit across the codebase. Some of them are quite verbose, and others fail to include the delimeters around the thread name. This commit introduces a utility method to standardize this kind of assertion.
1 parent 9abfe4b commit d6b38f6

File tree

26 files changed

+76
-107
lines changed

26 files changed

+76
-107
lines changed

server/src/main/java/org/elasticsearch/action/admin/cluster/stats/TransportClusterStatsAction.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ protected void newResponseAsync(
112112
"Computation of mapping/analysis stats runs expensive computations on mappings found in "
113113
+ "the cluster state that are too slow for a transport thread"
114114
);
115-
assert Thread.currentThread().getName().contains("[" + ThreadPool.Names.MANAGEMENT + "]") : Thread.currentThread().getName();
115+
assert ThreadPool.assertCurrentThreadPool(ThreadPool.Names.MANAGEMENT);
116116
assert task instanceof CancellableTask;
117117
final CancellableTask cancellableTask = (CancellableTask) task;
118118
final ClusterState state = clusterService.state();

server/src/main/java/org/elasticsearch/action/search/CanMatchPreFilterSearchPhase.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -129,9 +129,7 @@ final class CanMatchPreFilterSearchPhase extends SearchPhase {
129129
}
130130

131131
private static boolean assertSearchCoordinationThread() {
132-
assert Thread.currentThread().getName().contains(ThreadPool.Names.SEARCH_COORDINATION)
133-
: "not called from the right thread " + Thread.currentThread().getName();
134-
return true;
132+
return ThreadPool.assertCurrentThreadPool(ThreadPool.Names.SEARCH_COORDINATION);
135133
}
136134

137135
@Override

server/src/main/java/org/elasticsearch/cluster/coordination/Coordinator.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@
6464
import org.elasticsearch.monitor.NodeHealthService;
6565
import org.elasticsearch.monitor.StatusInfo;
6666
import org.elasticsearch.threadpool.Scheduler;
67+
import org.elasticsearch.threadpool.ThreadPool;
6768
import org.elasticsearch.threadpool.ThreadPool.Names;
6869
import org.elasticsearch.transport.NodeDisconnectedException;
6970
import org.elasticsearch.transport.TransportRequest;
@@ -396,8 +397,7 @@ private void handleApplyCommit(ApplyCommitRequest applyCommitRequest, ActionList
396397
}
397398

398399
private void onClusterStateApplied() {
399-
assert Thread.currentThread().getName().contains('[' + ClusterApplierService.CLUSTER_UPDATE_THREAD_NAME + ']')
400-
|| Thread.currentThread().getName().startsWith("TEST-") : Thread.currentThread().getName();
400+
assert ThreadPool.assertCurrentThreadPool(ClusterApplierService.CLUSTER_UPDATE_THREAD_NAME);
401401
if (getMode() != Mode.CANDIDATE) {
402402
joinHelper.onClusterStateApplied();
403403
}

server/src/main/java/org/elasticsearch/cluster/coordination/JoinHelper.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -246,10 +246,7 @@ public void onResponse(Releasable connectionReference) {
246246
new ActionListener<>() {
247247
@Override
248248
public void onResponse(Void unused) {
249-
assert Thread.currentThread()
250-
.getName()
251-
.contains('[' + ClusterApplierService.CLUSTER_UPDATE_THREAD_NAME + ']')
252-
|| Thread.currentThread().getName().startsWith("TEST-") : Thread.currentThread().getName();
249+
assert ThreadPool.assertCurrentThreadPool(ClusterApplierService.CLUSTER_UPDATE_THREAD_NAME);
253250
pendingJoinInfo.message = PENDING_JOIN_WAITING_RESPONSE;
254251
transportService.sendRequest(
255252
destination,

server/src/main/java/org/elasticsearch/cluster/coordination/JoinReasonService.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import org.elasticsearch.core.Nullable;
1818
import org.elasticsearch.core.TimeValue;
1919
import org.elasticsearch.core.Tuple;
20+
import org.elasticsearch.threadpool.ThreadPool;
2021

2122
import java.util.ArrayList;
2223
import java.util.Comparator;
@@ -50,8 +51,7 @@ public JoinReasonService(LongSupplier relativeTimeInMillisSupplier) {
5051
* Called when a new cluster state was applied by a master-eligible node, possibly adding or removing some nodes.
5152
*/
5253
public void onClusterStateApplied(DiscoveryNodes discoveryNodes) {
53-
assert Thread.currentThread().getName().contains('[' + ClusterApplierService.CLUSTER_UPDATE_THREAD_NAME + ']')
54-
|| Thread.currentThread().getName().startsWith("TEST-") : Thread.currentThread().getName();
54+
assert ThreadPool.assertCurrentThreadPool(ClusterApplierService.CLUSTER_UPDATE_THREAD_NAME);
5555
assert discoveryNodes.getLocalNode().isMasterNode();
5656

5757
if (this.discoveryNodes != discoveryNodes) {
@@ -98,8 +98,7 @@ public void onClusterStateApplied(DiscoveryNodes discoveryNodes) {
9898
* absent node is still tracked then this adds the removal reason ({@code disconnected}, {@code lagging}, etc.) to the tracker.
9999
*/
100100
public void onNodeRemoved(DiscoveryNode discoveryNode, String reason) {
101-
assert MasterService.isMasterUpdateThread() || Thread.currentThread().getName().startsWith("TEST-")
102-
: Thread.currentThread().getName();
101+
assert MasterService.assertMasterUpdateOrTestThread();
103102
trackedNodes.computeIfPresent(discoveryNode.getId(), (ignored, trackedNode) -> trackedNode.withRemovalReason(reason));
104103
}
105104

server/src/main/java/org/elasticsearch/cluster/routing/RoutingNodes.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -275,8 +275,7 @@ public RoutingNode node(String nodeId) {
275275

276276
public Set<String> getAttributeValues(String attributeName) {
277277
// Only ever accessed on the master service thread so no need for synchronization
278-
assert MasterService.isMasterUpdateThread() || Thread.currentThread().getName().startsWith("TEST-")
279-
: Thread.currentThread().getName() + " should be the master service thread";
278+
assert MasterService.assertMasterUpdateOrTestThread();
280279
return attributeValuesByAttribute.computeIfAbsent(
281280
attributeName,
282281
ignored -> stream().map(r -> r.node().getAttributes().get(attributeName)).filter(Objects::nonNull).collect(Collectors.toSet())

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -195,10 +195,10 @@ public ClusterApplierService getClusterApplierService() {
195195
}
196196

197197
public static boolean assertClusterOrMasterStateThread() {
198-
assert Thread.currentThread().getName().contains(ClusterApplierService.CLUSTER_UPDATE_THREAD_NAME)
199-
|| Thread.currentThread().getName().contains(MasterService.MASTER_UPDATE_THREAD_NAME)
200-
: "not called from the master/cluster state update thread";
201-
return true;
198+
return ThreadPool.assertCurrentThreadPool(
199+
ClusterApplierService.CLUSTER_UPDATE_THREAD_NAME,
200+
MasterService.MASTER_UPDATE_THREAD_NAME
201+
);
202202
}
203203

204204
public ClusterName getClusterName() {

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,10 @@ public static boolean isMasterUpdateThread() {
225225
return Thread.currentThread().getName().contains('[' + MASTER_UPDATE_THREAD_NAME + ']');
226226
}
227227

228+
public static boolean assertMasterUpdateOrTestThread() {
229+
return ThreadPool.assertCurrentThreadPool(MASTER_UPDATE_THREAD_NAME);
230+
}
231+
228232
public static boolean assertNotMasterUpdateThread(String reason) {
229233
assert isMasterUpdateThread() == false
230234
: "Expected current thread [" + Thread.currentThread() + "] to not be the master service thread. Reason: [" + reason + "]";
@@ -794,8 +798,7 @@ public T getTask() {
794798
}
795799

796800
private boolean incomplete() {
797-
assert MasterService.isMasterUpdateThread() || Thread.currentThread().getName().startsWith("TEST-")
798-
: Thread.currentThread().getName();
801+
assert assertMasterUpdateOrTestThread();
799802
return publishedStateConsumer == null && onPublicationSuccess == null && failure == null;
800803
}
801804

server/src/main/java/org/elasticsearch/common/io/DiskIoBufferPool.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
import org.elasticsearch.threadpool.ThreadPool;
1414

1515
import java.nio.ByteBuffer;
16-
import java.util.Arrays;
1716

1817
public class DiskIoBufferPool {
1918

@@ -50,14 +49,15 @@ public ByteBuffer maybeGetDirectIOBuffer() {
5049
return ioBuffer.clear();
5150
}
5251

52+
private static final String[] WRITE_OR_FLUSH_THREAD_NAMES = new String[] {
53+
"[" + ThreadPool.Names.WRITE + "]",
54+
"[" + ThreadPool.Names.FLUSH + "]",
55+
"[" + ThreadPool.Names.SYSTEM_WRITE + "]",
56+
"[" + ThreadPool.Names.SYSTEM_CRITICAL_WRITE + "]" };
57+
5358
private static boolean isWriteOrFlushThread() {
5459
String threadName = Thread.currentThread().getName();
55-
for (String s : Arrays.asList(
56-
"[" + ThreadPool.Names.WRITE + "]",
57-
"[" + ThreadPool.Names.FLUSH + "]",
58-
"[" + ThreadPool.Names.SYSTEM_WRITE + "]",
59-
"[" + ThreadPool.Names.SYSTEM_CRITICAL_WRITE + "]"
60-
)) {
60+
for (String s : WRITE_OR_FLUSH_THREAD_NAMES) {
6161
if (threadName.contains(s)) {
6262
return true;
6363
}

server/src/main/java/org/elasticsearch/index/shard/StoreRecovery.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -545,9 +545,7 @@ private void restore(
545545
}
546546
assert indexShard.getEngineOrNull() == null;
547547
indexIdListener.whenComplete(idx -> {
548-
assert Thread.currentThread().getName().contains('[' + ThreadPool.Names.GENERIC + ']')
549-
|| Thread.currentThread().getName().contains('[' + ThreadPool.Names.SNAPSHOT + ']')
550-
|| Thread.currentThread().getName().startsWith("TEST-") : Thread.currentThread().getName();
548+
assert ThreadPool.assertCurrentThreadPool(ThreadPool.Names.GENERIC, ThreadPool.Names.SNAPSHOT);
551549
repository.restoreShard(
552550
indexShard.store(),
553551
restoreSource.snapshot().getSnapshotId(),

server/src/main/java/org/elasticsearch/indices/recovery/plan/ShardSnapshotsService.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ public void fetchLatestSnapshotsForShard(ShardId shardId, ActionListener<Optiona
109109
}
110110

111111
private Optional<ShardSnapshot> fetchSnapshotFiles(GetShardSnapshotResponse shardSnapshotResponse) {
112-
assert Thread.currentThread().getName().contains(ThreadPool.Names.GENERIC);
112+
assert ThreadPool.assertCurrentThreadPool(ThreadPool.Names.GENERIC);
113113

114114
final Optional<ShardSnapshotInfo> latestShardSnapshotOpt = shardSnapshotResponse.getLatestShardSnapshot();
115115
if (latestShardSnapshotOpt.isEmpty()) {

server/src/main/java/org/elasticsearch/repositories/IndexSnapshotsService.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,7 @@ public void getLatestSuccessfulSnapshotForShard(
9595
}, listener::onFailure);
9696

9797
snapshotInfoStepListener.whenComplete(fetchSnapshotContext -> {
98-
assert Thread.currentThread().getName().contains('[' + ThreadPool.Names.SNAPSHOT_META + ']')
99-
: "Expected current thread [" + Thread.currentThread() + "] to be a snapshot meta thread.";
98+
assert ThreadPool.assertCurrentThreadPool(ThreadPool.Names.SNAPSHOT_META);
10099
final SnapshotInfo snapshotInfo = fetchSnapshotContext.getSnapshotInfo();
101100

102101
if (snapshotInfo == null || snapshotInfo.state() != SnapshotState.SUCCESS) {

server/src/main/java/org/elasticsearch/repositories/Repository.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -317,9 +317,6 @@ default Map<String, Object> adaptUserMetadata(Map<String, Object> userMetadata)
317317
void awaitIdle();
318318

319319
static boolean assertSnapshotMetaThread() {
320-
final String threadName = Thread.currentThread().getName();
321-
assert threadName.contains('[' + ThreadPool.Names.SNAPSHOT_META + ']') || threadName.startsWith("TEST-")
322-
: "Expected current thread [" + Thread.currentThread() + "] to be a snapshot meta thread.";
323-
return true;
320+
return ThreadPool.assertCurrentThreadPool(ThreadPool.Names.SNAPSHOT_META);
324321
}
325322
}

server/src/main/java/org/elasticsearch/repositories/blobstore/BlobStoreRepository.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1636,10 +1636,7 @@ public long getRestoreThrottleTimeInNanos() {
16361636
}
16371637

16381638
protected void assertSnapshotOrGenericThread() {
1639-
assert Thread.currentThread().getName().contains('[' + ThreadPool.Names.SNAPSHOT + ']')
1640-
|| Thread.currentThread().getName().contains('[' + ThreadPool.Names.SNAPSHOT_META + ']')
1641-
|| Thread.currentThread().getName().contains('[' + ThreadPool.Names.GENERIC + ']')
1642-
: "Expected current thread [" + Thread.currentThread() + "] to be the snapshot or generic thread.";
1639+
assert ThreadPool.assertCurrentThreadPool(ThreadPool.Names.SNAPSHOT, ThreadPool.Names.SNAPSHOT_META, ThreadPool.Names.GENERIC);
16431640
}
16441641

16451642
@Override

server/src/main/java/org/elasticsearch/threadpool/ThreadPool.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -908,6 +908,15 @@ public static boolean assertNotScheduleThread(String reason) {
908908
return true;
909909
}
910910

911+
public static boolean assertCurrentThreadPool(String... permittedThreadPoolNames) {
912+
final var threadName = Thread.currentThread().getName();
913+
assert threadName.startsWith("TEST-")
914+
|| threadName.startsWith("LuceneTestCase")
915+
|| Arrays.stream(permittedThreadPoolNames).anyMatch(n -> threadName.contains('[' + n + ']'))
916+
: threadName + " not in " + Arrays.toString(permittedThreadPoolNames) + " nor a test thread";
917+
return true;
918+
}
919+
911920
public static boolean assertCurrentMethodIsNotCalledRecursively() {
912921
final StackTraceElement[] stackTraceElements = Thread.currentThread().getStackTrace();
913922
assert stackTraceElements.length >= 3 : stackTraceElements.length;

server/src/main/java/org/elasticsearch/transport/Transports.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
import org.elasticsearch.http.HttpServerTransport;
1313
import org.elasticsearch.tasks.Task;
1414

15-
import java.util.Arrays;
1615
import java.util.Set;
1716

1817
public enum Transports {
@@ -26,18 +25,19 @@ public enum Transports {
2625
/** threads whose name is prefixed by this string will be considered network threads, even though they aren't */
2726
public static final String TEST_MOCK_TRANSPORT_THREAD_PREFIX = "__mock_network_thread";
2827

28+
private static final String[] TRANSPORT_THREAD_NAMES = new String[] {
29+
'[' + HttpServerTransport.HTTP_SERVER_WORKER_THREAD_NAME_PREFIX + ']',
30+
'[' + TcpTransport.TRANSPORT_WORKER_THREAD_NAME_PREFIX + ']',
31+
TEST_MOCK_TRANSPORT_THREAD_PREFIX };
32+
2933
/**
3034
* Utility method to detect whether a thread is a network thread. Typically
3135
* used in assertions to make sure that we do not call blocking code from
3236
* networking threads.
3337
*/
3438
public static boolean isTransportThread(Thread t) {
3539
final String threadName = t.getName();
36-
for (String s : Arrays.asList(
37-
HttpServerTransport.HTTP_SERVER_WORKER_THREAD_NAME_PREFIX,
38-
TcpTransport.TRANSPORT_WORKER_THREAD_NAME_PREFIX,
39-
TEST_MOCK_TRANSPORT_THREAD_PREFIX
40-
)) {
40+
for (String s : TRANSPORT_THREAD_NAMES) {
4141
if (threadName.contains(s)) {
4242
return true;
4343
}

x-pack/plugin/enrich/src/main/java/org/elasticsearch/xpack/enrich/action/EnrichCoordinatorProxyAction.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,10 +71,12 @@ protected void doExecute(Task task, SearchRequest request, ActionListener<Search
7171
// Management tp is expected when executing enrich processor from ingest simulate api
7272
// Search tp is allowed for now - After enriching, the remaining parts of the pipeline are processed on the
7373
// search thread, which could end up here again if there is more than one enrich processor in a pipeline.
74-
assert Thread.currentThread().getName().contains(ThreadPool.Names.WRITE)
75-
|| Thread.currentThread().getName().contains(ThreadPool.Names.SYSTEM_WRITE)
76-
|| Thread.currentThread().getName().contains(ThreadPool.Names.SEARCH)
77-
|| Thread.currentThread().getName().contains(ThreadPool.Names.MANAGEMENT);
74+
assert ThreadPool.assertCurrentThreadPool(
75+
ThreadPool.Names.WRITE,
76+
ThreadPool.Names.SYSTEM_WRITE,
77+
ThreadPool.Names.SEARCH,
78+
ThreadPool.Names.MANAGEMENT
79+
);
7880
coordinator.schedule(request, listener);
7981
}
8082
}

x-pack/plugin/searchable-snapshots/src/main/java/org/elasticsearch/xpack/searchablesnapshots/allocation/SearchableSnapshotIndexEventListener.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ public SearchableSnapshotIndexEventListener(
5656
*/
5757
@Override
5858
public void beforeIndexShardRecovery(IndexShard indexShard, IndexSettings indexSettings) {
59-
assert Thread.currentThread().getName().contains(ThreadPool.Names.GENERIC);
59+
assert ThreadPool.assertCurrentThreadPool(ThreadPool.Names.GENERIC);
6060
ensureSnapshotIsLoaded(indexShard);
6161
}
6262

x-pack/plugin/searchable-snapshots/src/main/java/org/elasticsearch/xpack/searchablesnapshots/cache/blob/BlobStoreCacheMaintenanceService.java

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -368,7 +368,7 @@ public void onFailure(Exception e) {
368368
}
369369

370370
void executeNextCleanUp(final Queue<Tuple<DeleteByQueryRequest, ActionListener<BulkByScrollResponse>>> queue) {
371-
assert Thread.currentThread().getName().contains(ThreadPool.Names.GENERIC);
371+
assert ThreadPool.assertCurrentThreadPool(ThreadPool.Names.GENERIC);
372372
final Tuple<DeleteByQueryRequest, ActionListener<BulkByScrollResponse>> next = queue.poll();
373373
if (next != null) {
374374
cleanUp(next.v1(), next.v2(), queue);
@@ -380,7 +380,7 @@ void cleanUp(
380380
final ActionListener<BulkByScrollResponse> listener,
381381
final Queue<Tuple<DeleteByQueryRequest, ActionListener<BulkByScrollResponse>>> queue
382382
) {
383-
assert Thread.currentThread().getName().contains(ThreadPool.Names.GENERIC);
383+
assert ThreadPool.assertCurrentThreadPool(ThreadPool.Names.GENERIC);
384384
clientWithOrigin.execute(DeleteByQueryAction.INSTANCE, request, ActionListener.runAfter(listener, () -> {
385385
if (queue.isEmpty() == false) {
386386
threadPool.generic().execute(() -> executeNextCleanUp(queue));
@@ -429,7 +429,7 @@ private class PeriodicMaintenanceTask implements Runnable, Releasable {
429429

430430
@Override
431431
public void run() {
432-
assert assertGenericThread();
432+
assert ThreadPool.assertCurrentThreadPool(ThreadPool.Names.GENERIC);
433433
try {
434434
ensureOpen();
435435
if (pointIntTimeId == null) {
@@ -682,12 +682,6 @@ private void executeNext(PeriodicMaintenanceTask maintenanceTask) {
682682
threadPool.generic().execute(maintenanceTask);
683683
}
684684

685-
private static boolean assertGenericThread() {
686-
final String threadName = Thread.currentThread().getName();
687-
assert threadName.contains(ThreadPool.Names.GENERIC) : threadName;
688-
return true;
689-
}
690-
691685
private static Instant getCreationTime(SearchHit searchHit) {
692686
final DocumentField creationTimeField = searchHit.field(CachedBlob.CREATION_TIME_FIELD);
693687
assert creationTimeField != null;

x-pack/plugin/searchable-snapshots/src/main/java/org/elasticsearch/xpack/searchablesnapshots/cache/full/CacheService.java

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -370,7 +370,7 @@ public void onFailure(Exception e) {
370370
* @param shardId the {@link ShardId}
371371
*/
372372
public void waitForCacheFilesEvictionIfNeeded(String snapshotUUID, String snapshotIndexName, ShardId shardId) {
373-
assert assertGenericThreadPool();
373+
assert ThreadPool.assertCurrentThreadPool(ThreadPool.Names.GENERIC);
374374
final Future<?> future;
375375
synchronized (shardsEvictionsMutex) {
376376
if (allowShardsEvictions == false) {
@@ -391,7 +391,7 @@ public void waitForCacheFilesEvictionIfNeeded(String snapshotUUID, String snapsh
391391
*/
392392
private void processShardEviction(ShardEviction shardEviction) {
393393
assert isPendingShardEviction(shardEviction) : "shard is not marked as evicted: " + shardEviction;
394-
assert assertGenericThreadPool();
394+
assert ThreadPool.assertCurrentThreadPool(ThreadPool.Names.GENERIC);
395395

396396
shardsEvictionsLock.readLock().lock();
397397
try {
@@ -735,13 +735,6 @@ boolean matches(CacheKey cacheKey) {
735735
}
736736
}
737737

738-
private static boolean assertGenericThreadPool() {
739-
final String threadName = Thread.currentThread().getName();
740-
assert threadName.contains('[' + ThreadPool.Names.GENERIC + ']') || threadName.startsWith("TEST-")
741-
: "expected generic thread pool but got " + threadName;
742-
return true;
743-
}
744-
745738
private enum CacheFileEventType {
746739
NEEDS_FSYNC,
747740
DELETE

x-pack/plugin/searchable-snapshots/src/main/java/org/elasticsearch/xpack/searchablesnapshots/store/SearchableSnapshotDirectory.java

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -193,15 +193,6 @@ private synchronized boolean invariant() {
193193
return true;
194194
}
195195

196-
protected final boolean assertCurrentThreadMayLoadSnapshot() {
197-
final String threadName = Thread.currentThread().getName();
198-
assert threadName.contains('[' + ThreadPool.Names.GENERIC + ']')
199-
// Unit tests access the blob store on the main test thread; simplest just to permit this rather than have them override this
200-
// method somehow.
201-
|| threadName.startsWith("TEST-") : "current thread [" + Thread.currentThread() + "] may not load " + snapshotId;
202-
return true;
203-
}
204-
205196
/**
206197
* Loads the snapshot if and only if the snapshot is not loaded yet.
207198
*
@@ -213,7 +204,7 @@ public boolean loadSnapshot(RecoveryState snapshotRecoveryState, ActionListener<
213204
assert snapshotRecoveryState.getRecoverySource().getType() == RecoverySource.Type.SNAPSHOT
214205
|| snapshotRecoveryState.getRecoverySource().getType() == RecoverySource.Type.PEER
215206
: snapshotRecoveryState.getRecoverySource().getType();
216-
assert assertCurrentThreadMayLoadSnapshot();
207+
assert ThreadPool.assertCurrentThreadPool(ThreadPool.Names.GENERIC);
217208
// noinspection ConstantConditions in case assertions are disabled
218209
if (snapshotRecoveryState instanceof SearchableSnapshotRecoveryState == false) {
219210
throw new IllegalArgumentException("A SearchableSnapshotRecoveryState instance was expected");

0 commit comments

Comments
 (0)