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:
AmatyaAvadhanula 2023-11-17 12:19:20 +05:30 committed by GitHub
parent 6a5da5a05e
commit 77828bead4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 25 additions and 3 deletions

View File

@ -947,6 +947,17 @@ public class TaskQueue
return stats;
}
public Optional<Task> getActiveTask(String id)
{
giant.lock();
try {
return Optional.fromNullable(tasks.get(id));
}
finally {
giant.unlock();
}
}
@VisibleForTesting
List<Task> getTasks()
{

View File

@ -48,12 +48,14 @@ public class TaskStorageQueryAdapter
{
private final TaskStorage storage;
private final TaskLockbox taskLockbox;
private final Optional<TaskQueue> taskQueue;
@Inject
public TaskStorageQueryAdapter(TaskStorage storage, TaskLockbox taskLockbox)
public TaskStorageQueryAdapter(TaskStorage storage, TaskLockbox taskLockbox, TaskMaster taskMaster)
{
this.storage = storage;
this.taskLockbox = taskLockbox;
this.taskQueue = taskMaster.getTaskQueue();
}
public List<Task> getActiveTasks()
@ -104,6 +106,12 @@ public class TaskStorageQueryAdapter
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);
}

View File

@ -482,7 +482,10 @@ public class TaskLifecycleTest extends InitializedNullHandlingTest
default:
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;
}

View File

@ -257,7 +257,7 @@ public class OverlordTest
Assert.assertEquals(taskMaster.getCurrentLeader(), druidNode.getHostAndPort());
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);
// Test Overlord resource stuff
overlordResource = new OverlordResource(