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();
}
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);
}
}
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;
}
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();
}
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);
}
}
Aggregations