Add an interface for the stale search deleter
This commit is contained in:
parent
01d102accc
commit
bcff22c769
|
@ -38,7 +38,8 @@ import org.springframework.scheduling.concurrent.ScheduledExecutorFactoryBean;
|
||||||
import org.springframework.scheduling.config.ScheduledTaskRegistrar;
|
import org.springframework.scheduling.config.ScheduledTaskRegistrar;
|
||||||
|
|
||||||
import ca.uhn.fhir.jpa.search.DatabaseBackedPagingProvider;
|
import ca.uhn.fhir.jpa.search.DatabaseBackedPagingProvider;
|
||||||
import ca.uhn.fhir.jpa.search.StaleSearchDeletingSvc;
|
import ca.uhn.fhir.jpa.search.IStaleSearchDeletingSvc;
|
||||||
|
import ca.uhn.fhir.jpa.search.StaleSearchDeletingSvcImpl;
|
||||||
|
|
||||||
@Configuration
|
@Configuration
|
||||||
@EnableScheduling
|
@EnableScheduling
|
||||||
|
@ -59,13 +60,13 @@ public class BaseConfig implements SchedulingConfigurer {
|
||||||
|
|
||||||
@Bean(autowire = Autowire.BY_TYPE)
|
@Bean(autowire = Autowire.BY_TYPE)
|
||||||
public DatabaseBackedPagingProvider databaseBackedPagingProvider() {
|
public DatabaseBackedPagingProvider databaseBackedPagingProvider() {
|
||||||
DatabaseBackedPagingProvider retVal = new DatabaseBackedPagingProvider(10);
|
DatabaseBackedPagingProvider retVal = new DatabaseBackedPagingProvider();
|
||||||
return retVal;
|
return retVal;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Bean(autowire=Autowire.BY_TYPE)
|
@Bean(autowire=Autowire.BY_TYPE)
|
||||||
public StaleSearchDeletingSvc staleSearchDeletingSvc() {
|
public IStaleSearchDeletingSvc staleSearchDeletingSvc() {
|
||||||
return new StaleSearchDeletingSvc();
|
return new StaleSearchDeletingSvcImpl();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Bean()
|
@Bean()
|
||||||
|
|
|
@ -0,0 +1,9 @@
|
||||||
|
package ca.uhn.fhir.jpa.search;
|
||||||
|
|
||||||
|
public interface IStaleSearchDeletingSvc {
|
||||||
|
|
||||||
|
void pollForStaleSearchesAndDeleteThem();
|
||||||
|
|
||||||
|
void schedulePollForStaleSearches();
|
||||||
|
|
||||||
|
}
|
|
@ -42,8 +42,8 @@ import ca.uhn.fhir.jpa.entity.Search;
|
||||||
/**
|
/**
|
||||||
* Deletes old searches
|
* Deletes old searches
|
||||||
*/
|
*/
|
||||||
public class StaleSearchDeletingSvc {
|
public class StaleSearchDeletingSvcImpl implements IStaleSearchDeletingSvc {
|
||||||
private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(StaleSearchDeletingSvc.class);
|
private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(StaleSearchDeletingSvcImpl.class);
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private ISearchDao mySearchDao;
|
private ISearchDao mySearchDao;
|
||||||
|
@ -62,15 +62,23 @@ public class StaleSearchDeletingSvc {
|
||||||
|
|
||||||
@Scheduled(fixedDelay = 10 * DateUtils.MILLIS_PER_SECOND)
|
@Scheduled(fixedDelay = 10 * DateUtils.MILLIS_PER_SECOND)
|
||||||
@Transactional(propagation = Propagation.NOT_SUPPORTED)
|
@Transactional(propagation = Propagation.NOT_SUPPORTED)
|
||||||
public synchronized void pollForStaleSearches() {
|
@Override
|
||||||
if (myDaoConfig.isExpireSearchResults()) {
|
public synchronized void schedulePollForStaleSearches() {
|
||||||
Date cutoff = new Date(System.currentTimeMillis() - myDaoConfig.getExpireSearchResultsAfterMillis());
|
if (!myDaoConfig.isSchedulingDisabled()) {
|
||||||
ourLog.debug("Searching for searches which are before {}", cutoff);
|
if (myDaoConfig.isExpireSearchResults()) {
|
||||||
|
pollForStaleSearchesAndDeleteThem();
|
||||||
Collection<Search> toDelete = mySearchDao.findWhereCreatedBefore(cutoff);
|
|
||||||
if (toDelete.isEmpty()) {
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@Transactional(propagation = Propagation.NOT_SUPPORTED)
|
||||||
|
public void pollForStaleSearchesAndDeleteThem() {
|
||||||
|
Date cutoff = new Date(System.currentTimeMillis() - myDaoConfig.getExpireSearchResultsAfterMillis());
|
||||||
|
ourLog.debug("Searching for searches which are before {}", cutoff);
|
||||||
|
|
||||||
|
Collection<Search> toDelete = mySearchDao.findWhereCreatedBefore(cutoff);
|
||||||
|
if (!toDelete.isEmpty()) {
|
||||||
|
|
||||||
for (final Search next : toDelete) {
|
for (final Search next : toDelete) {
|
||||||
deleteSearch(next);
|
deleteSearch(next);
|
|
@ -36,7 +36,7 @@ import ca.uhn.fhir.jpa.dao.dstu2.FhirResourceDaoDstu2SearchNoFtTest;
|
||||||
import ca.uhn.fhir.jpa.entity.ResourceIndexedSearchParamString;
|
import ca.uhn.fhir.jpa.entity.ResourceIndexedSearchParamString;
|
||||||
import ca.uhn.fhir.jpa.entity.ResourceTable;
|
import ca.uhn.fhir.jpa.entity.ResourceTable;
|
||||||
import ca.uhn.fhir.jpa.provider.dstu3.JpaSystemProviderDstu3;
|
import ca.uhn.fhir.jpa.provider.dstu3.JpaSystemProviderDstu3;
|
||||||
import ca.uhn.fhir.jpa.search.StaleSearchDeletingSvc;
|
import ca.uhn.fhir.jpa.search.IStaleSearchDeletingSvc;
|
||||||
import ca.uhn.fhir.jpa.term.IHapiTerminologySvc;
|
import ca.uhn.fhir.jpa.term.IHapiTerminologySvc;
|
||||||
import ca.uhn.fhir.jpa.validation.JpaValidationSupportChainDstu3;
|
import ca.uhn.fhir.jpa.validation.JpaValidationSupportChainDstu3;
|
||||||
import ca.uhn.fhir.parser.IParser;
|
import ca.uhn.fhir.parser.IParser;
|
||||||
|
@ -162,7 +162,7 @@ public abstract class BaseJpaDstu3Test extends BaseJpaTest {
|
||||||
@Autowired
|
@Autowired
|
||||||
protected IFulltextSearchSvc mySearchDao;
|
protected IFulltextSearchSvc mySearchDao;
|
||||||
@Autowired
|
@Autowired
|
||||||
protected StaleSearchDeletingSvc myStaleSearchDeletingSvc;
|
protected IStaleSearchDeletingSvc myStaleSearchDeletingSvc;
|
||||||
@Autowired
|
@Autowired
|
||||||
@Qualifier("myStructureDefinitionDaoDstu3")
|
@Qualifier("myStructureDefinitionDaoDstu3")
|
||||||
protected IFhirResourceDao<StructureDefinition> myStructureDefinitionDao;
|
protected IFhirResourceDao<StructureDefinition> myStructureDefinitionDao;
|
||||||
|
|
|
@ -49,7 +49,7 @@ import ca.uhn.fhir.jpa.dao.DaoConfig;
|
||||||
import ca.uhn.fhir.jpa.dao.SearchParameterMap;
|
import ca.uhn.fhir.jpa.dao.SearchParameterMap;
|
||||||
import ca.uhn.fhir.jpa.dao.SearchParameterMap.EverythingModeEnum;
|
import ca.uhn.fhir.jpa.dao.SearchParameterMap.EverythingModeEnum;
|
||||||
import ca.uhn.fhir.jpa.entity.*;
|
import ca.uhn.fhir.jpa.entity.*;
|
||||||
import ca.uhn.fhir.jpa.search.StaleSearchDeletingSvc;
|
import ca.uhn.fhir.jpa.search.IStaleSearchDeletingSvc;
|
||||||
import ca.uhn.fhir.model.api.IQueryParameterType;
|
import ca.uhn.fhir.model.api.IQueryParameterType;
|
||||||
import ca.uhn.fhir.model.api.Include;
|
import ca.uhn.fhir.model.api.Include;
|
||||||
import ca.uhn.fhir.model.dstu.valueset.QuantityCompararatorEnum;
|
import ca.uhn.fhir.model.dstu.valueset.QuantityCompararatorEnum;
|
||||||
|
@ -1510,7 +1510,7 @@ public class FhirResourceDaoDstu3SearchNoFtTest extends BaseJpaDstu3Test {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
protected StaleSearchDeletingSvc myStaleSearchDeletingSvc;
|
protected IStaleSearchDeletingSvc myStaleSearchDeletingSvc;
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -1539,7 +1539,7 @@ public class FhirResourceDaoDstu3SearchNoFtTest extends BaseJpaDstu3Test {
|
||||||
assertThat(toUnqualifiedVersionlessIds(bundleProvider), containsInAnyOrder(pid1, pid2));
|
assertThat(toUnqualifiedVersionlessIds(bundleProvider), containsInAnyOrder(pid1, pid2));
|
||||||
|
|
||||||
myDaoConfig.setExpireSearchResults(false);
|
myDaoConfig.setExpireSearchResults(false);
|
||||||
myStaleSearchDeletingSvc.pollForStaleSearches();
|
myStaleSearchDeletingSvc.pollForStaleSearchesAndDeleteThem();
|
||||||
Thread.sleep(1500);
|
Thread.sleep(1500);
|
||||||
|
|
||||||
assertThat(toUnqualifiedVersionlessIds(bundleProvider), (containsInAnyOrder(pid1, pid2)));
|
assertThat(toUnqualifiedVersionlessIds(bundleProvider), (containsInAnyOrder(pid1, pid2)));
|
||||||
|
@ -1572,7 +1572,7 @@ public class FhirResourceDaoDstu3SearchNoFtTest extends BaseJpaDstu3Test {
|
||||||
Thread.sleep(1500);
|
Thread.sleep(1500);
|
||||||
|
|
||||||
myDaoConfig.setExpireSearchResultsAfterMillis(500);
|
myDaoConfig.setExpireSearchResultsAfterMillis(500);
|
||||||
myStaleSearchDeletingSvc.pollForStaleSearches();
|
myStaleSearchDeletingSvc.pollForStaleSearchesAndDeleteThem();
|
||||||
|
|
||||||
assertThat(toUnqualifiedVersionlessIds(bundleProvider), not(containsInAnyOrder(pid1, pid2)));
|
assertThat(toUnqualifiedVersionlessIds(bundleProvider), not(containsInAnyOrder(pid1, pid2)));
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,7 +17,6 @@ import org.junit.Test;
|
||||||
import ca.uhn.fhir.rest.gclient.IClientExecutable;
|
import ca.uhn.fhir.rest.gclient.IClientExecutable;
|
||||||
import ca.uhn.fhir.rest.gclient.IQuery;
|
import ca.uhn.fhir.rest.gclient.IQuery;
|
||||||
import ca.uhn.fhir.rest.server.exceptions.ResourceGoneException;
|
import ca.uhn.fhir.rest.server.exceptions.ResourceGoneException;
|
||||||
import ca.uhn.fhir.rest.server.servlet.ServletRequestDetails;
|
|
||||||
import ca.uhn.fhir.util.TestUtil;
|
import ca.uhn.fhir.util.TestUtil;
|
||||||
|
|
||||||
public class StaleSearchDeletingSvcDstu3Test extends BaseResourceProviderDstu3Test {
|
public class StaleSearchDeletingSvcDstu3Test extends BaseResourceProviderDstu3Test {
|
||||||
|
@ -69,13 +68,13 @@ public class StaleSearchDeletingSvcDstu3Test extends BaseResourceProviderDstu3Te
|
||||||
Bundle resp2 = ourClient.search().byUrl(nextLinkUrl).returnBundle(Bundle.class).execute();
|
Bundle resp2 = ourClient.search().byUrl(nextLinkUrl).returnBundle(Bundle.class).execute();
|
||||||
ourLog.info(myFhirCtx.newXmlParser().setPrettyPrint(true).encodeResourceToString(resp2));
|
ourLog.info(myFhirCtx.newXmlParser().setPrettyPrint(true).encodeResourceToString(resp2));
|
||||||
|
|
||||||
myStaleSearchDeletingSvc.pollForStaleSearches();
|
myStaleSearchDeletingSvc.pollForStaleSearchesAndDeleteThem();
|
||||||
|
|
||||||
ourClient.search().byUrl(nextLinkUrl).returnBundle(Bundle.class).execute();
|
ourClient.search().byUrl(nextLinkUrl).returnBundle(Bundle.class).execute();
|
||||||
|
|
||||||
Thread.sleep(20);
|
Thread.sleep(20);
|
||||||
myDaoConfig.setExpireSearchResultsAfterMillis(10);
|
myDaoConfig.setExpireSearchResultsAfterMillis(10);
|
||||||
myStaleSearchDeletingSvc.pollForStaleSearches();
|
myStaleSearchDeletingSvc.pollForStaleSearchesAndDeleteThem();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
ourClient.search().byUrl(nextLinkUrl).returnBundle(Bundle.class).execute();
|
ourClient.search().byUrl(nextLinkUrl).returnBundle(Bundle.class).execute();
|
||||||
|
|
Loading…
Reference in New Issue