Search in sources :

Example 1 with Transactions

use of org.alfresco.solr.client.Transactions 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 2 with Transactions

use of org.alfresco.solr.client.Transactions in project SearchServices by Alfresco.

the class MetadataTracker method indexTransactions.

private void indexTransactions() throws IOException, AuthenticationException, JSONException {
    long startElapsed = System.nanoTime();
    int docCount = 0;
    boolean requiresCommit = false;
    while (transactionsToIndex.peek() != null) {
        Long transactionId = transactionsToIndex.poll();
        if (transactionId != null) {
            Transactions transactions = client.getTransactions(null, transactionId, null, transactionId + 1, 1);
            if ((transactions.getTransactions().size() > 0) && (transactionId.equals(transactions.getTransactions().get(0).getId()))) {
                Transaction info = transactions.getTransactions().get(0);
                GetNodesParameters gnp = new GetNodesParameters();
                ArrayList<Long> txs = new ArrayList<Long>();
                txs.add(info.getId());
                gnp.setTransactionIds(txs);
                gnp.setStoreProtocol(storeRef.getProtocol());
                gnp.setStoreIdentifier(storeRef.getIdentifier());
                gnp.setShardProperty(shardProperty);
                List<Node> nodes = client.getNodes(gnp, (int) info.getUpdates());
                for (Node node : nodes) {
                    docCount++;
                    if (log.isDebugEnabled()) {
                        log.debug(node.toString());
                    }
                    this.infoSrv.indexNode(node, false);
                    checkShutdown();
                }
                // Index the transaction doc after the node - if this is not found then a reindex will be done.
                this.infoSrv.indexTransaction(info, false);
                requiresCommit = true;
                trackerStats.addTxDocs(nodes.size());
            }
        }
        if (docCount > batchCount) {
            if (this.infoSrv.getRegisteredSearcherCount() < getMaxLiveSearchers()) {
                checkShutdown();
                // this.infoSrv.commit();
                long endElapsed = System.nanoTime();
                trackerStats.addElapsedNodeTime(docCount, endElapsed - startElapsed);
                startElapsed = endElapsed;
                docCount = 0;
                requiresCommit = false;
            }
        }
    }
    if (requiresCommit || (docCount > 0)) {
        checkShutdown();
        // this.infoSrv.commit();
        long endElapsed = System.nanoTime();
        trackerStats.addElapsedNodeTime(docCount, endElapsed - startElapsed);
    }
}
Also used : Transactions(org.alfresco.solr.client.Transactions) Transaction(org.alfresco.solr.client.Transaction) GetNodesParameters(org.alfresco.solr.client.GetNodesParameters) Node(org.alfresco.solr.client.Node) ArrayList(java.util.ArrayList)

Example 3 with Transactions

use of org.alfresco.solr.client.Transactions in project SearchServices by Alfresco.

the class MetadataTracker method getSomeTransactions.

protected Transactions getSomeTransactions(BoundedDeque<Transaction> txnsFound, Long fromCommitTime, long timeStep, int maxResults, long endTime) throws AuthenticationException, IOException, JSONException, EncoderException {
    long actualTimeStep = timeStep;
    ShardState shardstate = getShardState();
    Transactions transactions;
    // step forward in time until we find something or hit the time bound
    // max id unbounded
    Long startTime = fromCommitTime == null ? Long.valueOf(0L) : fromCommitTime;
    do {
        transactions = client.getTransactions(startTime, null, startTime + actualTimeStep, null, maxResults, shardstate);
        startTime += actualTimeStep;
    } while (((transactions.getTransactions().size() == 0) && (startTime < endTime)) || ((transactions.getTransactions().size() > 0) && alreadyFoundTransactions(txnsFound, transactions)));
    return transactions;
}
Also used : Transactions(org.alfresco.solr.client.Transactions) ShardState(org.alfresco.repo.index.shard.ShardState)

Example 4 with Transactions

use of org.alfresco.solr.client.Transactions in project SearchServices by Alfresco.

the class MetadataTrackerTest method doTrackWithOneTransactionUpdatesOnce.

