mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-07-24 17:32:48 +00:00
Merged V2.1 to HEAD
6950: Fix for forum issue (6111) when using xsl:include 6951: Partial fix for WCM-862 6952: Merged V1.4 to V2.1 6921: Reindex tracking refactoring. 6954: Merged V1.4 to V2.1 6927: Config and startup changes for index tracking git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@7369 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -24,186 +24,41 @@
|
||||
*/
|
||||
package org.alfresco.repo.node.index;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.alfresco.repo.domain.Transaction;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
/**
|
||||
* Component to check and recover the indexes.
|
||||
*
|
||||
* @deprecated Deprecated as of 1.4.5. Use {@linkplain IndexTransactionTracker}
|
||||
*
|
||||
* @author Derek Hulley
|
||||
*/
|
||||
public class IndexRemoteTransactionTracker extends AbstractReindexComponent
|
||||
{
|
||||
private static Log logger = LogFactory.getLog(IndexRemoteTransactionTracker.class);
|
||||
|
||||
private boolean remoteOnly;
|
||||
private boolean started;
|
||||
private long currentTxnId;
|
||||
|
||||
/**
|
||||
* Dumps an error message.
|
||||
*/
|
||||
public IndexRemoteTransactionTracker()
|
||||
{
|
||||
remoteOnly = true;
|
||||
currentTxnId = -1L;
|
||||
logger.warn(
|
||||
"The component 'org.alfresco.repo.node.index.IndexRemoteTransactionTracker' " +
|
||||
"has been replaced by 'org.alfresco.repo.node.index.IndexTransactionTracker' \n" +
|
||||
"See the extension sample file 'index-tracking-context.xml.sample'. \n" +
|
||||
"See http://wiki.alfresco.com/wiki/High_Availability_Configuration_V1.4_to_V2.1#Lucene_Index_Synchronization.");
|
||||
}
|
||||
|
||||
/**
|
||||
* Set whether or not this component should only track remote transactions.
|
||||
* By default, it is <tt>true</tt>, but under certain test conditions, it may
|
||||
* be desirable to track local transactions too; e.g. during testing of clustering
|
||||
* when running multiple instances on the same machine.
|
||||
*
|
||||
* @param remoteOnly <tt>true</tt> to reindex only those transactions that were
|
||||
* committed to the database by a remote server.
|
||||
* As of release 1.4.5, 2.0.5 and 2.1.1, this property is no longer is use.
|
||||
*/
|
||||
public void setRemoteOnly(boolean remoteOnly)
|
||||
{
|
||||
this.remoteOnly = remoteOnly;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
protected void reindexImpl()
|
||||
{
|
||||
if (!started)
|
||||
{
|
||||
// Initialize the starting poing
|
||||
currentTxnId = getLastIndexedTxn();
|
||||
started = true;
|
||||
}
|
||||
|
||||
if (logger.isDebugEnabled())
|
||||
{
|
||||
logger.debug("Performing index tracking from txn " + currentTxnId);
|
||||
}
|
||||
|
||||
while (true)
|
||||
{
|
||||
// get next transactions to index
|
||||
List<Transaction> txns = getNextTransactions(currentTxnId);
|
||||
if (txns.size() == 0)
|
||||
{
|
||||
// we've caught up
|
||||
break;
|
||||
}
|
||||
// break out if the VM is shutting down
|
||||
if (isShuttingDown())
|
||||
{
|
||||
break;
|
||||
}
|
||||
// reindex all "foreign" or "local" transactions, one at a time
|
||||
for (Transaction txn : txns)
|
||||
{
|
||||
long txnId = txn.getId();
|
||||
reindexTransaction(txnId);
|
||||
currentTxnId = txnId;
|
||||
// break out if the VM is shutting down
|
||||
if (isShuttingDown())
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static final long DECREMENT_COUNT = 10L;
|
||||
/**
|
||||
* Finds the last indexed transaction. It works backwards from the
|
||||
* last index in increments, respecting the {@link #setRemoteOnly(boolean) remoteOnly}
|
||||
* flag.
|
||||
*
|
||||
* @return Returns the last index transaction or -1 if there is none
|
||||
*/
|
||||
protected long getLastIndexedTxn()
|
||||
{
|
||||
// get the last transaction
|
||||
Transaction txn = null;
|
||||
if (remoteOnly)
|
||||
{
|
||||
txn = nodeDaoService.getLastRemoteTxn();
|
||||
}
|
||||
else
|
||||
{
|
||||
txn = nodeDaoService.getLastTxn();
|
||||
}
|
||||
if (txn == null)
|
||||
{
|
||||
// There is no last transaction to use
|
||||
return -1L;
|
||||
}
|
||||
long currentTxnId = txn.getId();
|
||||
while (currentTxnId >= 0L)
|
||||
{
|
||||
// Check if the current txn is in the index
|
||||
InIndex txnInIndex = isTxnIdPresentInIndex(currentTxnId);
|
||||
if (txnInIndex == InIndex.YES)
|
||||
{
|
||||
// We found somewhere to start
|
||||
break;
|
||||
}
|
||||
|
||||
// Get back in time
|
||||
long lastCheckTxnId = currentTxnId;
|
||||
currentTxnId -= DECREMENT_COUNT;
|
||||
if (currentTxnId < 0L)
|
||||
{
|
||||
currentTxnId = -1L;
|
||||
}
|
||||
// We don't know if this number we have is a local or remote txn, so get the very next one
|
||||
Transaction nextTxn = null;
|
||||
if (remoteOnly)
|
||||
{
|
||||
List<Transaction> nextTxns = nodeDaoService.getNextRemoteTxns(currentTxnId, 1);
|
||||
if (nextTxns.size() > 0)
|
||||
{
|
||||
nextTxn = nextTxns.get(0);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
List<Transaction> nextTxns = nodeDaoService.getNextTxns(currentTxnId, 1);
|
||||
if (nextTxns.size() > 0)
|
||||
{
|
||||
nextTxn = nextTxns.get(0);
|
||||
}
|
||||
}
|
||||
if (nextTxn == null)
|
||||
{
|
||||
// There was nothing relevant after this, so keep going back in time
|
||||
continue;
|
||||
}
|
||||
else if (nextTxn.getId() >= lastCheckTxnId)
|
||||
{
|
||||
// Decrementing by DECREMENT_COUNT was not enough
|
||||
continue;
|
||||
}
|
||||
// Adjust the last one we looked at to reflect the correct txn id
|
||||
currentTxnId = nextTxn.getId();
|
||||
}
|
||||
// We are close enough to the beginning, so just go for the first transaction
|
||||
if (currentTxnId < 0L)
|
||||
{
|
||||
currentTxnId = -1L;
|
||||
}
|
||||
return currentTxnId;
|
||||
}
|
||||
|
||||
private static final int MAX_TXN_COUNT = 1000;
|
||||
private List<Transaction> getNextTransactions(long currentTxnId)
|
||||
{
|
||||
List<Transaction> txns = null;
|
||||
if (remoteOnly)
|
||||
{
|
||||
txns = nodeDaoService.getNextRemoteTxns(currentTxnId, MAX_TXN_COUNT);
|
||||
}
|
||||
else
|
||||
{
|
||||
txns = nodeDaoService.getNextTxns(currentTxnId, MAX_TXN_COUNT);
|
||||
}
|
||||
// done
|
||||
return txns;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user