From bf17b980da0741a1670b34f5b9156e019b118f93 Mon Sep 17 00:00:00 2001 From: Angel Borroy Date: Tue, 18 Feb 2020 11:55:55 +0100 Subject: [PATCH] SEARCH-2112: On Shards configured with DB_ID_RANGE, the first indexed transaction can be different from the first transaction in the repository --- .../solr/tracker/MetadataTracker.java | 25 ++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/search-services/alfresco-search/src/main/java/org/alfresco/solr/tracker/MetadataTracker.java b/search-services/alfresco-search/src/main/java/org/alfresco/solr/tracker/MetadataTracker.java index 9ba07de17..763678a3a 100644 --- a/search-services/alfresco-search/src/main/java/org/alfresco/solr/tracker/MetadataTracker.java +++ b/search-services/alfresco-search/src/main/java/org/alfresco/solr/tracker/MetadataTracker.java @@ -255,7 +255,30 @@ public class MetadataTracker extends CoreStatePublisher implements Tracker if (!state.isCheckedFirstTransactionTime()) { - firstTransactions = client.getTransactions(null, 0L, null, Long.MAX_VALUE, 1); + + // On Shards configured with DB_ID_RANGE, the first indexed transaction can be + // different from the first transaction in the repository as some transactions + // are skipped if they are not related with the range of the Shard. + // Getting the minCommitTime for the Shard is enough in order to check + // that the first transaction is present. + long minCommitTime = 0l; + if (docRouter instanceof DBIDRangeRouter && txIntervalCommitTimeServiceAvailable) + { + try + { + DBIDRangeRouter dbIdRangeRouter = (DBIDRangeRouter) docRouter; + Pair commitTimes = client.getTxIntervalCommitTime(coreName, + dbIdRangeRouter.getStartRange(), dbIdRangeRouter.getEndRange()); + minCommitTime = commitTimes.getFirst(); + } + catch (NoSuchMethodException e) + { + log.warn("txIntervalCommitTimeServiceAvailable is not available. If you are using DB_ID_RANGE shard method, " + + "upgrade your ACS Repository version in order to use this feature: {} ", e.getMessage()); + } + } + + firstTransactions = client.getTransactions(minCommitTime, 0L, null, Long.MAX_VALUE, 1); if (!firstTransactions.getTransactions().isEmpty()) { Transaction firstTransaction = firstTransactions.getTransactions().get(0);