@Test
@Ignore("Superseded by AlfrescoSolrTrackerTest")
public void doTrackWithOneTransactionUpdatesOnce() throws AuthenticationException, IOException, JSONException, EncoderException {
    TrackerState state = new TrackerState();
    state.setTimeToStopIndexing(2L);
    when(srv.getTrackerInitialState()).thenReturn(state);
    // TrackerState is persisted per tracker
    when(this.metadataTracker.getTrackerState()).thenReturn(state);
    List<Transaction> txsList = new ArrayList<>();
    Transaction tx = new Transaction();
    tx.setCommitTimeMs(1L);
    tx.setDeletes(1);
    tx.setUpdates(1);
    txsList.add(tx);
    Transactions txs = mock(Transactions.class);
    when(txs.getTransactions()).thenReturn(txsList);
    // Subsequent calls to getTransactions must return a different set of transactions to avoid an infinite loop
    when(repositoryClient.getTransactions(anyLong(), anyLong(), anyLong(), anyLong(), anyInt())).thenReturn(txs).thenReturn(txs).thenReturn(mock(Transactions.class));
    when(repositoryClient.getTransactions(anyLong(), anyLong(), anyLong(), anyLong(), anyInt(), isNull(ShardState.class))).thenReturn(txs).thenReturn(txs).thenReturn(mock(Transactions.class));
    when(repositoryClient.getTransactions(anyLong(), anyLong(), anyLong(), anyLong(), anyInt(), any(ShardState.class))).thenReturn(txs).thenReturn(txs).thenReturn(mock(Transactions.class));
    List<Node> nodes = new ArrayList<>();
    Node node = new Node();
    nodes.add(node);
    when(repositoryClient.getNodes(any(GetNodesParameters.class), anyInt())).thenReturn(nodes);
    this.metadataTracker.doTrack();
    InOrder inOrder = inOrder(srv);
    inOrder.verify(srv).indexNodes(nodes, true, false);
    inOrder.verify(srv).indexTransaction(tx, true);
    inOrder.verify(srv).commit();
}
Also used : Transactions(org.alfresco.solr.client.Transactions) ShardState(org.alfresco.repo.index.shard.ShardState) InOrder(org.mockito.InOrder) Transaction(org.alfresco.solr.client.Transaction) Node(org.alfresco.solr.client.Node) GetNodesParameters(org.alfresco.solr.client.GetNodesParameters) ArrayList(java.util.ArrayList) TrackerState(org.alfresco.solr.TrackerState) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 5 with Transactions

use of org.alfresco.solr.client.Transactions in project SearchServices by Alfresco.

the class MetadataTracker method reindexTransactions.

private void reindexTransactions() throws IOException, AuthenticationException, JSONException {
    long startElapsed = System.nanoTime();
    int docCount = 0;
    while (transactionsToReindex.peek() != null) {
        Long transactionId = transactionsToReindex.poll();
        if (transactionId != null) {
            // make sure it is cleaned out so we do not miss deletes
            this.infoSrv.deleteByTransactionId(transactionId);
            Transactions transactions = client.getTransactions(null, transactionId, null, transactionId + 1, 1);
            if ((transactions.getTransactions().size() > 0) && (transactionId.equals(transactions.getTransactions().get(0).getId()))) {
                Transaction info = transactions.getTransactions().get(0);
                this.infoSrv.dirtyTransaction(info.getId());
                GetNodesParameters gnp = new GetNodesParameters();
                ArrayList<Long> txs = new ArrayList<Long>();
                txs.add(info.getId());
                gnp.setTransactionIds(txs);
                gnp.setStoreProtocol(storeRef.getProtocol());
                gnp.setStoreIdentifier(storeRef.getIdentifier());
                List<Node> nodes = client.getNodes(gnp, (int) info.getUpdates());
                for (Node node : nodes) {
                    docCount++;
                    if (log.isDebugEnabled()) {
                        log.debug(node.toString());
                    }
                    this.infoSrv.indexNode(node, true);
                    checkShutdown();
                }
                // Index the transaction doc after the node - if this is not found then a reindex will be done.
                this.infoSrv.indexTransaction(info, true);
            }
        }
        if (docCount > batchCount) {
            if (this.infoSrv.getRegisteredSearcherCount() < getMaxLiveSearchers()) {
                checkShutdown();
                long endElapsed = System.nanoTime();
                trackerStats.addElapsedNodeTime(docCount, endElapsed - startElapsed);
                startElapsed = endElapsed;
                docCount = 0;
            }
        }
    }
    if (docCount > 0) {
        checkShutdown();
        // this.infoSrv.commit();
        long endElapsed = System.nanoTime();
        trackerStats.addElapsedNodeTime(docCount, endElapsed - startElapsed);
    }
}
Also used : Transactions(org.alfresco.solr.client.Transactions) Transaction(org.alfresco.solr.client.Transaction) GetNodesParameters(org.alfresco.solr.client.GetNodesParameters) Node(org.alfresco.solr.client.Node) ArrayList(java.util.ArrayList)

Aggregations

Transactions (org.alfresco.solr.client.Transactions)8 Transaction (org.alfresco.solr.client.Transaction)7 ArrayList (java.util.ArrayList)5 ShardState (org.alfresco.repo.index.shard.ShardState)3 GetNodesParameters (org.alfresco.solr.client.GetNodesParameters)3 Node (org.alfresco.solr.client.Node)3 AlfrescoRuntimeException (org.alfresco.error.AlfrescoRuntimeException)2 BoundedDeque (org.alfresco.solr.BoundedDeque)2 TrackerState (org.alfresco.solr.TrackerState)2 Ignore (org.junit.Ignore)2 Test (org.junit.Test)2 IOException (java.io.IOException)1 LinkedHashSet (java.util.LinkedHashSet)1 AuthenticationException (org.alfresco.httpclient.AuthenticationException)1 IOpenBitSet (org.alfresco.solr.adapters.IOpenBitSet)1 EncoderException (org.apache.commons.codec.EncoderException)1 JSONException (org.json.JSONException)1 InOrder (org.mockito.InOrder)1