Search in sources :

Example 1 with TrackerState

use of org.alfresco.solr.TrackerState in project SearchServices by Alfresco.

the class ConsistencyComponent method process.

@Override
public void process(ResponseBuilder rb) throws IOException {
    SolrQueryRequest req = rb.req;
    AlfrescoCoreAdminHandler adminHandler = (AlfrescoCoreAdminHandler) req.getCore().getCoreContainer().getMultiCoreHandler();
    boolean isShard = rb.req.getParams().getBool(ShardParams.IS_SHARD, false);
    MetadataTracker metaTrkr = adminHandler.getTrackerRegistry().getTrackerForCore(req.getCore().getName(), MetadataTracker.class);
    if (metaTrkr != null && !isShard) {
        TrackerState metadataTrkrState = metaTrkr.getTrackerState();
        long lastIndexedTx = metadataTrkrState.getLastIndexedTxId();
        long lastIndexTxCommitTime = metadataTrkrState.getLastIndexedTxCommitTime();
        long lastTxIdOnServer = metadataTrkrState.getLastTxIdOnServer();
        long transactionsToDo = lastTxIdOnServer - lastIndexedTx;
        if (transactionsToDo < 0) {
            transactionsToDo = 0;
        }
        rb.rsp.add("lastIndexedTx", lastIndexedTx);
        rb.rsp.add("lastIndexedTxTime", lastIndexTxCommitTime);
        rb.rsp.add("txRemaining", transactionsToDo);
    }
}
Also used : SolrQueryRequest(org.apache.solr.request.SolrQueryRequest) AlfrescoCoreAdminHandler(org.alfresco.solr.AlfrescoCoreAdminHandler) TrackerState(org.alfresco.solr.TrackerState) MetadataTracker(org.alfresco.solr.tracker.MetadataTracker)

Example 2 with TrackerState

use of org.alfresco.solr.TrackerState in project SearchServices by Alfresco.

the class MetadataTrackerTest method doTrackWithNoTransactionsDoesNothing.

@Test
@Ignore("Superseded by AlfrescoSolrTrackerTest")
public void doTrackWithNoTransactionsDoesNothing() throws AuthenticationException, IOException, JSONException, EncoderException {
    TrackerState state = new TrackerState();
    when(srv.getTrackerInitialState()).thenReturn(state);
    when(this.metadataTracker.getTrackerState()).thenReturn(state);
    Transactions txs = mock(Transactions.class);
    List<Transaction> txsList = new ArrayList<>();
    when(txs.getTransactions()).thenReturn(txsList);
    when(repositoryClient.getTransactions(anyLong(), anyLong(), anyLong(), anyLong(), anyInt(), isNull(ShardState.class))).thenReturn(txs);
    when(repositoryClient.getTransactions(anyLong(), anyLong(), anyLong(), anyLong(), anyInt(), any(ShardState.class))).thenReturn(txs);
    when(repositoryClient.getTransactions(anyLong(), anyLong(), anyLong(), anyLong(), anyInt())).thenReturn(txs);
    this.metadataTracker.doTrack();
    verify(srv, never()).commit();
}
Also used : Transactions(org.alfresco.solr.client.Transactions) ShardState(org.alfresco.repo.index.shard.ShardState) Transaction(org.alfresco.solr.client.Transaction) ArrayList(java.util.ArrayList) TrackerState(org.alfresco.solr.TrackerState) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 3 with TrackerState

use of org.alfresco.solr.TrackerState in project SearchServices by Alfresco.

the class MetadataTracker method getShardState.

/**
 * @return
 */
private ShardState getShardState() {
    TrackerState state = super.getTrackerState();
    ShardState shardstate = ShardStateBuilder.shardState().withMaster(isMaster).withLastUpdated(System.currentTimeMillis()).withLastIndexedChangeSetCommitTime(state.getLastIndexedChangeSetCommitTime()).withLastIndexedChangeSetId(state.getLastIndexedChangeSetId()).withLastIndexedTxCommitTime(state.getLastIndexedTxCommitTime()).withLastIndexedTxId(state.getLastIndexedTxId()).withShardInstance().withBaseUrl(infoSrv.getBaseUrl()).withPort(infoSrv.getPort()).withHostName(infoSrv.getHostName()).withShard().withInstance(shardInstance).withFloc().withNumberOfShards(shardCount).withAddedStoreRef(storeRef).withTemplate(shardTemplate).withHasContent(transformContent).withShardMethod(ShardMethodEnum.getShardMethod(shardMethod)).endFloc().endShard().endShardInstance().build();
    return shardstate;
}
Also used : ShardState(org.alfresco.repo.index.shard.ShardState) TrackerState(org.alfresco.solr.TrackerState)

Example 4 with TrackerState

use of org.alfresco.solr.TrackerState in project SearchServices by Alfresco.

the class MetadataTracker method trackRepository.

private void trackRepository() throws IOException, AuthenticationException, JSONException, EncoderException {
    checkShutdown();
    if (!isMaster && isSlave) {
        // Dynamic registration
        ShardState shardstate = getShardState();
        client.getTransactions(0L, null, 0L, null, 0, shardstate);
        return;
    }
    // Check we are tracking the correct repository
    TrackerState state = super.getTrackerState();
    if (state.getTrackerCycles() == 0) {
        // We have a new tracker state so do the checks.
        checkRepoAndIndexConsistency(state);
    }
    if (docRouter instanceof DBIDRangeRouter) {
        DBIDRangeRouter dbidRangeRouter = (DBIDRangeRouter) docRouter;
        long indexCap = infoSrv.getIndexCap();
        long endRange = dbidRangeRouter.getEndRange();
        assert (indexCap == -1 || indexCap >= endRange);
        if (indexCap > endRange) {
            dbidRangeRouter.setExpanded(true);
            dbidRangeRouter.setEndRange(indexCap);
        }
        dbidRangeRouter.setInitialized(true);
    }
    checkShutdown();
    trackTransactions();
}
Also used : ShardState(org.alfresco.repo.index.shard.ShardState) TrackerState(org.alfresco.solr.TrackerState)

Example 5 with TrackerState

use of org.alfresco.solr.TrackerState in project SearchServices by Alfresco.

the class AclTrackerTest method setUp.

@Before
public void setUp() throws Exception {
    trackerState = new TrackerState();
    // Nothing would happen if it were already running.
    trackerState.setRunning(false);
    Properties props = createProperties();
    // Spy in order to stub some methods and verify others. Note: non-stubbed methods go to the real class.
    tracker = spy(new AclTracker(props, client, "core-name", informationServer));
}
Also used : TrackerState(org.alfresco.solr.TrackerState) Properties(java.util.Properties) Before(org.junit.Before)

Aggregations

TrackerState (org.alfresco.solr.TrackerState)7 ShardState (org.alfresco.repo.index.shard.ShardState)4 ArrayList (java.util.ArrayList)2 Transaction (org.alfresco.solr.client.Transaction)2 Transactions (org.alfresco.solr.client.Transactions)2 Ignore (org.junit.Ignore)2 Test (org.junit.Test)2 Properties (java.util.Properties)1 AlfrescoCoreAdminHandler (org.alfresco.solr.AlfrescoCoreAdminHandler)1 GetNodesParameters (org.alfresco.solr.client.GetNodesParameters)1 Node (org.alfresco.solr.client.Node)1 MetadataTracker (org.alfresco.solr.tracker.MetadataTracker)1 SolrQueryRequest (org.apache.solr.request.SolrQueryRequest)1 Before (org.junit.Before)1 InOrder (org.mockito.InOrder)1