-
Notifications
You must be signed in to change notification settings - Fork 740
SOLR-17160: Time based tracking of core admin requests with Caffeine cache #2304
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 2 commits
fdfc9f0
8df6c8c
ddd45a6
eda2c05
b29b498
7e87990
09c3430
e23d0ba
525aa35
c439377
ec33077
9629e2a
a1b4ad3
1e350dd
42c2575
ee7a896
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,14 +18,14 @@ | |
|
||
import static org.apache.solr.handler.admin.CoreAdminHandler.CoreAdminAsyncTracker.COMPLETED; | ||
import static org.apache.solr.handler.admin.CoreAdminHandler.CoreAdminAsyncTracker.FAILED; | ||
import static org.apache.solr.handler.admin.CoreAdminHandler.CoreAdminAsyncTracker.RUNNING; | ||
|
||
import jakarta.inject.Inject; | ||
import org.apache.solr.client.api.endpoint.GetNodeCommandStatusApi; | ||
import org.apache.solr.client.api.model.GetNodeCommandStatusResponse; | ||
import org.apache.solr.common.params.CoreAdminParams; | ||
import org.apache.solr.core.CoreContainer; | ||
import org.apache.solr.handler.admin.CoreAdminHandler; | ||
import org.apache.solr.handler.admin.CoreAdminHandler.CoreAdminAsyncTracker.TaskObject; | ||
import org.apache.solr.jersey.PermissionName; | ||
import org.apache.solr.request.SolrQueryRequest; | ||
import org.apache.solr.response.SolrQueryResponse; | ||
|
@@ -51,25 +51,24 @@ public GetNodeCommandStatus( | |
public GetNodeCommandStatusResponse getCommandStatus(String requestId) { | ||
ensureRequiredParameterProvided(CoreAdminParams.REQUESTID, requestId); | ||
var requestStatusResponse = new GetNodeCommandStatusResponse(); | ||
if (coreAdminAsyncTracker.getRequestStatusMap(RUNNING).containsKey(requestId)) { | ||
requestStatusResponse.status = RUNNING; | ||
} else if (coreAdminAsyncTracker.getRequestStatusMap(COMPLETED).containsKey(requestId)) { | ||
requestStatusResponse.status = COMPLETED; | ||
requestStatusResponse.response = | ||
coreAdminAsyncTracker.getRequestStatusMap(COMPLETED).get(requestId).getRspObject(); | ||
requestStatusResponse.response = | ||
coreAdminAsyncTracker | ||
.getRequestStatusMap(COMPLETED) | ||
.get(requestId) | ||
.getOperationRspObject(); | ||
} else if (coreAdminAsyncTracker.getRequestStatusMap(FAILED).containsKey(requestId)) { | ||
requestStatusResponse.status = FAILED; | ||
requestStatusResponse.response = | ||
coreAdminAsyncTracker.getRequestStatusMap(FAILED).get(requestId).getRspObject(); | ||
} else { | ||
|
||
TaskObject taskObject = coreAdminAsyncTracker.getAsyncRequestForStatus(requestId); | ||
String status = taskObject != null ? taskObject.getStatus() : null; | ||
|
||
if (status == null) { | ||
requestStatusResponse.status = "notfound"; | ||
requestStatusResponse.msg = "No task found in running, completed or failed tasks"; | ||
} else { | ||
requestStatusResponse.status = status; | ||
|
||
if (taskObject.getStatus().equals(COMPLETED)) { | ||
psalagnac marked this conversation as resolved.
Show resolved
Hide resolved
|
||
requestStatusResponse.response = taskObject.getRspObject(); | ||
requestStatusResponse.response = taskObject.getOperationRspObject(); | ||
Comment on lines
+65
to
+66
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm confused; you are setting the response twice? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh, good catch! Maybe I should put this PR on hold and fix this first? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah; didn't know it was existing code. Do in whichever order you want; it doesn't really matter. |
||
} else if (taskObject.getStatus().equals(FAILED)) { | ||
requestStatusResponse.response = taskObject.getRspObject(); | ||
} | ||
} | ||
|
||
return requestStatusResponse; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,6 +16,8 @@ | |
*/ | ||
package org.apache.solr.handler.admin; | ||
|
||
import static org.apache.solr.handler.admin.CoreAdminHandler.CoreAdminAsyncTracker.COMPLETED; | ||
|
||
import java.io.Reader; | ||
import java.nio.charset.StandardCharsets; | ||
import java.nio.file.Files; | ||
|
@@ -24,7 +26,9 @@ | |
import java.nio.file.StandardCopyOption; | ||
import java.util.Map; | ||
import java.util.Properties; | ||
import java.util.Set; | ||
import java.util.concurrent.TimeUnit; | ||
import java.util.concurrent.atomic.AtomicLong; | ||
import org.apache.commons.io.file.PathUtils; | ||
import org.apache.lucene.util.Constants; | ||
import org.apache.solr.SolrTestCaseJ4; | ||
|
@@ -43,6 +47,8 @@ | |
import org.apache.solr.core.CoreDescriptor; | ||
import org.apache.solr.core.SolrCore; | ||
import org.apache.solr.embedded.JettySolrRunner; | ||
import org.apache.solr.handler.admin.CoreAdminHandler.CoreAdminAsyncTracker; | ||
import org.apache.solr.handler.admin.CoreAdminHandler.CoreAdminAsyncTracker.TaskObject; | ||
import org.apache.solr.response.SolrQueryResponse; | ||
import org.junit.BeforeClass; | ||
import org.junit.Test; | ||
|
@@ -528,4 +534,39 @@ public void testNonexistentCoreReload() throws Exception { | |
e.getMessage()); | ||
admin.close(); | ||
} | ||
|
||
@Test | ||
public void testTrackedRequestExpiration() throws Exception { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. wonderful test |
||
// Create a tracker with controlled clock, relative to 0 | ||
AtomicLong clock = new AtomicLong(0L); | ||
CoreAdminAsyncTracker asyncTracker = new CoreAdminAsyncTracker(clock::get, 100L, 10L); | ||
try { | ||
Set<TaskObject> tasks = | ||
Set.of( | ||
new TaskObject("id1", "ACTION", false, SolrQueryResponse::new), | ||
new TaskObject("id2", "ACTION", false, SolrQueryResponse::new)); | ||
|
||
// Submit all tasks and wait for internal status to be COMPLETED | ||
tasks.forEach(asyncTracker::submitAsyncTask); | ||
while (!tasks.stream().allMatch(t -> COMPLETED.equals(t.getStatus()))) { | ||
Thread.sleep(10L); | ||
} | ||
|
||
// Timeout for running tasks is 100n, so status can be retrieved after 20n. | ||
// But timeout for complete tasks is 10n once we polled the status at least once, so status | ||
// is not available anymore 20n later. | ||
clock.set(20); | ||
assertEquals(COMPLETED, asyncTracker.getAsyncRequestForStatus("id1").getStatus()); | ||
clock.set(40L); | ||
assertNull(asyncTracker.getAsyncRequestForStatus("id1")); | ||
|
||
// Move the clock after the running timeout. | ||
// Status of second task is not available anymore, even if it wasn't retrieved yet | ||
clock.set(110L); | ||
assertNull(asyncTracker.getAsyncRequestForStatus("id2")); | ||
|
||
} finally { | ||
asyncTracker.shutdown(); | ||
} | ||
} | ||
} |
Uh oh!
There was an error while loading. Please reload this page.