Ensure HS before attempting fulltext reindex. (#3995)

* Do not attempt fulltext reindex if disabled. Validate enabled before using any operation

* attribute
This commit is contained in:
Tadgh 2022-09-07 11:35:57 -04:00 committed by GitHub
parent c647154777
commit cc183c7079
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 23 additions and 2 deletions

View File

@ -0,0 +1,4 @@
---
type: fix
issue: 3987
title: "Previously, if a FullTextSearchSvcImpl was defined, but was disabled via configuration, there could be data loss when reindexing due to transaction rollbacks. This has been corrected. Thanks to @dyoung-work for the fix!"

View File

@ -129,6 +129,7 @@ public class FulltextSearchSvcImpl implements IFulltextSearchSvc {
@Override
public boolean supportsSomeOf(SearchParameterMap myParams) {
// keep this in sync with the guts of doSearch
boolean requiresHibernateSearchAccess = myParams.containsKey(Constants.PARAM_CONTENT) || myParams.containsKey(Constants.PARAM_TEXT) || myParams.isLastN();
@ -139,12 +140,16 @@ public class FulltextSearchSvcImpl implements IFulltextSearchSvc {
@Override
public void reindex(ResourceTable theEntity) {
validateHibernateSearchIsEnabled();
SearchIndexingPlan plan = getSearchSession().indexingPlan();
plan.addOrUpdate(theEntity);
}
@Override
public ISearchQueryExecutor searchNotScrolled(String theResourceName, SearchParameterMap theParams, Integer theMaxResultsToFetch) {
validateHibernateSearchIsEnabled();
return doSearch(theResourceName, theParams, null, theMaxResultsToFetch);
}
@ -264,6 +269,8 @@ public class FulltextSearchSvcImpl implements IFulltextSearchSvc {
@Override
public List<ResourcePersistentId> everything(String theResourceName, SearchParameterMap theParams, ResourcePersistentId theReferencingPid) {
validateHibernateSearchIsEnabled();
// wipmb what about max results here?
List<ResourcePersistentId> retVal = toList(doSearch(null, theParams, theReferencingPid, 10_000), 10_000);
if (theReferencingPid != null) {
@ -272,6 +279,12 @@ public class FulltextSearchSvcImpl implements IFulltextSearchSvc {
return retVal;
}
private void validateHibernateSearchIsEnabled() {
if (isDisabled()) {
throw new UnsupportedOperationException(Msg.code(2137) + "Hibernate search is not enabled!");
}
}
@Override
public boolean isDisabled() {
Boolean retVal = ourDisabled;
@ -298,6 +311,7 @@ public class FulltextSearchSvcImpl implements IFulltextSearchSvc {
@Transactional()
@Override
public List<ResourcePersistentId> search(String theResourceName, SearchParameterMap theParams) {
validateHibernateSearchIsEnabled();
return toList(doSearch(theResourceName, theParams, null, DEFAULT_MAX_NON_PAGED_SIZE), DEFAULT_MAX_NON_PAGED_SIZE);
}
@ -314,6 +328,7 @@ public class FulltextSearchSvcImpl implements IFulltextSearchSvc {
@Transactional()
@Override
public IBaseResource tokenAutocompleteValueSetSearch(ValueSetAutocompleteOptions theOptions) {
validateHibernateSearchIsEnabled();
ensureElastic();
ValueSetAutocompleteSearch autocomplete = new ValueSetAutocompleteSearch(myFhirContext, myModelConfig, getSearchSession());
@ -329,7 +344,6 @@ public class FulltextSearchSvcImpl implements IFulltextSearchSvc {
* Lastn and the autocomplete search use nested aggregations which are Elasticsearch-only
*/
private void ensureElastic() {
//String hibernateSearchBackend = (String) myEntityManager.g.getJpaPropertyMap().get(BackendSettings.backendKey(BackendSettings.TYPE));
try {
getSearchSession().scope( ResourceTable.class )
.aggregation()

View File

@ -105,7 +105,7 @@ public class ResourceReindexer {
Class<T> resourceClass = (Class<T>) resourceDefinition.getImplementingClass();
final IFhirResourceDao<T> dao = myDaoRegistry.getResourceDao(resourceClass);
dao.reindex(theResource, theResourceTable);
if (myFulltextSearchSvc != null) {
if (myFulltextSearchSvc != null && !myFulltextSearchSvc.isDisabled()) {
// update the full-text index, if active.
myFulltextSearchSvc.reindex(theResourceTable);
}

View File

@ -756,6 +756,9 @@
<id>gjergjsheldija</id>
<name>Gjergj Sheldija</name>
</developer>
<developer>
<id>dyoung-work</id>
</developer>
</developers>
<licenses>