[exo-jcr-commits] exo-jcr SVN: r3264 - jcr/branches/1.14-CNK/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene.
do-not-reply at jboss.org
do-not-reply at jboss.org
Fri Oct 8 09:03:56 EDT 2010
Author: nzamosenchuk
Date: 2010-10-08 09:03:55 -0400 (Fri, 08 Oct 2010)
New Revision: 3264
Removed:
jcr/branches/1.14-CNK/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/Recovery.java
jcr/branches/1.14-CNK/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/RedoLog.java
Modified:
jcr/branches/1.14-CNK/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/MultiIndex.java
Log:
EXOJCR-987 : actions and redo successfully deleted
Modified: jcr/branches/1.14-CNK/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/MultiIndex.java
===================================================================
--- jcr/branches/1.14-CNK/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/MultiIndex.java 2010-10-08 12:39:11 UTC (rev 3263)
+++ jcr/branches/1.14-CNK/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/MultiIndex.java 2010-10-08 13:03:55 UTC (rev 3264)
@@ -23,7 +23,6 @@
import org.exoplatform.services.jcr.dataflow.ItemDataConsumer;
import org.exoplatform.services.jcr.datamodel.ItemData;
import org.exoplatform.services.jcr.datamodel.NodeData;
-import org.exoplatform.services.jcr.impl.Constants;
import org.exoplatform.services.jcr.impl.core.query.IndexerIoMode;
import org.exoplatform.services.jcr.impl.core.query.IndexerIoModeHandler;
import org.exoplatform.services.jcr.impl.core.query.IndexerIoModeListener;
@@ -156,11 +155,6 @@
private final Object updateMonitor = new Object();
/**
- * <code>true</code> if the redo log contained entries on startup.
- */
- private boolean redoLogApplied = false;
-
- /**
* The time this index was last flushed or a transaction was committed.
*/
private long lastFlushTime;
@@ -182,11 +176,6 @@
private TimerTask flushTask;
/**
- * The RedoLog of this <code>MultiIndex</code>.
- */
- private RedoLog redoLog = null;
-
- /**
* The indexing queue with pending text extraction jobs.
*/
private IndexingQueue indexingQueue;
@@ -202,11 +191,6 @@
private long nextTransactionId = 0;
/**
- * The current transaction id.
- */
- private long currentTransactionId = -1;
-
- /**
* Flag indicating whether re-indexing is running.
*/
private boolean reindexing = false;
@@ -386,16 +370,16 @@
{
long count = 0;
// traverse and index workspace
-
+
// TODO: this was removed
//executeAndLog(new Start(Action.INTERNAL_TRANSACTION));
-
+
// NodeData rootState = (NodeData) stateMgr.getItemData(rootId);
count = createIndex(indexingTree.getIndexingRoot(), stateMgr, count);
-
+
// TODO : this was replaced
//executeAndLog(new Commit(getTransactionId()));
-
+
log.info("Created initial index for {} nodes", new Long(count));
releaseMultiReader();
scheduleFlushTask();
@@ -461,15 +445,15 @@
try
{
long transactionId = nextTransactionId++;
-
- // TODO: this was removed
+
+ // TODO: this was removed
//executeAndLog(new Start(transactionId));
for (Iterator it = remove.iterator(); it.hasNext();)
{
// TODO this was replaced
//executeAndLog(new DeleteNode(transactionId, (String)it.next()));
-
+
String uuidString = (String)it.next();
// check if indexing queue is still working on
// this node from a previous update
@@ -498,9 +482,7 @@
}
}
}
-
-
-
+
}
for (Iterator it = add.iterator(); it.hasNext();)
{
@@ -514,13 +496,13 @@
{
volatileIndex.addDocuments(new Document[]{doc});
}
-
+
// commit volatile index if needed
flush |= checkVolatileCommit();
}
}
-
- // TODO : this was replaced
+
+ // TODO : this was replaced
//executeAndLog(new Commit(transactionId));
// flush whole index when volatile index has been commited.
@@ -596,10 +578,10 @@
try
{
Term idTerm = new Term(FieldNames.UUID, uuid.toString());
-
- // TODO: this was removed
+
+ // TODO: this was removed
//executeAndLog(new Start(Action.INTERNAL_TRANSACTION));
-
+
num = volatileIndex.removeDocument(idTerm);
if (num > 0)
{
@@ -621,7 +603,7 @@
num += removed;
}
}
- // TODO : this was replaced
+ // TODO : this was replaced
//executeAndLog(new Commit(getTransactionId()));
}
finally
@@ -849,7 +831,7 @@
{
// TODO this was replaced
//executeAndLog(new DeleteIndex(getTransactionId(), indexName));
-
+
for (Iterator it2 = indexes.iterator(); it2.hasNext();)
{
PersistentIndex idx = (PersistentIndex)it2.next();
@@ -860,7 +842,7 @@
break;
}
}
-
+
}
}
@@ -871,7 +853,7 @@
///executeAndLog(new CreateIndex(getTransactionId(), index.getName()));
PersistentIndex idx = getOrCreateIndex(index.getName());
-
+
// TODO: this is replaced
//executeAndLog(new AddIndex(getTransactionId(), index.getName()));
if (!indexNames.contains(index.getName()))
@@ -891,8 +873,8 @@
{
// only commit if we are not reindexing
// when reindexing the final commit is done at the very end
-
- // TODO : this was replaced
+
+ // TODO : this was replaced
//executeAndLog(new Commit(getTransactionId()));
}
}
@@ -1130,17 +1112,6 @@
}
/**
- * Returns <code>true</code> if the redo log contained entries while this
- * index was instantiated; <code>false</code> otherwise.
- *
- * @return <code>true</code> if the redo log contained entries.
- */
- boolean getRedoLogApplied()
- {
- return redoLogApplied;
- }
-
- /**
* Removes the <code>index</code> from the list of active sub indexes. The
* Index is not acutally deleted right away, but postponed to the
* transaction commit.
@@ -1198,19 +1169,17 @@
//executeAndLog(new DeleteIndex(getTransactionId(), index.getName()));
index.close();
- deleteIndex(index);
+ deleteIndex(index);
}
}
}
- // TODO : this was replaced
+ // TODO : this was replaced
//executeAndLog(new Commit(getTransactionId()));
indexNames.write();
// reset redo log
- redoLog.clear();
-
lastFlushTime = System.currentTimeMillis();
lastFileSystemFlushTime = System.currentTimeMillis();
}
@@ -1326,48 +1295,6 @@
}
/**
- * Returns the current transaction id.
- *
- * @return the current transaction id.
- */
- private long getTransactionId()
- {
- return currentTransactionId;
- }
-
- /**
- * Executes action <code>a</code> and appends the action to the redo log if
- * successful.
- *
- * @param a
- * the <code>Action</code> to execute.
- * @return the executed action.
- * @throws IOException
- * if an error occurs while executing the action or appending
- * the action to the redo log.
- */
- private Action executeAndLog(final Action a) throws IOException
- {
- return SecurityHelper.doPriviledgedIOExceptionAction(new PrivilegedExceptionAction<Action>()
- {
- public Action run() throws Exception
- {
- a.execute(MultiIndex.this);
- redoLog.append(a);
- // please note that flushing the redo log is only required on
- // commit, but we also want to keep track of new indexes for sure.
- // otherwise it might happen that unused index folders are orphaned
- // after a crash.
- if (a.getType() == Action.TYPE_COMMIT || a.getType() == Action.TYPE_ADD_INDEX)
- {
- redoLog.flush();
- }
- return a;
- }
- });
- }
-
- /**
* Checks if it is needed to commit the volatile index according to
* {@link SearchIndex#getMaxVolatileIndexSize()}.
*
@@ -1403,31 +1330,31 @@
long time = System.currentTimeMillis();
// create index
-
+
//TODO this was replaced
-// CreateIndex create = new CreateIndex(getTransactionId(), null);
-// executeAndLog(create);
-
+ // CreateIndex create = new CreateIndex(getTransactionId(), null);
+ // executeAndLog(create);
+
PersistentIndex idx = getOrCreateIndex(null);
// commit volatile index
-
+
// TODO THIS IS REPLACED
//executeAndLog(new VolatileCommit(getTransactionId(), idx.getName()));
idx.copyIndex(volatileIndex);
resetVolatileIndex();
-
+
// TODO this is replaced
// add new index
-// AddIndex add = new AddIndex(getTransactionId(), create.getIndexName());
-// executeAndLog(add);
+ // AddIndex add = new AddIndex(getTransactionId(), create.getIndexName());
+ // executeAndLog(add);
if (!indexNames.contains(idx.getName()))
{
indexNames.addName(idx.getName());
}
-
+
// create new volatile index
resetVolatileIndex();
@@ -1465,11 +1392,11 @@
{
return count;
}
-
+
// TODO: this is replaced
//executeAndLog(new AddNode(getTransactionId(), node.getIdentifier()));
volatileIndex.addDocuments(new Document[]{createDocument(node)});
-
+
if (++count % 100 == 0)
{
@@ -1565,7 +1492,6 @@
{
try
{
- if (redoLog.hasEntries())
{
log.debug("Flushing index after being idle for " + idleTime + " ms.");
synchronized (updateMonitor)
@@ -1647,7 +1573,7 @@
{
// TODO this was replaced
//executeAndLog(new DeleteNode(getTransactionId(), (String)it.next()));
-
+
String uuidString = (String)it.next();
// check if indexing queue is still working on
// this node from a previous update
@@ -1676,8 +1602,7 @@
}
}
}
-
-
+
}
for (Iterator it = finished.values().iterator(); it.hasNext();)
{
@@ -1703,899 +1628,6 @@
// >---------------------------------------
/**
- * Defines an action on an <code>MultiIndex</code>.
- */
- public abstract static class Action
- {
-
- /**
- * Action identifier in redo log for transaction start action.
- */
- static final String START = "STR";
-
- /**
- * Action type for start action.
- */
- public static final int TYPE_START = 0;
-
- /**
- * Action identifier in redo log for add node action.
- */
- static final String ADD_NODE = "ADD";
-
- /**
- * Action type for add node action.
- */
- public static final int TYPE_ADD_NODE = 1;
-
- /**
- * Action identifier in redo log for node delete action.
- */
- static final String DELETE_NODE = "DEL";
-
- /**
- * Action type for delete node action.
- */
- public static final int TYPE_DELETE_NODE = 2;
-
- /**
- * Action identifier in redo log for transaction commit action.
- */
- static final String COMMIT = "COM";
-
- /**
- * Action type for commit action.
- */
- public static final int TYPE_COMMIT = 3;
-
- /**
- * Action identifier in redo log for volatile index commit action.
- */
- static final String VOLATILE_COMMIT = "VOL_COM";
-
- /**
- * Action type for volatile index commit action.
- */
- public static final int TYPE_VOLATILE_COMMIT = 4;
-
- /**
- * Action identifier in redo log for index create action.
- */
- static final String CREATE_INDEX = "CRE_IDX";
-
- /**
- * Action type for create index action.
- */
- public static final int TYPE_CREATE_INDEX = 5;
-
- /**
- * Action identifier in redo log for index add action.
- */
- static final String ADD_INDEX = "ADD_IDX";
-
- /**
- * Action type for add index action.
- */
- public static final int TYPE_ADD_INDEX = 6;
-
- /**
- * Action identifier in redo log for delete index action.
- */
- static final String DELETE_INDEX = "DEL_IDX";
-
- /**
- * Action type for delete index action.
- */
- public static final int TYPE_DELETE_INDEX = 7;
-
- /**
- * Transaction identifier for internal actions like volatile index
- * commit triggered by timer thread.
- */
- static final long INTERNAL_TRANSACTION = -1;
-
- /**
- * Transaction identifier for internal action that replaces indexs.
- */
- static final long INTERNAL_TRANS_REPL_INDEXES = -2;
-
- /**
- * The id of the transaction that executed this action.
- */
- private final long transactionId;
-
- /**
- * The action type.
- */
- private final int type;
-
- /**
- * Creates a new <code>Action</code>.
- *
- * @param transactionId
- * the id of the transaction that executed this action.
- * @param type
- * the action type.
- */
- Action(long transactionId, int type)
- {
- this.transactionId = transactionId;
- this.type = type;
- }
-
- /**
- * Returns the transaction id for this <code>Action</code>.
- *
- * @return the transaction id for this <code>Action</code>.
- */
- long getTransactionId()
- {
- return transactionId;
- }
-
- /**
- * Returns the action type.
- *
- * @return the action type.
- */
- int getType()
- {
- return type;
- }
-
- /**
- * Executes this action on the <code>index</code>.
- *
- * @param index
- * the index where to execute the action.
- * @throws IOException
- * if the action fails due to some I/O error in the index or
- * some other error.
- */
- public abstract void execute(MultiIndex index) throws IOException;
-
- /**
- * Executes the inverse operation of this action. That is, does an undo
- * of this action. This default implementation does nothing, but returns
- * silently.
- *
- * @param index
- * the index where to undo the action.
- * @throws IOException
- * if the action cannot be undone.
- */
- public void undo(MultiIndex index) throws IOException
- {
- }
-
- /**
- * Returns a <code>String</code> representation of this action that can
- * be written to the {@link RedoLog}.
- *
- * @return a <code>String</code> representation of this action.
- */
- @Override
- public abstract String toString();
-
- /**
- * Parses an line in the redo log and created an {@link Action}.
- *
- * @param line
- * the line from the redo log.
- * @return an <code>Action</code>.
- * @throws IllegalArgumentException
- * if the line is malformed.
- */
- static Action fromString(String line) throws IllegalArgumentException
- {
- int endTransIdx = line.indexOf(' ');
- if (endTransIdx == -1)
- {
- throw new IllegalArgumentException(line);
- }
- long transactionId;
- try
- {
- transactionId = Long.parseLong(line.substring(0, endTransIdx));
- }
- catch (NumberFormatException e)
- {
- throw new IllegalArgumentException(line);
- }
- int endActionIdx = line.indexOf(' ', endTransIdx + 1);
- if (endActionIdx == -1)
- {
- // action does not have arguments
- endActionIdx = line.length();
- }
- String actionLabel = line.substring(endTransIdx + 1, endActionIdx);
- String arguments = "";
- if (endActionIdx + 1 <= line.length())
- {
- arguments = line.substring(endActionIdx + 1);
- }
- Action a;
- if (actionLabel.equals(Action.ADD_NODE))
- {
- a = AddNode_.fromString(transactionId, arguments);
- }
- else if (actionLabel.equals(Action.ADD_INDEX))
- {
- a = AddIndex_.fromString(transactionId, arguments);
- }
- else if (actionLabel.equals(Action.COMMIT))
- {
- a = Commit_.fromString(transactionId, arguments);
- }
- else if (actionLabel.equals(Action.CREATE_INDEX))
- {
- a = CreateIndex_.fromString(transactionId, arguments);
- }
- else if (actionLabel.equals(Action.DELETE_INDEX))
- {
- a = DeleteIndex_.fromString(transactionId, arguments);
- }
- else if (actionLabel.equals(Action.DELETE_NODE))
- {
- a = DeleteNode_.fromString(transactionId, arguments);
- }
- else if (actionLabel.equals(Action.START))
- {
- a = Start_.fromString(transactionId, arguments);
- }
- else if (actionLabel.equals(Action.VOLATILE_COMMIT))
- {
- a = VolatileCommit_.fromString(transactionId, arguments);
- }
- else
- {
- throw new IllegalArgumentException(line);
- }
- return a;
- }
- }
-
- /**
- * Adds an index to the MultiIndex's active persistent index list.
- */
- private static class AddIndex_ extends Action
- {
-
- /**
- * The name of the index to add.
- */
- private String indexName;
-
- /**
- * Creates a new AddIndex action.
- *
- * @param transactionId
- * the id of the transaction that executes this action.
- * @param indexName
- * the name of the index to add, or <code>null</code> if an
- * index with a new name should be created.
- */
- AddIndex_(long transactionId, String indexName)
- {
- super(transactionId, Action.TYPE_ADD_INDEX);
- this.indexName = indexName;
- }
-
- /**
- * Creates a new AddIndex action.
- *
- * @param transactionId
- * the id of the transaction that executes this action.
- * @param arguments
- * the name of the index to add.
- * @return the AddIndex action.
- * @throws IllegalArgumentException
- * if the arguments are malformed.
- */
- static AddIndex_ fromString(long transactionId, String arguments)
- {
- return new AddIndex_(transactionId, arguments);
- }
-
- /**
- * Adds a sub index to <code>index</code>.
- *
- * @inheritDoc
- */
- @Override
- public void execute(MultiIndex index) throws IOException
- {
- PersistentIndex idx = index.getOrCreateIndex(indexName);
- if (!index.indexNames.contains(indexName))
- {
- index.indexNames.addName(indexName);
- }
- }
-
- /**
- * @inheritDoc
- */
- @Override
- public String toString()
- {
- StringBuffer logLine = new StringBuffer();
- logLine.append(Long.toString(getTransactionId()));
- logLine.append(' ');
- logLine.append(Action.ADD_INDEX);
- logLine.append(' ');
- logLine.append(indexName);
- return logLine.toString();
- }
- }
-
- /**
- * Adds a node to the index.
- */
- private static class AddNode_ extends Action
- {
-
- /**
- * The maximum length of a AddNode String.
- */
- private static final int ENTRY_LENGTH =
- Long.toString(Long.MAX_VALUE).length() + Action.ADD_NODE.length() + Constants.UUID_FORMATTED_LENGTH + 2;
-
- /**
- * The uuid of the node to add.
- */
- private final String uuid;
-
- /**
- * The document to add to the index, or <code>null</code> if not
- * available.
- */
- private Document doc;
-
- /**
- * Creates a new AddNode action.
- *
- * @param transactionId
- * the id of the transaction that executes this action.
- * @param uuid
- * the uuid of the node to add.
- */
- AddNode_(long transactionId, String uuid)
- {
- super(transactionId, Action.TYPE_ADD_NODE);
- this.uuid = uuid;
- }
-
- /**
- * Creates a new AddNode action.
- *
- * @param transactionId
- * the id of the transaction that executes this action.
- * @param doc
- * the document to add.
- */
- AddNode_(long transactionId, Document doc)
- {
- this(transactionId, doc.get(FieldNames.UUID));
- this.doc = doc;
- }
-
- /**
- * Creates a new AddNode action.
- *
- * @param transactionId
- * the id of the transaction that executes this action.
- * @param arguments
- * the arguments to this action. The uuid of the node to add
- * @return the AddNode action.
- * @throws IllegalArgumentException
- * if the arguments are malformed. Not a UUID.
- */
- static AddNode_ fromString(long transactionId, String arguments) throws IllegalArgumentException
- {
- // simple length check
- if (arguments.length() != Constants.UUID_FORMATTED_LENGTH)
- {
- throw new IllegalArgumentException("arguments is not a uuid");
- }
- return new AddNode_(transactionId, arguments);
- }
-
- /**
- * Adds a node to the index.
- *
- * @inheritDoc
- */
- @Override
- public void execute(MultiIndex index) throws IOException
- {
- if (doc == null)
- {
- try
- {
- doc = index.createDocument(uuid);
- }
- catch (RepositoryException e)
- {
- // node does not exist anymore
- log.debug(e.getMessage());
- }
- }
- if (doc != null)
- {
- index.volatileIndex.addDocuments(new Document[]{doc});
- }
- }
-
- /**
- * @inheritDoc
- */
- @Override
- public String toString()
- {
- StringBuffer logLine = new StringBuffer(ENTRY_LENGTH);
- logLine.append(Long.toString(getTransactionId()));
- logLine.append(' ');
- logLine.append(Action.ADD_NODE);
- logLine.append(' ');
- logLine.append(uuid);
- return logLine.toString();
- }
- }
-
- /**
- * Commits a transaction.
- */
- private static class Commit_ extends Action
- {
-
- /**
- * Creates a new Commit action.
- *
- * @param transactionId
- * the id of the transaction that is committed.
- */
- Commit_(long transactionId)
- {
- super(transactionId, Action.TYPE_COMMIT);
- }
-
- /**
- * Creates a new Commit action.
- *
- * @param transactionId
- * the id of the transaction that executes this action.
- * @param arguments
- * ignored by this method.
- * @return the Commit action.
- */
- static Commit_ fromString(long transactionId, String arguments)
- {
- return new Commit_(transactionId);
- }
-
- /**
- * Touches the last flush time (sets it to the current time).
- *
- * @inheritDoc
- */
- @Override
- public void execute(MultiIndex index) throws IOException
- {
- index.lastFlushTime = System.currentTimeMillis();
- }
-
- /**
- * @inheritDoc
- */
- @Override
- public String toString()
- {
- return Long.toString(getTransactionId()) + ' ' + Action.COMMIT;
- }
- }
-
- /**
- * Creates an new sub index but does not add it to the active persistent
- * index list.
- */
- private static class CreateIndex_ extends Action
- {
-
- /**
- * The name of the index to add.
- */
- private String indexName;
-
- /**
- * Creates a new CreateIndex action.
- *
- * @param transactionId
- * the id of the transaction that executes this action.
- * @param indexName
- * the name of the index to add, or <code>null</code> if an
- * index with a new name should be created.
- */
- CreateIndex_(long transactionId, String indexName)
- {
- super(transactionId, Action.TYPE_CREATE_INDEX);
- this.indexName = indexName;
- }
-
- /**
- * Creates a new CreateIndex action.
- *
- * @param transactionId
- * the id of the transaction that executes this action.
- * @param arguments
- * the name of the index to create.
- * @return the AddIndex action.
- * @throws IllegalArgumentException
- * if the arguments are malformed.
- */
- static CreateIndex_ fromString(long transactionId, String arguments)
- {
- // when created from String, this action is executed as redo action
- return new CreateIndex_(transactionId, arguments);
- }
-
- /**
- * Creates a new index.
- *
- * @inheritDoc
- */
- @Override
- public void execute(MultiIndex index) throws IOException
- {
- PersistentIndex idx = index.getOrCreateIndex(indexName);
- indexName = idx.getName();
- }
-
- /**
- * @inheritDoc
- */
- @Override
- public void undo(MultiIndex index) throws IOException
- {
- if (index.hasIndex(indexName))
- {
- PersistentIndex idx = index.getOrCreateIndex(indexName);
- idx.close();
- index.deleteIndex(idx);
- }
- }
-
- /**
- * @inheritDoc
- */
- @Override
- public String toString()
- {
- StringBuffer logLine = new StringBuffer();
- logLine.append(Long.toString(getTransactionId()));
- logLine.append(' ');
- logLine.append(Action.CREATE_INDEX);
- logLine.append(' ');
- logLine.append(indexName);
- return logLine.toString();
- }
-
- /**
- * Returns the index name that has been created. If this method is
- * called before {@link #execute(MultiIndex)} it will return
- * <code>null</code>.
- *
- * @return the name of the index that has been created.
- */
- String getIndexName()
- {
- return indexName;
- }
- }
-
- /**
- * Closes and deletes an index that is no longer in use.
- */
- private static class DeleteIndex_ extends Action
- {
-
- /**
- * The name of the index to add.
- */
- private String indexName;
-
- /**
- * Creates a new DeleteIndex action.
- *
- * @param transactionId
- * the id of the transaction that executes this action.
- * @param indexName
- * the name of the index to delete.
- */
- DeleteIndex_(long transactionId, String indexName)
- {
- super(transactionId, Action.TYPE_DELETE_INDEX);
- this.indexName = indexName;
- }
-
- /**
- * Creates a new DeleteIndex action.
- *
- * @param transactionId
- * the id of the transaction that executes this action.
- * @param arguments
- * the name of the index to delete.
- * @return the DeleteIndex action.
- * @throws IllegalArgumentException
- * if the arguments are malformed.
- */
- static DeleteIndex_ fromString(long transactionId, String arguments)
- {
- return new DeleteIndex_(transactionId, arguments);
- }
-
- /**
- * Removes a sub index from <code>index</code>.
- *
- * @inheritDoc
- */
- @Override
- public void execute(MultiIndex index) throws IOException
- {
- // get index if it exists
- for (Iterator it = index.indexes.iterator(); it.hasNext();)
- {
- PersistentIndex idx = (PersistentIndex)it.next();
- if (idx.getName().equals(indexName))
- {
- idx.close();
- index.deleteIndex(idx);
- break;
- }
- }
- }
-
- /**
- * @inheritDoc
- */
- @Override
- public String toString()
- {
- StringBuffer logLine = new StringBuffer();
- logLine.append(Long.toString(getTransactionId()));
- logLine.append(' ');
- logLine.append(Action.DELETE_INDEX);
- logLine.append(' ');
- logLine.append(indexName);
- return logLine.toString();
- }
- }
-
- /**
- * Deletes a node from the index.
- */
- private static class DeleteNode_ extends Action
- {
-
- /**
- * The maximum length of a DeleteNode String.
- */
- private static final int ENTRY_LENGTH =
- Long.toString(Long.MAX_VALUE).length() + Action.DELETE_NODE.length() + Constants.UUID_FORMATTED_LENGTH + 2;
-
- /**
- * The uuid of the node to remove.
- */
- private final String uuid;
-
- /**
- * Creates a new DeleteNode action.
- *
- * @param transactionId
- * the id of the transaction that executes this action.
- * @param uuid
- * the uuid of the node to delete.
- */
- DeleteNode_(long transactionId, String uuid)
- {
- super(transactionId, Action.TYPE_DELETE_NODE);
- this.uuid = uuid;
- }
-
- /**
- * Creates a new DeleteNode action.
- *
- * @param transactionId
- * the id of the transaction that executes this action.
- * @param arguments
- * the uuid of the node to delete.
- * @return the DeleteNode action.
- * @throws IllegalArgumentException
- * if the arguments are malformed. Not a UUID.
- */
- static DeleteNode_ fromString(long transactionId, String arguments)
- {
- // simple length check
- if (arguments.length() != Constants.UUID_FORMATTED_LENGTH)
- {
- throw new IllegalArgumentException("arguments is not a uuid");
- }
- return new DeleteNode_(transactionId, arguments);
- }
-
- /**
- * Deletes a node from the index.
- *
- * @inheritDoc
- */
- @Override
- public void execute(MultiIndex index) throws IOException
- {
- String uuidString = uuid.toString();
- // check if indexing queue is still working on
- // this node from a previous update
- Document doc = index.indexingQueue.removeDocument(uuidString);
- if (doc != null)
- {
- Util.disposeDocument(doc);
- }
- Term idTerm = new Term(FieldNames.UUID, uuidString);
- // if the document cannot be deleted from the volatile index
- // delete it from one of the persistent indexes.
- int num = index.volatileIndex.removeDocument(idTerm);
- if (num == 0)
- {
- for (int i = index.indexes.size() - 1; i >= 0; i--)
- {
- // only look in registered indexes
- PersistentIndex idx = (PersistentIndex)index.indexes.get(i);
- if (index.indexNames.contains(idx.getName()))
- {
- num = idx.removeDocument(idTerm);
- if (num > 0)
- {
- return;
- }
- }
- }
- }
- }
-
- /**
- * @inheritDoc
- */
- @Override
- public String toString()
- {
- StringBuffer logLine = new StringBuffer(ENTRY_LENGTH);
- logLine.append(Long.toString(getTransactionId()));
- logLine.append(' ');
- logLine.append(Action.DELETE_NODE);
- logLine.append(' ');
- logLine.append(uuid);
- return logLine.toString();
- }
- }
-
- /**
- * Starts a transaction.
- */
- private static class Start_ extends Action
- {
-
- /**
- * Creates a new Start transaction action.
- *
- * @param transactionId
- * the id of the transaction that started.
- */
- Start_(long transactionId)
- {
- super(transactionId, Action.TYPE_START);
- }
-
- /**
- * Creates a new Start action.
- *
- * @param transactionId
- * the id of the transaction that executes this action.
- * @param arguments
- * ignored by this method.
- * @return the Start action.
- */
- static Start_ fromString(long transactionId, String arguments)
- {
- return new Start_(transactionId);
- }
-
- /**
- * Sets the current transaction id on <code>index</code>.
- *
- * @inheritDoc
- */
- @Override
- public void execute(MultiIndex index) throws IOException
- {
- index.currentTransactionId = getTransactionId();
- }
-
- /**
- * @inheritDoc
- */
- @Override
- public String toString()
- {
- return Long.toString(getTransactionId()) + ' ' + Action.START;
- }
- }
-
- /**
- * Commits the volatile index to disk.
- */
- private static class VolatileCommit_ extends Action
- {
-
- /**
- * The name of the target index to commit to.
- */
- private final String targetIndex;
-
- /**
- * Creates a new VolatileCommit action.
- *
- * @param transactionId
- * the id of the transaction that executes this action.
- */
- VolatileCommit_(long transactionId, String targetIndex)
- {
- super(transactionId, Action.TYPE_VOLATILE_COMMIT);
- this.targetIndex = targetIndex;
- }
-
- /**
- * Creates a new VolatileCommit action.
- *
- * @param transactionId
- * the id of the transaction that executes this action.
- * @param arguments
- * ignored by this implementation.
- * @return the VolatileCommit action.
- */
- static VolatileCommit_ fromString(long transactionId, String arguments)
- {
- return new VolatileCommit_(transactionId, arguments);
- }
-
- /**
- * Commits the volatile index to disk.
- *
- * @inheritDoc
- */
- @Override
- public void execute(MultiIndex index) throws IOException
- {
- VolatileIndex volatileIndex = index.getVolatileIndex();
- PersistentIndex persistentIndex = index.getOrCreateIndex(targetIndex);
- persistentIndex.copyIndex(volatileIndex);
- index.resetVolatileIndex();
- }
-
- /**
- * @inheritDoc
- */
- @Override
- public String toString()
- {
- StringBuffer logLine = new StringBuffer();
- logLine.append(Long.toString(getTransactionId()));
- logLine.append(' ');
- logLine.append(Action.VOLATILE_COMMIT);
- logLine.append(' ');
- logLine.append(targetIndex);
- return logLine.toString();
- }
- }
-
- /**
* @see org.exoplatform.services.jcr.impl.core.query.IndexerIoModeListener#onChangeMode(org.exoplatform.services.jcr.impl.core.query.IndexerIoMode)
*/
public void onChangeMode(IndexerIoMode mode)
@@ -2626,7 +1658,6 @@
// try to stop merger in safe way
flushTask.cancel();
FLUSH_TIMER.purge();
- this.redoLog = null;
}
/**
@@ -2644,21 +1675,12 @@
releaseMultiReader();
}
- this.redoLog = new RedoLog(indexDir);
- redoLogApplied = redoLog.hasEntries();
-
- // run recovery
- Recovery.run(this, redoLog);
-
// enqueue unused segments for deletion
enqueueUnusedSegments();
attemptDelete();
// now that we are ready, start index merger
- if (redoLogApplied)
- {
- flush();
- }
+ flush();
if (indexNames.size() > 0)
{
@@ -2749,4 +1771,10 @@
}
}
}
+
+ @Deprecated
+ public boolean getRedoLogApplied()
+ {
+ return false;
+ }
}
Deleted: jcr/branches/1.14-CNK/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/Recovery.java
===================================================================
--- jcr/branches/1.14-CNK/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/Recovery.java 2010-10-08 12:39:11 UTC (rev 3263)
+++ jcr/branches/1.14-CNK/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/Recovery.java 2010-10-08 13:03:55 UTC (rev 3264)
@@ -1,203 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.exoplatform.services.jcr.impl.core.query.lucene;
-
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import java.io.IOException;
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Set;
-
-/**
- * Implements the recovery process.
- */
-class Recovery
-{
-
- /**
- * The logger instance for this class.
- */
- private static final Logger log = LoggerFactory.getLogger("exo.jcr.component.core.Recovery");
-
- /**
- * The MultiIndex where to run the recovery on.
- */
- private final MultiIndex index;
-
- /**
- * The redo redoLog.
- */
- private final RedoLog redoLog;
-
- /**
- * The ids of the uncommitted transactions. Set of Integer objects.
- */
- private final Set losers = new HashSet();
-
- /**
- * Creates a new Recovery instance.
- *
- * @param index the MultiIndex to recover.
- * @param redoLog the redo redoLog.
- */
- private Recovery(MultiIndex index, RedoLog redoLog)
- {
- this.index = index;
- this.redoLog = redoLog;
- }
-
- /**
- * Runs a recovery on <code>index</code> if <code>redoLog</code> contains
- * log entries.
- * <p/>
- * If recovery succeeds the <code>index</code> is flushed and the redo log
- * is cleared. That is, the <code>index</code> is stable.<br/>
- * If recovery fails an IOException is thrown, and the redo log will not
- * be modified. The recovery process can then be executed again, after
- * fixing the cause of the IOException (e.g. disk full).
- *
- * @param index the index to recover.
- * @param redoLog the redo log.
- * @throws IOException if the recovery fails.
- */
- static void run(MultiIndex index, RedoLog redoLog) throws IOException
- {
- if (!redoLog.hasEntries())
- {
- log.debug("RedoLog is empty, no recovery needed.");
- return;
- }
- log.info("Found uncommitted redo log. Applying changes now...");
- Recovery r = new Recovery(index, redoLog);
- r.run();
- log.info("Redo changes applied.");
- }
-
- /**
- * Runs the recovery process.
- *
- * @throws IOException if the recovery fails.
- */
- private void run() throws IOException
- {
- List actions = redoLog.getActions();
-
- // find loser transactions
- for (Iterator it = actions.iterator(); it.hasNext();)
- {
- MultiIndex.Action a = (MultiIndex.Action)it.next();
- if (a.getType() == MultiIndex.Action.TYPE_START)
- {
- losers.add(new Long(a.getTransactionId()));
- }
- else if (a.getType() == MultiIndex.Action.TYPE_COMMIT)
- {
- losers.remove(new Long(a.getTransactionId()));
- }
- }
-
- // find last volatile commit without changes from a loser
- int lastSafeVolatileCommit = -1;
- Set transactionIds = new HashSet();
- for (int i = 0; i < actions.size(); i++)
- {
- MultiIndex.Action a = (MultiIndex.Action)actions.get(i);
- if (a.getType() == MultiIndex.Action.TYPE_COMMIT)
- {
- transactionIds.clear();
- }
- else if (a.getType() == MultiIndex.Action.TYPE_VOLATILE_COMMIT)
- {
- transactionIds.retainAll(losers);
- // check if transactionIds contains losers
- if (transactionIds.size() > 0)
- {
- // found dirty volatile commit
- break;
- }
- else
- {
- lastSafeVolatileCommit = i;
- }
- }
- else
- {
- transactionIds.add(new Long(a.getTransactionId()));
- }
- }
-
- // delete dirty indexes
- for (int i = lastSafeVolatileCommit + 1; i < actions.size(); i++)
- {
- MultiIndex.Action a = (MultiIndex.Action)actions.get(i);
- if (a.getType() == MultiIndex.Action.TYPE_CREATE_INDEX)
- {
- a.undo(index);
- }
- }
-
- // replay actions up to last safe volatile commit
- // ignore add node actions, they are included in volatile commits
- for (int i = 0; i < actions.size() && i <= lastSafeVolatileCommit; i++)
- {
- MultiIndex.Action a = (MultiIndex.Action)actions.get(i);
- switch (a.getType())
- {
- case MultiIndex.Action.TYPE_ADD_INDEX :
- case MultiIndex.Action.TYPE_CREATE_INDEX :
- case MultiIndex.Action.TYPE_DELETE_INDEX :
- case MultiIndex.Action.TYPE_DELETE_NODE :
- // ignore actions by the index merger.
- // the previously created index of a merge has been
- // deleted because it was considered dirty.
- // we are conservative here and let the index merger do
- // its work again.
- if (a.getTransactionId() == MultiIndex.Action.INTERNAL_TRANS_REPL_INDEXES)
- {
- continue;
- }
- a.execute(index);
- }
- }
-
- // now replay the rest until we encounter a loser transaction
- for (int i = lastSafeVolatileCommit + 1; i < actions.size(); i++)
- {
- MultiIndex.Action a = (MultiIndex.Action)actions.get(i);
- if (losers.contains(new Long(a.getTransactionId())))
- {
- break;
- }
- else
- {
- // ignore actions by the index merger.
- if (a.getTransactionId() == MultiIndex.Action.INTERNAL_TRANS_REPL_INDEXES)
- {
- continue;
- }
- a.execute(index);
- }
- }
-
- // now we are consistent again -> flush
- index.flush();
- index.releaseMultiReader();
- }
-}
Deleted: jcr/branches/1.14-CNK/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/RedoLog.java
===================================================================
--- jcr/branches/1.14-CNK/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/RedoLog.java 2010-10-08 12:39:11 UTC (rev 3263)
+++ jcr/branches/1.14-CNK/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/RedoLog.java 2010-10-08 13:03:55 UTC (rev 3264)
@@ -1,291 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.exoplatform.services.jcr.impl.core.query.lucene;
-
-import org.apache.lucene.store.Directory;
-import org.exoplatform.services.jcr.impl.core.query.lucene.directory.IndexInputStream;
-import org.exoplatform.services.jcr.impl.core.query.lucene.directory.IndexOutputStream;
-import org.exoplatform.services.jcr.impl.util.SecurityHelper;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import java.io.BufferedReader;
-import java.io.BufferedWriter;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.InputStreamReader;
-import java.io.OutputStream;
-import java.io.OutputStreamWriter;
-import java.io.Writer;
-import java.security.PrivilegedExceptionAction;
-import java.util.ArrayList;
-import java.util.List;
-
-/**
- * Implements a redo log for changes that have not been committed to disk. While
- * nodes are added to and removed from the volatile index (held in memory) a
- * redo log is written to keep track of the changes. In case the Jackrabbit
- * process terminates unexpected the redo log is applied when Jackrabbit is
- * restarted the next time.
- * <p/>
- * This class is not thread-safe.
- */
-class RedoLog
-{
-
- /**
- * Logger instance for this class
- */
- private static final Logger log = LoggerFactory.getLogger("exo.jcr.component.core.RedoLog");
-
- /**
- * Default name of the redo log file
- */
- private static final String REDO_LOG = "redo.log";
-
- /**
- * Implements a {@link ActionCollector} that counts all entries and sets
- * {@link #entryCount}.
- */
- private final ActionCollector ENTRY_COUNTER = new ActionCollector()
- {
- public void collect(MultiIndex.Action a)
- {
- entryCount++;
- }
- };
-
- /**
- * The directory where the log file is stored.
- */
- private final Directory dir;
-
- /**
- * The number of log entries in the log file
- */
- private int entryCount = 0;
-
- /**
- * Writer to the log file
- */
- private Writer out;
-
- /**
- * Creates a new <code>RedoLog</code> instance, which stores its log in the
- * given directory.
- *
- * @param dir the directory where the redo log file is located.
- * @throws IOException if an error occurs while reading the redo log.
- */
- RedoLog(Directory dir) throws IOException
- {
- this.dir = dir;
- read(ENTRY_COUNTER);
- }
-
- /**
- * Returns <code>true</code> if this redo log contains any entries,
- * <code>false</code> otherwise.
- * @return <code>true</code> if this redo log contains any entries,
- * <code>false</code> otherwise.
- */
- boolean hasEntries()
- {
- return entryCount > 0;
- }
-
- /**
- * Returns the number of entries in this redo log.
- * @return the number of entries in this redo log.
- */
- int getSize()
- {
- return entryCount;
- }
-
- /**
- * Returns a List with all {@link MultiIndex.Action} instances in the
- * redo log.
- *
- * @return an List with all {@link MultiIndex.Action} instances in the
- * redo log.
- * @throws IOException if an error occurs while reading from the redo log.
- */
- List getActions() throws IOException
- {
- final List actions = new ArrayList();
- read(new ActionCollector()
- {
- public void collect(MultiIndex.Action a)
- {
- actions.add(a);
- }
- });
- return actions;
- }
-
- /**
- * Appends an action to the log.
- *
- * @param action the action to append.
- * @throws IOException if the node cannot be written to the redo
- * log.
- */
- void append(final MultiIndex.Action action) throws IOException
- {
- SecurityHelper.doPriviledgedIOExceptionAction(new PrivilegedExceptionAction<Object>()
- {
- public Object run() throws Exception
- {
- initOut();
- out.write(action.toString() + "\n");
- entryCount++;
- return null;
- }
- });
- }
-
- /**
- * Flushes all pending writes to the underlying file.
- * @throws IOException if an error occurs while writing.
- */
- void flush() throws IOException
- {
- SecurityHelper.doPriviledgedIOExceptionAction(new PrivilegedExceptionAction<Object>()
- {
- public Object run() throws Exception
- {
- if (out != null)
- {
- out.flush();
- }
- return null;
- }
- });
- }
-
- /**
- * Clears the redo log.
- * @throws IOException if the redo log cannot be cleared.
- */
- void clear() throws IOException
- {
- SecurityHelper.doPriviledgedIOExceptionAction(new PrivilegedExceptionAction<Object>()
- {
- public Object run() throws Exception
- {
- if (out != null)
- {
- out.close();
- out = null;
- }
- if (dir.fileExists(REDO_LOG))
- {
- dir.deleteFile(REDO_LOG);
- }
- entryCount = 0;
- return null;
- }
- });
- }
-
- /**
- * Initializes the {@link #out} stream if it is not yet set.
- * @throws IOException if an error occurs while creating the
- * output stream.
- */
- private void initOut() throws IOException
- {
- SecurityHelper.doPriviledgedIOExceptionAction(new PrivilegedExceptionAction<Object>()
- {
- public Object run() throws Exception
- {
- if (out == null)
- {
- OutputStream os = new IndexOutputStream(dir.createOutput(REDO_LOG));
- out = new BufferedWriter(new OutputStreamWriter(os));
- }
- return null;
- }
- });
- }
-
- /**
- * Reads the log file and calls back {@link RedoLog.ActionCollector}.
- *
- * @param collector called back for each {@link MultiIndex.Action} read.
- * @throws IOException if an error occurs while reading from the
- * log file.
- */
- private void read(final ActionCollector collector) throws IOException
- {
- SecurityHelper.doPriviledgedIOExceptionAction(new PrivilegedExceptionAction<Object>()
- {
- public Object run() throws Exception
- {
- if (!dir.fileExists(REDO_LOG))
- {
- return null;
- }
- InputStream in = new IndexInputStream(dir.openInput(REDO_LOG));
- try
- {
- BufferedReader reader = new BufferedReader(new InputStreamReader(in));
- String line;
- while ((line = reader.readLine()) != null)
- {
- try
- {
- collector.collect(MultiIndex.Action.fromString(line));
- }
- catch (IllegalArgumentException e)
- {
- log.warn("Malformed redo entry: " + e.getMessage());
- }
- }
- }
- finally
- {
- if (in != null)
- {
- try
- {
- in.close();
- }
- catch (IOException e)
- {
- log.warn("Exception while closing redo log: " + e.toString());
- }
- }
- }
- return null;
- }
- });
- }
-
- //-----------------------< internal >---------------------------------------
-
- /**
- * Helper interface to collect Actions read from the redo log.
- */
- interface ActionCollector
- {
-
- /** Called when an action is created */
- void collect(MultiIndex.Action action);
- }
-}
More information about the exo-jcr-commits
mailing list