Remove parent-less task methods

Callers should explicitly handle parents - either using EMPTY_TASK_ID when
a parent isn't possible or piping parents from the TransportRequest when
possible.
This commit is contained in:
Nik Everett 2016-04-19 17:49:13 -04:00
parent 2b56a42b69
commit ffeb5e38fc
7 changed files with 14 additions and 18 deletions

View File

@ -202,8 +202,8 @@ public abstract class ReplicationRequest<Request extends ReplicationRequest<Requ
}
@Override
public Task createTask(long id, String type, String action, TaskId parentTaskId) {
return new ReplicationTask(id, type, action, getDescription(), parentTaskId);
public Task createTask(long id, String type, String action) {
return new ReplicationTask(id, type, action, getDescription(), getParentTask());
}
/**

View File

@ -30,10 +30,6 @@ public class CancellableTask extends Task {
private final AtomicReference<String> reason = new AtomicReference<>();
public CancellableTask(long id, String type, String action, String description) {
super(id, type, action, description);
}
public CancellableTask(long id, String type, String action, String description, TaskId parentTaskId) {
super(id, type, action, description, parentTaskId);
}

View File

@ -44,10 +44,6 @@ public class Task {
private final long startTimeNanos;
public Task(long id, String type, String action, String description) {
this(id, type, action, description, TaskId.EMPTY_TASK_ID);
}
public Task(long id, String type, String action, String description, TaskId parentTask) {
this(id, type, action, description, parentTask, System.currentTimeMillis(), System.nanoTime());
}

View File

@ -49,22 +49,25 @@ public abstract class TransportRequest extends TransportMessage {
}
/**
* Set a reference to task that caused this task to be run.
* Set a reference to task that created this request.
*/
public void setParentTask(TaskId taskId) {
this.parentTaskId = taskId;
}
/**
* Get a reference to the task that created this request. Defaults to {@link TaskId#EMPTY_TASK_ID}, meaning "there is no parent".
*/
public TaskId getParentTask() {
return parentTaskId;
}
/**
* Returns the task object that should be used to keep track of the processing of the request.
*
* A request can override this method and return null to avoid being tracked by the task manager.
*/
public Task createTask(long id, String type, String action) {
return new Task(id, type, action, getDescription());
}
public Task createTask(long id, String type, String action, TaskId parentTaskId) {
return new Task(id, type, action, getDescription(), parentTaskId);
}

View File

@ -126,7 +126,7 @@ public class CancellableTasksTests extends TaskManagerTestCase {
@Override
public Task createTask(long id, String type, String action) {
return new CancellableTask(id, type, action, getDescription());
return new CancellableTask(id, type, action, getDescription(), TaskId.EMPTY_TASK_ID);
}
}

View File

@ -209,7 +209,7 @@ public class TestTaskPlugin extends Plugin {
@Override
public Task createTask(long id, String type, String action) {
return new CancellableTask(id, type, action, getDescription());
return new CancellableTask(id, type, action, getDescription(), TaskId.EMPTY_TASK_ID);
}
}

View File

@ -28,6 +28,7 @@ import org.elasticsearch.common.util.concurrent.FutureUtils;
import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.tasks.CancellableTask;
import org.elasticsearch.tasks.Task;
import org.elasticsearch.tasks.TaskId;
import org.elasticsearch.threadpool.ThreadPool;
import java.io.IOException;
@ -70,7 +71,7 @@ public class BulkByScrollTask extends CancellableTask {
private final AtomicReference<DelayedPrepareBulkRequest> delayedPrepareBulkRequestReference = new AtomicReference<>();
public BulkByScrollTask(long id, String type, String action, String description, float requestsPerSecond) {
super(id, type, action, description);
super(id, type, action, description, TaskId.EMPTY_TASK_ID);
setRequestsPerSecond(requestsPerSecond);
}