Skip to content

Commit 91d6ea9

Browse files
committed
Assert for no duplicate persistent task executor
The same persistent task name should not be registered twice with different executors. This PR adds an assertion for it. Relates: ES-10533
1 parent 26e5373 commit 91d6ea9

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

server/src/main/java/org/elasticsearch/persistent/PersistentTasksExecutorRegistry.java

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
*/
99
package org.elasticsearch.persistent;
1010

11+
import org.elasticsearch.core.Strings;
12+
1113
import java.util.Collection;
1214
import java.util.Collections;
1315
import java.util.HashMap;
@@ -23,7 +25,17 @@ public class PersistentTasksExecutorRegistry {
2325
public PersistentTasksExecutorRegistry(Collection<PersistentTasksExecutor<?>> taskExecutors) {
2426
Map<String, PersistentTasksExecutor<?>> map = new HashMap<>();
2527
for (PersistentTasksExecutor<?> executor : taskExecutors) {
26-
map.put(executor.getTaskName(), executor);
28+
final var old = map.put(executor.getTaskName(), executor);
29+
if (old != null) {
30+
final var message = Strings.format(
31+
"task [%s] is already registered with [%s], cannot re-register with [%s]",
32+
executor.getTaskName(),
33+
old,
34+
executor
35+
);
36+
assert false : message;
37+
throw new IllegalStateException(message);
38+
}
2739
}
2840
this.taskExecutors = Collections.unmodifiableMap(map);
2941
}

0 commit comments

Comments
 (0)