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