Add proper toString() method to UpdateTask (#21582)
Adds a proper toString() method to ClusterService.UpdateTask
This commit is contained in:
parent
d7fa2eb155
commit
aa73a76ffd
|
@ -451,7 +451,7 @@ public class ClusterService extends AbstractLifecycleComponent {
|
||||||
// convert to an identity map to check for dups based on update tasks semantics of using identity instead of equal
|
// convert to an identity map to check for dups based on update tasks semantics of using identity instead of equal
|
||||||
final IdentityHashMap<T, ClusterStateTaskListener> tasksIdentity = new IdentityHashMap<>(tasks);
|
final IdentityHashMap<T, ClusterStateTaskListener> tasksIdentity = new IdentityHashMap<>(tasks);
|
||||||
final List<UpdateTask<T>> updateTasks = tasksIdentity.entrySet().stream().map(
|
final List<UpdateTask<T>> updateTasks = tasksIdentity.entrySet().stream().map(
|
||||||
entry -> new UpdateTask<>(source, entry.getKey(), config, executor, safe(entry.getValue(), logger))
|
entry -> new UpdateTask<>(source, entry.getKey(), config.priority(), executor, safe(entry.getValue(), logger))
|
||||||
).collect(Collectors.toList());
|
).collect(Collectors.toList());
|
||||||
|
|
||||||
synchronized (updateTasksPerExecutor) {
|
synchronized (updateTasksPerExecutor) {
|
||||||
|
@ -590,11 +590,11 @@ public class ClusterService extends AbstractLifecycleComponent {
|
||||||
if (pending != null) {
|
if (pending != null) {
|
||||||
for (UpdateTask<T> task : pending) {
|
for (UpdateTask<T> task : pending) {
|
||||||
if (task.processed.getAndSet(true) == false) {
|
if (task.processed.getAndSet(true) == false) {
|
||||||
logger.trace("will process {}", task.toString(executor));
|
logger.trace("will process {}", task);
|
||||||
toExecute.add(task);
|
toExecute.add(task);
|
||||||
processTasksBySource.computeIfAbsent(task.source, s -> new ArrayList<>()).add(task.task);
|
processTasksBySource.computeIfAbsent(task.source, s -> new ArrayList<>()).add(task.task);
|
||||||
} else {
|
} else {
|
||||||
logger.trace("skipping {}, already processed", task.toString(executor));
|
logger.trace("skipping {}, already processed", task);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -652,7 +652,7 @@ public class ClusterService extends AbstractLifecycleComponent {
|
||||||
if (assertsEnabled) {
|
if (assertsEnabled) {
|
||||||
for (UpdateTask<T> updateTask : toExecute) {
|
for (UpdateTask<T> updateTask : toExecute) {
|
||||||
assert batchResult.executionResults.containsKey(updateTask.task) :
|
assert batchResult.executionResults.containsKey(updateTask.task) :
|
||||||
"missing task result for " + updateTask.toString(executor);
|
"missing task result for " + updateTask;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -660,7 +660,7 @@ public class ClusterService extends AbstractLifecycleComponent {
|
||||||
final ArrayList<UpdateTask<T>> proccessedListeners = new ArrayList<>();
|
final ArrayList<UpdateTask<T>> proccessedListeners = new ArrayList<>();
|
||||||
// fail all tasks that have failed and extract those that are waiting for results
|
// fail all tasks that have failed and extract those that are waiting for results
|
||||||
for (UpdateTask<T> updateTask : toExecute) {
|
for (UpdateTask<T> updateTask : toExecute) {
|
||||||
assert batchResult.executionResults.containsKey(updateTask.task) : "missing " + updateTask.toString(executor);
|
assert batchResult.executionResults.containsKey(updateTask.task) : "missing " + updateTask;
|
||||||
final ClusterStateTaskExecutor.TaskResult executionResult =
|
final ClusterStateTaskExecutor.TaskResult executionResult =
|
||||||
batchResult.executionResults.get(updateTask.task);
|
batchResult.executionResults.get(updateTask.task);
|
||||||
executionResult.handle(
|
executionResult.handle(
|
||||||
|
@ -668,7 +668,7 @@ public class ClusterService extends AbstractLifecycleComponent {
|
||||||
ex -> {
|
ex -> {
|
||||||
logger.debug(
|
logger.debug(
|
||||||
(Supplier<?>)
|
(Supplier<?>)
|
||||||
() -> new ParameterizedMessage("cluster state update task {} failed", updateTask.toString(executor)), ex);
|
() -> new ParameterizedMessage("cluster state update task {} failed", updateTask), ex);
|
||||||
updateTask.listener.onFailure(updateTask.source, ex);
|
updateTask.listener.onFailure(updateTask.source, ex);
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
@ -944,16 +944,13 @@ public class ClusterService extends AbstractLifecycleComponent {
|
||||||
class UpdateTask<T> extends SourcePrioritizedRunnable {
|
class UpdateTask<T> extends SourcePrioritizedRunnable {
|
||||||
|
|
||||||
public final T task;
|
public final T task;
|
||||||
public final ClusterStateTaskConfig config;
|
|
||||||
public final ClusterStateTaskExecutor<T> executor;
|
|
||||||
public final ClusterStateTaskListener listener;
|
public final ClusterStateTaskListener listener;
|
||||||
|
private final ClusterStateTaskExecutor<T> executor;
|
||||||
public final AtomicBoolean processed = new AtomicBoolean();
|
public final AtomicBoolean processed = new AtomicBoolean();
|
||||||
|
|
||||||
UpdateTask(String source, T task, ClusterStateTaskConfig config, ClusterStateTaskExecutor<T> executor,
|
UpdateTask(String source, T task, Priority priority, ClusterStateTaskExecutor<T> executor, ClusterStateTaskListener listener) {
|
||||||
ClusterStateTaskListener listener) {
|
super(priority, source);
|
||||||
super(config.priority(), source);
|
|
||||||
this.task = task;
|
this.task = task;
|
||||||
this.config = config;
|
|
||||||
this.executor = executor;
|
this.executor = executor;
|
||||||
this.listener = listener;
|
this.listener = listener;
|
||||||
}
|
}
|
||||||
|
@ -967,7 +964,8 @@ public class ClusterService extends AbstractLifecycleComponent {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public String toString(ClusterStateTaskExecutor<T> executor) {
|
@Override
|
||||||
|
public String toString() {
|
||||||
String taskDescription = executor.describeTasks(Collections.singletonList(task));
|
String taskDescription = executor.describeTasks(Collections.singletonList(task));
|
||||||
if (taskDescription.isEmpty()) {
|
if (taskDescription.isEmpty()) {
|
||||||
return "[" + source + "]";
|
return "[" + source + "]";
|
||||||
|
|
Loading…
Reference in New Issue