Skip to content

Commit

Permalink
Merge pull request #1440 from UNC-Libraries/bxc-3748-index-mismatch
Browse files Browse the repository at this point in the history
BXC-3748 - Fix ObjectTypeMismatchException thrown during work reindexing batches
  • Loading branch information
bbpennel authored Jul 27, 2022
2 parents 7a3d68d + ce6e9e5 commit fd937cd
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,18 @@

import edu.unc.lib.boxc.model.api.ids.PID;
import edu.unc.lib.boxc.model.fcrepo.ids.PIDs;
import edu.unc.lib.boxc.model.fcrepo.ids.RepositoryPaths;
import edu.unc.lib.boxc.operations.jms.indexing.IndexingActionType;
import edu.unc.lib.boxc.operations.jms.indexing.IndexingMessageSender;
import edu.unc.lib.boxc.search.solr.config.SolrSettings;
import org.apache.camel.Exchange;
import org.apache.camel.Message;
import org.apache.camel.Processor;
import org.apache.solr.client.solrj.SolrClient;
import org.apache.solr.client.solrj.SolrServerException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.IOException;
import java.util.Collection;

/**
Expand All @@ -37,8 +40,14 @@ public class AggregateUpdateProcessor implements Processor {
private static final Logger log = LoggerFactory.getLogger(AggregateUpdateProcessor.class);
private IndexingMessageSender messageSender;
private IndexingActionType actionType;
private SolrSettings solrSettings;
private SolrClient solrClient;
private boolean forceCommit;

public void init() {
solrClient = solrSettings.getSolrClient();
}

@Override
public void process(Exchange exchange) throws Exception {
final Message in = exchange.getIn();
Expand All @@ -48,7 +57,11 @@ public void process(Exchange exchange) throws Exception {
}
if (forceCommit) {
// Force commit of any pending solr updates before sending indexing operations
messageSender.sendIndexingOperation(null, RepositoryPaths.getRootPid(), IndexingActionType.COMMIT);
try {
solrClient.commit();
} catch (SolrServerException | IOException e) {
log.error("Failed to commit solr updates prior to indexing children of a collection");
}
}
for (Object idObj : idCollection) {
PID pid = PIDs.get(idObj.toString());
Expand All @@ -60,6 +73,14 @@ public void setIndexingMessageSender(IndexingMessageSender messageSender) {
this.messageSender = messageSender;
}

public void setSolrSettings(SolrSettings solrSettings) {
this.solrSettings = solrSettings;
}

public void setSolrClient(SolrClient solrClient) {
this.solrClient = solrClient;
}

public void setActionType(IndexingActionType actionType) {
this.actionType = actionType;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -469,10 +469,12 @@
<bean id="solrUpdatePreprocessor" class="edu.unc.lib.boxc.services.camel.solrUpdate.SolrUpdatePreprocessor">
</bean>

<bean id="aggregateWorkForFileProcessor" class="edu.unc.lib.boxc.services.camel.solrUpdate.AggregateUpdateProcessor">
<bean id="aggregateWorkForFileProcessor" class="edu.unc.lib.boxc.services.camel.solrUpdate.AggregateUpdateProcessor"
init-method="init">
<property name="indexingMessageSender" ref="indexingMessageSender" />
<property name="actionType" value="UPDATE_WORK_FILES" />
<property name="forceCommit" value="true" />
<property name="solrSettings" ref="solrSettings" />
</bean>

<bean id="updateWorkJmsTemplate" class="org.springframework.jms.core.JmsTemplate">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import org.apache.camel.builder.NotifyBuilder;
import org.apache.camel.test.spring.CamelSpringRunner;
import org.apache.camel.test.spring.CamelTestContextBootstrapper;
import org.apache.solr.client.solrj.SolrClient;
import org.jdom2.Document;
import org.jdom2.Element;
import org.junit.Before;
Expand Down Expand Up @@ -94,6 +95,9 @@ public class SolrUpdateRouterTest {
@Autowired
private SolrUpdatePreprocessor solrUpdatePreprocessor;

@Autowired
private SolrClient solrClient;

private ArgumentCaptor<Exchange> exchangeCaptor;

private PIDMinter pidMinter;
Expand Down Expand Up @@ -262,6 +266,7 @@ public void multipleWorkFromFile() throws Exception {

notify.matches(3l, TimeUnit.SECONDS);

verify(solrClient).commit();
verify(indexingMessageSender).sendIndexingOperation(null, targetPid1, IndexingActionType.UPDATE_WORK_FILES);
verify(indexingMessageSender).sendIndexingOperation(null, targetPid2, IndexingActionType.UPDATE_WORK_FILES);
}
Expand Down
5 changes: 5 additions & 0 deletions services-camel-app/src/test/resources/solr-update-context.xml
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,15 @@
<constructor-arg value="edu.unc.lib.boxc.operations.jms.indexing.IndexingMessageSender" />
</bean>

<bean id="mockSolrClient" class="org.mockito.Mockito" factory-method="mock">
<constructor-arg value="org.apache.solr.client.solrj.SolrClient" />
</bean>

<bean id="aggregateWorkForFileProcessor" class="edu.unc.lib.boxc.services.camel.solrUpdate.AggregateUpdateProcessor">
<property name="indexingMessageSender" ref="mockIndexingMessageSender" />
<property name="actionType" value="UPDATE_WORK_FILES" />
<property name="forceCommit" value="true" />
<property name="solrClient" ref="mockSolrClient" />
</bean>

<bean id="orderedSetAggregationStrategy" class="edu.unc.lib.boxc.services.camel.util.OrderedSetAggregationStrategy"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,7 @@
<property name="indexingMessageSender" ref="indexingMessageSender" />
<property name="actionType" value="UPDATE_WORK_FILES" />
<property name="forceCommit" value="true" />
<property name="solrClient" ref="embeddedSolrServer" />
</bean>

<bean id="updateWorkJmsTemplate" class="org.springframework.jms.core.JmsTemplate">
Expand Down

0 comments on commit fd937cd

Please sign in to comment.