Add ability to suspend scheduled reindexer

This commit is contained in:
James Agnew 2018-09-05 16:22:09 +08:00
parent e20924dd09
commit 979b1287d0
4 changed files with 84 additions and 30 deletions

View File

@ -256,6 +256,9 @@ public abstract class BaseHapiFhirSystemDao<T, MT> extends BaseHapiFhirDao<IBase
@Override
@Transactional(propagation = Propagation.NEVER)
public Integer performReindexingPass(final Integer theCount) {
if (getConfig().isStatusBasedReindexingDisabled()) {
return -1;
}
if (!myReindexLock.tryLock()) {
return -1;
}

View File

@ -8,6 +8,8 @@ import org.apache.commons.lang3.ObjectUtils;
import org.apache.commons.lang3.Validate;
import org.apache.commons.lang3.time.DateUtils;
import org.hl7.fhir.r4.model.Bundle;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.*;
@ -58,6 +60,10 @@ public class DaoConfig {
* @see #setTranslationCachesExpireAfterWriteInMinutes(Long)
*/
public static final Long DEFAULT_TRANSLATION_CACHES_EXPIRE_AFTER_WRITE_IN_MINUTES = 60L;
/**
* See {@link #setStatusBasedReindexingDisabled(boolean)}
*/
public static final String DISABLE_STATUS_BASED_REINDEX = "disable_status_based_reindex";
/**
* Default value for {@link #setMaximumSearchResultCountInTransaction(Integer)}
*
@ -77,6 +83,7 @@ public class DaoConfig {
Bundle.BundleType.DOCUMENT.toCode(),
Bundle.BundleType.MESSAGE.toCode()
)));
private static final Logger ourLog = LoggerFactory.getLogger(DaoConfig.class);
private IndexEnabledEnum myIndexMissingFieldsEnabled = IndexEnabledEnum.DISABLED;
/**
* update setter javadoc if default changes
@ -90,7 +97,6 @@ public class DaoConfig {
* update setter javadoc if default changes
*/
private boolean myAllowContainsSearches = false;
/**
* update setter javadoc if default changes
*/
@ -139,6 +145,7 @@ public class DaoConfig {
private boolean myAutoCreatePlaceholderReferenceTargets;
private Integer myCacheControlNoStoreMaxResultsUpperLimit = 1000;
private Integer myCountSearchResultsUpTo = null;
private boolean myStatusBasedReindexingDisabled;
private IdStrategyEnum myResourceServerIdStrategy = IdStrategyEnum.SEQUENTIAL_NUMERIC;
private boolean myMarkResourcesForReindexingUponSearchParameterChange;
private boolean myExpungeEnabled;
@ -156,6 +163,38 @@ public class DaoConfig {
setMarkResourcesForReindexingUponSearchParameterChange(true);
setReindexThreadCount(Runtime.getRuntime().availableProcessors());
setBundleTypesAllowedForStorage(DEFAULT_BUNDLE_TYPES_ALLOWED_FOR_STORAGE);
if ("true".equalsIgnoreCase(System.getProperty(DISABLE_STATUS_BASED_REINDEX))) {
ourLog.info("Status based reindexing is DISABLED");
setStatusBasedReindexingDisabled(true);
}
}
/**
* If set to <code>true</code> (default is false), the reindexing of search parameters
* using a query on the HFJ_RESOURCE.SP_INDEX_STATUS column will be disabled completely.
* This query is just not efficient on Oracle and bogs the system down when there are
* a lot of resources. A more efficient way of doing this will be introduced
* in the next release of HAPI FHIR.
*
* @since 3.5.0
*/
public boolean isStatusBasedReindexingDisabled() {
return myStatusBasedReindexingDisabled;
}
/**
* If set to <code>true</code> (default is false), the reindexing of search parameters
* using a query on the HFJ_RESOURCE.SP_INDEX_STATUS column will be disabled completely.
* This query is just not efficient on Oracle and bogs the system down when there are
* a lot of resources. A more efficient way of doing this will be introduced
* in the next release of HAPI FHIR.
*
* @since 3.5.0
*/
public void setStatusBasedReindexingDisabled(boolean theStatusBasedReindexingDisabled) {
myStatusBasedReindexingDisabled = theStatusBasedReindexingDisabled;
}
/**
@ -461,6 +500,16 @@ public class DaoConfig {
myInterceptors = theInterceptors;
}
/**
* This may be used to optionally register server interceptors directly against the DAOs.
*/
public void setInterceptors(IServerInterceptor... theInterceptor) {
setInterceptors(new ArrayList<IServerInterceptor>());
if (theInterceptor != null && theInterceptor.length != 0) {
getInterceptors().addAll(Arrays.asList(theInterceptor));
}
}
/**
* See {@link #setMaximumExpansionSize(int)}
*/
@ -1241,16 +1290,6 @@ public class DaoConfig {
// nothing
}
/**
* This may be used to optionally register server interceptors directly against the DAOs.
*/
public void setInterceptors(IServerInterceptor... theInterceptor) {
setInterceptors(new ArrayList<IServerInterceptor>());
if (theInterceptor != null && theInterceptor.length != 0) {
getInterceptors().addAll(Arrays.asList(theInterceptor));
}
}
/**
* @deprecated As of HAPI FHIR 3.0.0, subscriptions no longer use polling for
* detecting changes, so this setting has no effect
@ -1282,18 +1321,6 @@ public class DaoConfig {
setSubscriptionPurgeInactiveAfterMillis(theSeconds * DateUtils.MILLIS_PER_SECOND);
}
private static void validateTreatBaseUrlsAsLocal(String theUrl) {
Validate.notBlank(theUrl, "Base URL must not be null or empty");
int starIdx = theUrl.indexOf('*');
if (starIdx != -1) {
if (starIdx != theUrl.length() - 1) {
throw new IllegalArgumentException("Base URL wildcard character (*) can only appear at the end of the string: " + theUrl);
}
}
}
public enum IndexEnabledEnum {
ENABLED,
DISABLED
@ -1311,4 +1338,16 @@ public class DaoConfig {
UUID
}
private static void validateTreatBaseUrlsAsLocal(String theUrl) {
Validate.notBlank(theUrl, "Base URL must not be null or empty");
int starIdx = theUrl.indexOf('*');
if (starIdx != -1) {
if (starIdx != theUrl.length() - 1) {
throw new IllegalArgumentException("Base URL wildcard character (*) can only appear at the end of the string: " + theUrl);
}
}
}
}

View File

@ -57,7 +57,7 @@ public class ReindexController implements IReindexController {
@Transactional(propagation = Propagation.NEVER)
@Override
public void performReindexingPass() {
if (myDaoConfig.isSchedulingDisabled()) {
if (myDaoConfig.isSchedulingDisabled() || myDaoConfig.isStatusBasedReindexingDisabled()) {
return;
}
@ -94,6 +94,9 @@ public class ReindexController implements IReindexController {
if (count == null) {
ourLog.info("Reindex pass complete, no remaining resource to index");
myDontReindexUntil = System.currentTimeMillis() + DateUtils.MILLIS_PER_HOUR;
} else if (count == -1) {
// Reindexing failed
myDontReindexUntil = System.currentTimeMillis() + DateUtils.MILLIS_PER_HOUR;
} else {
ourLog.info("Reindex pass complete, {} remaining resource to index", count);
myDontReindexUntil = null;

View File

@ -1,11 +1,12 @@
package ca.uhn.fhir.jpa.dao;
import static org.junit.Assert.*;
import org.junit.Test;
import java.util.Arrays;
import java.util.HashSet;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail;
public class DaoConfigTest {
@ -31,4 +32,12 @@ public class DaoConfigTest {
}
}
@Test
public void testDisableStatusBasedReindexUsingSystemProperty() {
assertEquals(false, new DaoConfig().isStatusBasedReindexingDisabled());
System.setProperty(DaoConfig.DISABLE_STATUS_BASED_REINDEX, "true");
assertEquals(true, new DaoConfig().isStatusBasedReindexingDisabled());
System.clearProperty(DaoConfig.DISABLE_STATUS_BASED_REINDEX);
}
}