Package ca.uhn.fhir.jpa.search.cache
Class DatabaseSearchCacheSvcImpl
java.lang.Object
ca.uhn.fhir.jpa.search.cache.DatabaseSearchCacheSvcImpl
- All Implemented Interfaces:
ISearchCacheSvc
-
Field Summary
Modifier and TypeFieldDescriptionstatic final int
static final int
static final int
static final long
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionfetchByUuid
(String theUuid, RequestPartitionId theRequestPartitionId) Fetch a search using its UUID.findCandidatesForReuse
(String theResourceType, String theQueryString, Instant theCreatedAfter, RequestPartitionId theRequestPartitionId) Look for any existing searches matching the given resource type and query string.static long
now()
void
pollForStaleSearchesAndDeleteThem
(RequestPartitionId theRequestPartitionId, Instant theDeadline) This method will be called periodically to delete stale searches.save
(Search theSearch, RequestPartitionId theRequestPartitionId) Places a new search of some sort in the cache, or updates an existing search.void
setCutoffSlackForUnitTest
(long theCutoffSlack) static void
setMaximumResultsToDeleteInOnePassForUnitTest
(int theMaximumResultsToDeleteInOnePass) static void
setMaximumResultsToDeleteInOneStatement
(int theMaximumResultsToDelete) static void
setNowForUnitTests
(Long theNowForUnitTests) This is for unit tests only, do not call otherwisetryToMarkSearchAsInProgress
(Search theSearch, RequestPartitionId theRequestPartitionId) TODO: this is perhaps an inappropriate responsibility for this service
-
Field Details
-
DEFAULT_MAX_RESULTS_TO_DELETE_IN_ONE_STMT
- See Also:
-
DEFAULT_MAX_RESULTS_TO_DELETE_IN_ONE_PAS
- See Also:
-
SEARCH_CLEANUP_JOB_INTERVAL_MILLIS
- See Also:
-
DEFAULT_MAX_DELETE_CANDIDATES_TO_FIND
- See Also:
-
-
Constructor Details
-
DatabaseSearchCacheSvcImpl
public DatabaseSearchCacheSvcImpl()
-
-
Method Details
-
setCutoffSlackForUnitTest
-
save
Description copied from interface:ISearchCacheSvc
Places a new search of some sort in the cache, or updates an existing search. The search passed in is guaranteed to have aUUID
so that is a good candidate for consistent identification.- Specified by:
save
in interfaceISearchCacheSvc
- Parameters:
theSearch
- The search to store- Returns:
- Returns a copy of the search as it was saved. Callers should use the returned Search object for any further processing.
-
fetchByUuid
@Transactional(propagation=REQUIRED) public Optional<Search> fetchByUuid(String theUuid, RequestPartitionId theRequestPartitionId) Description copied from interface:ISearchCacheSvc
Fetch a search using its UUID. The search should be fully loaded when it is returned (i.e. includes are fetched, so that access to its fields will not cause database errors if the current tranaction scope ends.- Specified by:
fetchByUuid
in interfaceISearchCacheSvc
- Parameters:
theUuid
- The search UUID- Returns:
- The search if it exists
-
tryToMarkSearchAsInProgress
public Optional<Search> tryToMarkSearchAsInProgress(Search theSearch, RequestPartitionId theRequestPartitionId) Description copied from interface:ISearchCacheSvc
TODO: this is perhaps an inappropriate responsibility for this serviceThis method marks a search as in progress, but should only allow exactly one call to do so across the cluster. This is done so that if two client threads request the next page at the exact same time (which is unlikely but not impossible) only one will actually proceed to load the next results and the other will just wait for them to arrive.
- Specified by:
tryToMarkSearchAsInProgress
in interfaceISearchCacheSvc
- Parameters:
theSearch
- The search to mark- Returns:
- This method should return an empty optional if the search was not marked (meaning that another thread
succeeded in marking it). If the search doesn't exist or some other error occurred, an exception will be thrown
instead of
Optional.empty()
-
findCandidatesForReuse
public Optional<Search> findCandidatesForReuse(String theResourceType, String theQueryString, Instant theCreatedAfter, RequestPartitionId theRequestPartitionId) Description copied from interface:ISearchCacheSvc
Look for any existing searches matching the given resource type and query string.This method is allowed to perform a "best effort" return, so it can return searches that don't match the query string exactly, or which have a created timestamp before
theCreatedAfter
date. The caller is responsible for removing any inappropriate Searches and picking the most relevant one.- Specified by:
findCandidatesForReuse
in interfaceISearchCacheSvc
- Parameters:
theResourceType
- The resource type of the search. Results MUST match this typetheQueryString
- The query string. Results SHOULD match this typetheCreatedAfter
- Results SHOULD not include any searches created before this cutoff timestamptheRequestPartitionId
- Search should examine only the requested partitions. Cache MUST not return results matching the given partition IDs- Returns:
- A collection of candidate searches
-
pollForStaleSearchesAndDeleteThem
public void pollForStaleSearchesAndDeleteThem(RequestPartitionId theRequestPartitionId, Instant theDeadline) Description copied from interface:ISearchCacheSvc
This method will be called periodically to delete stale searches. Implementations are not required to do anything if they have some other mechanism for expiring stale results other than manually looking for them and deleting them.- Specified by:
pollForStaleSearchesAndDeleteThem
in interfaceISearchCacheSvc
-
setMaximumResultsToDeleteInOnePassForUnitTest
public static void setMaximumResultsToDeleteInOnePassForUnitTest(int theMaximumResultsToDeleteInOnePass) -
setMaximumResultsToDeleteInOneStatement
-
setNowForUnitTests
This is for unit tests only, do not call otherwise -
now
-