Skip to content

Commit d875e8c

Browse files
docs and assertions
1 parent 54e9dea commit d875e8c

File tree

3 files changed

+28
-20
lines changed

3 files changed

+28
-20
lines changed

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import org.elasticsearch.common.util.concurrent.CountDown;
1414
import org.elasticsearch.snapshots.SnapshotId;
1515
import org.elasticsearch.snapshots.SnapshotInfo;
16+
import org.elasticsearch.threadpool.ThreadPool;
1617

1718
import java.util.Collection;
1819
import java.util.List;
@@ -46,12 +47,13 @@ public final class GetSnapshotInfoContext implements ActionListener<SnapshotInfo
4647
* Listener resolved when fetching {@link SnapshotInfo} has completed. If resolved successfully, no more calls to
4748
* {@link #consumer} will be made. Only resolves exceptionally if {@link #abortOnFailure} is true in case one or more
4849
* {@link SnapshotInfo} failed to be fetched.
50+
* This listener is always invoked on the {@link ThreadPool.Names#SNAPSHOT_META} pool.
4951
*/
5052
private final ActionListener<Void> doneListener;
5153

5254
/**
5355
* {@link BiConsumer} invoked for each {@link SnapshotInfo} that is fetched with this instance and the {@code SnapshotInfo} as
54-
* arguments.
56+
* arguments. This consumer is always invoked on the {@link ThreadPool.Names#SNAPSHOT_META} pool.
5557
*/
5658
private final BiConsumer<GetSnapshotInfoContext, SnapshotInfo> consumer;
5759

@@ -102,6 +104,7 @@ public boolean done() {
102104

103105
@Override
104106
public void onResponse(SnapshotInfo snapshotInfo) {
107+
assert Repository.assertSnapshotMetaThread();
105108
try {
106109
consumer.accept(this, snapshotInfo);
107110
} catch (Exception e) {
@@ -121,6 +124,7 @@ public void onResponse(SnapshotInfo snapshotInfo) {
121124

122125
@Override
123126
public void onFailure(Exception e) {
127+
assert Repository.assertSnapshotMetaThread();
124128
if (abortOnFailure) {
125129
if (counter.fastForward()) {
126130
failDoneListener(e);

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

Lines changed: 22 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import org.elasticsearch.indices.recovery.RecoveryState;
2626
import org.elasticsearch.snapshots.SnapshotId;
2727
import org.elasticsearch.snapshots.SnapshotInfo;
28+
import org.elasticsearch.threadpool.ThreadPool;
2829

2930
import java.io.IOException;
3031
import java.util.Collection;
@@ -81,28 +82,23 @@ default Repository create(RepositoryMetadata metadata, Function<String, Reposito
8182
* Reads a single snapshot description from the repository
8283
*
8384
* @param snapshotId snapshot id to read description for
84-
* @param listener listener to resolve with snapshot description
85+
* @param listener listener to resolve with snapshot description (is resolved on the {@link ThreadPool.Names#SNAPSHOT_META} pool)
8586
*/
8687
default void getSnapshotInfo(SnapshotId snapshotId, ActionListener<SnapshotInfo> listener) {
87-
getSnapshotInfo(
88-
new GetSnapshotInfoContext(
89-
List.of(snapshotId),
90-
true,
91-
() -> false,
92-
(context, snapshotInfo) -> listener.onResponse(snapshotInfo),
93-
new ActionListener<>() {
94-
@Override
95-
public void onResponse(Void o) {
96-
// ignored
97-
}
88+
getSnapshotInfo(new GetSnapshotInfoContext(List.of(snapshotId), true, () -> false, (context, snapshotInfo) -> {
89+
assert Repository.assertSnapshotMetaThread();
90+
listener.onResponse(snapshotInfo);
91+
}, new ActionListener<>() {
92+
@Override
93+
public void onResponse(Void o) {
94+
// ignored
95+
}
9896

99-
@Override
100-
public void onFailure(Exception e) {
101-
listener.onFailure(e);
102-
}
103-
}
104-
)
105-
);
97+
@Override
98+
public void onFailure(Exception e) {
99+
listener.onFailure(e);
100+
}
101+
}));
106102
}
107103

108104
/**
@@ -324,4 +320,11 @@ void cloneShardSnapshot(
324320
default Map<String, Object> adaptUserMetadata(Map<String, Object> userMetadata) {
325321
return userMetadata;
326322
}
323+
324+
static boolean assertSnapshotMetaThread() {
325+
final String threadName = Thread.currentThread().getName();
326+
assert threadName.contains('[' + ThreadPool.Names.SNAPSHOT_META + ']') || threadName.startsWith("TEST-")
327+
: "Expected current thread [" + Thread.currentThread() + "] to be a snapshot meta thread.";
328+
return true;
329+
}
327330
}

server/src/main/java/org/elasticsearch/snapshots/RestoreService.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,7 @@ private void startRestore(
289289
BiConsumer<ClusterState, Metadata.Builder> updater,
290290
ActionListener<RestoreCompletionResponse> listener
291291
) throws IOException {
292+
assert Repository.assertSnapshotMetaThread();
292293
final SnapshotId snapshotId = snapshotInfo.snapshotId();
293294
final String repositoryName = repository.getMetadata().name();
294295
final Snapshot snapshot = new Snapshot(repositoryName, snapshotId);

0 commit comments

Comments
 (0)