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 9df908039..82331fcf8 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 @@ -2,7 +2,7 @@ * #%L * Alfresco Search Services * %% - * Copyright (C) 2005 - 2022 Alfresco Software Limited + * Copyright (C) 2005 - 2024 Alfresco Software Limited * %% * This file is part of the Alfresco software. * If the software was purchased under a paid Alfresco license, the terms of @@ -79,7 +79,6 @@ public class MetadataTracker extends ActivatableTracker private static final int DEFAULT_NODE_BATCH_SIZE = 50; private static final String DEFAULT_INITIAL_TRANSACTION_RANGE = "0-2000"; private static final long DEFAULT_METADATA_TRACKER_TIMESTEP = TIME_STEP_1_HR_IN_MS; - private static final long INITIAL_MAX_TXN_ID = 2000L; private int matadataTrackerParallelism; private int transactionDocsBatchSize; @@ -355,8 +354,8 @@ public class MetadataTracker extends ActivatableTracker // No firstTransaction checking is required for this case. if (minCommitTime != -1L) { - firstTransactions = client.getTransactions(minCommitTime, 0L, - null, INITIAL_MAX_TXN_ID, 1); + firstTransactions = client.getTransactions(minCommitTime, minTxnIdRange.getFirst(), + null, minTxnIdRange.getSecond(), 1); if (!firstTransactions.getTransactions().isEmpty()) { Transaction firstTransaction = firstTransactions.getTransactions().get(0); @@ -1262,8 +1261,8 @@ public class MetadataTracker extends ActivatableTracker { // DB TX Count long firstTransactionCommitTime = 0; - Transactions firstTransactions = client.getTransactions(null, 0L, - null, INITIAL_MAX_TXN_ID, 1); + Transactions firstTransactions = client.getTransactions(null, minTxnIdRange.getFirst(), + null, minTxnIdRange.getSecond(), 1); if(firstTransactions.getTransactions().size() > 0) { Transaction firstTransaction = firstTransactions.getTransactions().get(0); diff --git a/search-services/alfresco-search/src/test/java/org/alfresco/solr/tracker/MetadataTrackerTest.java b/search-services/alfresco-search/src/test/java/org/alfresco/solr/tracker/MetadataTrackerTest.java index 7466a2576..bb9e61f79 100644 --- a/search-services/alfresco-search/src/test/java/org/alfresco/solr/tracker/MetadataTrackerTest.java +++ b/search-services/alfresco-search/src/test/java/org/alfresco/solr/tracker/MetadataTrackerTest.java @@ -2,7 +2,7 @@ * #%L * Alfresco Search Services * %% - * Copyright (C) 2005 - 2022 Alfresco Software Limited + * Copyright (C) 2005 - 2024 Alfresco Software Limited * %% * This file is part of the Alfresco software. * If the software was purchased under a paid Alfresco license, the terms of @@ -33,6 +33,7 @@ import java.util.Properties; import org.alfresco.httpclient.AuthenticationException; import org.alfresco.repo.index.shard.ShardState; +import org.alfresco.solr.AlfrescoCoreAdminHandler; import org.alfresco.solr.InformationServer; import org.alfresco.solr.NodeReport; import org.alfresco.solr.TrackerState; @@ -66,6 +67,7 @@ import static org.mockito.Mockito.inOrder; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.never; import static org.mockito.Mockito.spy; +import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; @@ -94,6 +96,7 @@ public class MetadataTrackerTest @Before public void setUp() { + doReturn("0-2000").when(props).getProperty("solr.initial.transaction.range"); doReturn("workspace://SpacesStore").when(props).getProperty("alfresco.stores"); when(srv.getTrackerStats()).thenReturn(trackerStats); String coreName = "theCoreName"; @@ -281,4 +284,34 @@ public class MetadataTrackerTest node.setTxnId(TX_ID); return node; } + + @Test + public void testCheckRepoAndIndexConsistency() throws AuthenticationException, IOException, JSONException + { + TrackerState state = new TrackerState(); + ModelTracker modelTracker = mock(ModelTracker.class); + when(modelTracker.hasModels()).thenReturn(true); + when(this.metadataTracker.getTrackerState()).thenReturn(state); + + TrackerRegistry registry = new TrackerRegistry(); + registry.setModelTracker(modelTracker); + AlfrescoCoreAdminHandler alfrescoCoreAdminHandler = mock(AlfrescoCoreAdminHandler.class); + when(this.srv.getAdminHandler()).thenReturn(alfrescoCoreAdminHandler); + when(alfrescoCoreAdminHandler.getTrackerRegistry()).thenReturn(registry); + + List txsList = new ArrayList<>(); + Transaction tx1 = new Transaction(); + tx1.setCommitTimeMs(1L); + tx1.setDeletes(1); + tx1.setUpdates(1); + txsList.add(tx1); + + Transactions txs = new Transactions(txsList, 0L, 2000L); + when(repositoryClient.getTransactions(null, 0L, null, 2000L, 1)).thenReturn(txs); + when(repositoryClient.getTransactions(1L, null, 3600001L, null, 2000)).thenReturn(txs); + + this.metadataTracker.doTrack("AnIterationId"); + + verify(this.metadataTracker, times(1)).doTrack("AnIterationId"); + } }