Search in sources :

Example 21 with Transaction

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

the class MetadataTracker method indexTransactionsAfterAsynchronous.

private void indexTransactionsAfterAsynchronous(HashSet<Transaction> txsIndexed, TrackerState state) throws IOException {
    waitForAsynchronous();
    for (Transaction tx : txsIndexed) {
        super.infoSrv.indexTransaction(tx, true);
        // Transactions are ordered by commit time and tie-broken by tx id
        if (tx.getCommitTimeMs() > state.getLastIndexedTxCommitTime() || tx.getCommitTimeMs() == state.getLastIndexedTxCommitTime() && tx.getId() > state.getLastIndexedTxId()) {
            state.setLastIndexedTxCommitTime(tx.getCommitTimeMs());
            state.setLastIndexedTxId(tx.getId());
        }
        trackerStats.addTxDocs((int) (tx.getDeletes() + tx.getUpdates()));
    }
    txsIndexed.clear();
// super.infoSrv.commit();
}
Also used : Transaction(org.alfresco.solr.client.Transaction)

Example 22 with Transaction

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

the class MetadataTracker method checkRepoAndIndexConsistency.

/**
 * Checks the first and last TX time
 * @param state the state of this tracker
 * @throws AuthenticationException
 * @throws IOException
 * @throws JSONException
 */
private void checkRepoAndIndexConsistency(TrackerState state) throws AuthenticationException, IOException, JSONException {
    Transactions firstTransactions = null;
    if (state.getLastGoodTxCommitTimeInIndex() == 0) {
        state.setCheckedLastTransactionTime(true);
        state.setCheckedFirstTransactionTime(true);
        log.info("No transactions found - no verification required");
        firstTransactions = client.getTransactions(null, 0L, null, 2000L, 1);
        if (!firstTransactions.getTransactions().isEmpty()) {
            Transaction firstTransaction = firstTransactions.getTransactions().get(0);
            long firstTransactionCommitTime = firstTransaction.getCommitTimeMs();
            state.setLastGoodTxCommitTimeInIndex(firstTransactionCommitTime);
            setLastTxCommitTimeAndTxIdInTrackerState(firstTransactions, state);
        }
    }
    if (!state.isCheckedFirstTransactionTime()) {
        firstTransactions = client.getTransactions(null, 0L, null, 2000L, 1);
        if (!firstTransactions.getTransactions().isEmpty()) {
            Transaction firstTransaction = firstTransactions.getTransactions().get(0);
            long firstTxId = firstTransaction.getId();
            long firstTransactionCommitTime = firstTransaction.getCommitTimeMs();
            int setSize = this.infoSrv.getTxDocsSize("" + firstTxId, "" + firstTransactionCommitTime);
            if (setSize == 0) {
                log.error("First transaction was not found with the correct timestamp.");
                log.error("SOLR has successfully connected to your repository  however the SOLR indexes and repository database do not match.");
                log.error("If this is a new or rebuilt database your SOLR indexes also need to be re-built to match the database.");
                log.error("You can also check your SOLR connection details in solrcore.properties.");
                throw new AlfrescoRuntimeException("Initial transaction not found with correct timestamp");
            } else if (setSize == 1) {
                state.setCheckedFirstTransactionTime(true);
                log.info("Verified first transaction and timestamp in index");
            } else {
                log.warn("Duplicate initial transaction found with correct timestamp");
            }
        }
    }
    // Checks that the last TxId in solr is <= last TxId in repo
    if (!state.isCheckedLastTransactionTime()) {
        if (firstTransactions == null) {
            firstTransactions = client.getTransactions(null, 0L, null, 2000L, 1);
        }
        setLastTxCommitTimeAndTxIdInTrackerState(firstTransactions, state);
        Long maxTxnCommitTimeInRepo = firstTransactions.getMaxTxnCommitTime();
        Long maxTxnIdInRepo = firstTransactions.getMaxTxnId();
        if (maxTxnCommitTimeInRepo != null && maxTxnIdInRepo != null) {
            Transaction maxTxInIndex = this.infoSrv.getMaxTransactionIdAndCommitTimeInIndex();
            if (maxTxInIndex.getCommitTimeMs() > maxTxnCommitTimeInRepo) {
                log.error("Last transaction was found in index with timestamp later than that of repository.");
                log.error("Max Tx In Index: " + maxTxInIndex.getId() + ", In Repo: " + maxTxnIdInRepo);
                log.error("Max Tx Commit Time In Index: " + maxTxInIndex.getCommitTimeMs() + ", In Repo: " + maxTxnCommitTimeInRepo);
                log.error("SOLR has successfully connected to your repository  however the SOLR indexes and repository database do not match.");
                log.error("If this is a new or rebuilt database your SOLR indexes also need to be re-built to match the database.");
                log.error("You can also check your SOLR connection details in solrcore.properties.");
                throw new AlfrescoRuntimeException("Last transaction found in index with incorrect timestamp");
            } else {
                state.setCheckedLastTransactionTime(true);
                log.info("Verified last transaction timestamp in index less than or equal to that of repository.");
            }
        }
    }
}
Also used : Transactions(org.alfresco.solr.client.Transactions) Transaction(org.alfresco.solr.client.Transaction) AlfrescoRuntimeException(org.alfresco.error.AlfrescoRuntimeException)

Aggregations

Transaction (org.alfresco.solr.client.Transaction)22 ArrayList (java.util.ArrayList)15 Node (org.alfresco.solr.client.Node)12 Test (org.junit.Test)10 AclChangeSet (org.alfresco.solr.client.AclChangeSet)9 NodeMetaData (org.alfresco.solr.client.NodeMetaData)9 AlfrescoSolrUtils.getAcl (org.alfresco.solr.AlfrescoSolrUtils.getAcl)8 AlfrescoSolrUtils.getAclChangeSet (org.alfresco.solr.AlfrescoSolrUtils.getAclChangeSet)8 AlfrescoSolrUtils.getAclReaders (org.alfresco.solr.AlfrescoSolrUtils.getAclReaders)8 AlfrescoSolrUtils.getNode (org.alfresco.solr.AlfrescoSolrUtils.getNode)8 AlfrescoSolrUtils.getNodeMetaData (org.alfresco.solr.AlfrescoSolrUtils.getNodeMetaData)8 AlfrescoSolrUtils.getTransaction (org.alfresco.solr.AlfrescoSolrUtils.getTransaction)8 AlfrescoSolrUtils.indexAclChangeSet (org.alfresco.solr.AlfrescoSolrUtils.indexAclChangeSet)8 Acl (org.alfresco.solr.client.Acl)8 AclReaders (org.alfresco.solr.client.AclReaders)8 Term (org.apache.lucene.index.Term)8 TermQuery (org.apache.lucene.search.TermQuery)8 Transactions (org.alfresco.solr.client.Transactions)7 AbstractAlfrescoDistributedTest (org.alfresco.solr.AbstractAlfrescoDistributedTest)4 GetNodesParameters (org.alfresco.solr.client.GetNodesParameters)4