mirror of https://github.com/apache/druid.git
Fetch active task payloads from memory (#15377)
The TaskQueue maintains a map of active task ids to tasks, which can be utilized to get active task payloads, before falling back to the metadata store.
This commit is contained in:
parent
6a5da5a05e
commit
77828bead4
|
@ -947,6 +947,17 @@ public class TaskQueue
|
||||||
return stats;
|
return stats;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Optional<Task> getActiveTask(String id)
|
||||||
|
{
|
||||||
|
giant.lock();
|
||||||
|
try {
|
||||||
|
return Optional.fromNullable(tasks.get(id));
|
||||||
|
}
|
||||||
|
finally {
|
||||||
|
giant.unlock();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
List<Task> getTasks()
|
List<Task> getTasks()
|
||||||
{
|
{
|
||||||
|
|
|
@ -48,12 +48,14 @@ public class TaskStorageQueryAdapter
|
||||||
{
|
{
|
||||||
private final TaskStorage storage;
|
private final TaskStorage storage;
|
||||||
private final TaskLockbox taskLockbox;
|
private final TaskLockbox taskLockbox;
|
||||||
|
private final Optional<TaskQueue> taskQueue;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
public TaskStorageQueryAdapter(TaskStorage storage, TaskLockbox taskLockbox)
|
public TaskStorageQueryAdapter(TaskStorage storage, TaskLockbox taskLockbox, TaskMaster taskMaster)
|
||||||
{
|
{
|
||||||
this.storage = storage;
|
this.storage = storage;
|
||||||
this.taskLockbox = taskLockbox;
|
this.taskLockbox = taskLockbox;
|
||||||
|
this.taskQueue = taskMaster.getTaskQueue();
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<Task> getActiveTasks()
|
public List<Task> getActiveTasks()
|
||||||
|
@ -104,6 +106,12 @@ public class TaskStorageQueryAdapter
|
||||||
|
|
||||||
public Optional<Task> getTask(final String taskid)
|
public Optional<Task> getTask(final String taskid)
|
||||||
{
|
{
|
||||||
|
if (taskQueue.isPresent()) {
|
||||||
|
Optional<Task> activeTask = taskQueue.get().getActiveTask(taskid);
|
||||||
|
if (activeTask.isPresent()) {
|
||||||
|
return activeTask;
|
||||||
|
}
|
||||||
|
}
|
||||||
return storage.getTask(taskid);
|
return storage.getTask(taskid);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -482,7 +482,10 @@ public class TaskLifecycleTest extends InitializedNullHandlingTest
|
||||||
default:
|
default:
|
||||||
throw new RE("Unknown task storage type [%s]", taskStorageType);
|
throw new RE("Unknown task storage type [%s]", taskStorageType);
|
||||||
}
|
}
|
||||||
tsqa = new TaskStorageQueryAdapter(taskStorage, taskLockbox);
|
TaskMaster taskMaster = EasyMock.createMock(TaskMaster.class);
|
||||||
|
EasyMock.expect(taskMaster.getTaskQueue()).andReturn(Optional.absent()).anyTimes();
|
||||||
|
EasyMock.replay(taskMaster);
|
||||||
|
tsqa = new TaskStorageQueryAdapter(taskStorage, taskLockbox, taskMaster);
|
||||||
return taskStorage;
|
return taskStorage;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -257,7 +257,7 @@ public class OverlordTest
|
||||||
Assert.assertEquals(taskMaster.getCurrentLeader(), druidNode.getHostAndPort());
|
Assert.assertEquals(taskMaster.getCurrentLeader(), druidNode.getHostAndPort());
|
||||||
Assert.assertEquals(Optional.absent(), taskMaster.getRedirectLocation());
|
Assert.assertEquals(Optional.absent(), taskMaster.getRedirectLocation());
|
||||||
|
|
||||||
final TaskStorageQueryAdapter taskStorageQueryAdapter = new TaskStorageQueryAdapter(taskStorage, taskLockbox);
|
final TaskStorageQueryAdapter taskStorageQueryAdapter = new TaskStorageQueryAdapter(taskStorage, taskLockbox, taskMaster);
|
||||||
final WorkerTaskRunnerQueryAdapter workerTaskRunnerQueryAdapter = new WorkerTaskRunnerQueryAdapter(taskMaster, null);
|
final WorkerTaskRunnerQueryAdapter workerTaskRunnerQueryAdapter = new WorkerTaskRunnerQueryAdapter(taskMaster, null);
|
||||||
// Test Overlord resource stuff
|
// Test Overlord resource stuff
|
||||||
overlordResource = new OverlordResource(
|
overlordResource = new OverlordResource(
|
||||||
|
|
Loading…
Reference in New Issue