Class DistributedApiAsyncTracker
- java.lang.Object
-
- org.apache.solr.cloud.DistributedApiAsyncTracker
-
public class DistributedApiAsyncTracker extends Object
Class holding the implementation required for tracking asynchronous Collection API (or other) tasks when the Collection API is distributed.This replaces the features provided by the distributed maps on ZK paths /overseer/collection-map-completed, /overseer/collection-map-failure and /overseer/async_ids when the Collection API commands are handled by the Overseer.
It works by using two Zookeeper directories, one for persistent nodes for each new async id and one for ephemeral nodes for each async id currently being processed (in flight).
A persistent async node has either no data, or has a serialized OverseerSolrResponse as content. An ephemeral async node has two possible states (content): 'S' or 'R'.The actual state of an async task is built from a combination of the two nodes:
+===================+=========================================+=================================================+====================+ | | persistent=success OverseerSolrResponse | persistent=null or failed OverseerSolrResponse | No persistent node | +===================+=========================================+=================================================+====================+ | ephemeral="S" | Task completed successfully | Task submitted | Unknown task | +-------------------+-----------------------------------------+-------------------------------------------------+--------------------+ | ephemeral="R" | Task completed successfully | Task running | Unknown task | +-------------------+-----------------------------------------+-------------------------------------------------+--------------------+ | No ephemeral node | Task completed successfully | Task failed (see response or null=node failure) | Unknown task | +-------------------+-----------------------------------------+-------------------------------------------------+--------------------+
-
-
Field Summary
Fields Modifier and Type Field Description static int
MAX_TRACKED_ASYNC_TASKS
Corresponds to Overseer.NUM_RESPONSES_TO_STORE.
-
Constructor Summary
Constructors Constructor Description DistributedApiAsyncTracker(org.apache.solr.common.cloud.SolrZkClient zkClient, String rootPath)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
cancelAsyncId(String asyncId)
Cancels the tracking of an asyncId, if the corresponding command could not be executed.boolean
createNewAsyncJobTracker(String asyncId)
After a successful call to this method, caller MUST eventually callsetTaskCompleted(java.lang.String, org.apache.solr.cloud.OverseerSolrResponse)
orcancelAsyncId(java.lang.String)
otherwise the task will forever be considered as in progress.void
deleteAllAsyncIds()
Deletes all async id's for completed or failed async jobs.boolean
deleteSingleAsyncId(String asyncId)
Deletes a single async tracking ID if the corresponding job has completed or failed.org.apache.solr.common.util.Pair<org.apache.solr.client.solrj.response.RequestStatusState,OverseerSolrResponse>
getAsyncTaskRequestStatus(String asyncId)
This method implements the logic described in the class Javadoc table (DistributedApiAsyncTracker
), using the two sets of tracking info to build the actual state of an async task.void
setTaskCompleted(String asyncId, OverseerSolrResponse solrResponse)
Mark the completion (success or error) of an async task.void
setTaskRunning(String asyncId)
Initially an async task is submitted.
-
-
-
Constructor Detail
-
DistributedApiAsyncTracker
public DistributedApiAsyncTracker(org.apache.solr.common.cloud.SolrZkClient zkClient, String rootPath)
-
-
Method Detail
-
createNewAsyncJobTracker
public boolean createNewAsyncJobTracker(String asyncId)
After a successful call to this method, caller MUST eventually callsetTaskCompleted(java.lang.String, org.apache.solr.cloud.OverseerSolrResponse)
orcancelAsyncId(java.lang.String)
otherwise the task will forever be considered as in progress.- Parameters:
asyncId
- ifnull
this method will do nothing.- Returns:
true
if the asyncId was not already in use (or isnull
) andfalse
if it is already in use and can't be allocated again.
-
setTaskRunning
public void setTaskRunning(String asyncId)
Initially an async task is submitted. Just before it actually starts execution it is set to running.
-
setTaskCompleted
public void setTaskCompleted(String asyncId, OverseerSolrResponse solrResponse)
Mark the completion (success or error) of an async task. The success or error is judged by the contents of theOverseerSolrResponse
.
-
cancelAsyncId
public void cancelAsyncId(String asyncId)
Cancels the tracking of an asyncId, if the corresponding command could not be executed.
-
getAsyncTaskRequestStatus
public org.apache.solr.common.util.Pair<org.apache.solr.client.solrj.response.RequestStatusState,OverseerSolrResponse> getAsyncTaskRequestStatus(String asyncId) throws Exception
This method implements the logic described in the class Javadoc table (DistributedApiAsyncTracker
), using the two sets of tracking info to build the actual state of an async task.Returns the status of an async task, and when relevant the corresponding response from the command execution. The returned
OverseerSolrResponse
will not benull
when the returnedRequestStatusState
isRequestStatusState.COMPLETED
orRequestStatusState.FAILED
(and will benull
in all other cases).- Throws:
Exception
-
deleteSingleAsyncId
public boolean deleteSingleAsyncId(String asyncId) throws Exception
Deletes a single async tracking ID if the corresponding job has completed or failed.- Returns:
true
if theasyncId
was found to be of a completed or failed job and was successfully removed,false
if the id was not found or was found for a submitted or running job (these are not removed).- Throws:
Exception
-
-