Author: tolusha
Date: 2011-02-07 13:54:11 -0500 (Mon, 07 Feb 2011)
New Revision: 3936
Modified:
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/MultiIndex.java
Log:
EXOJCR-1184: Improve the re-indexing mechanism to take advantage of multi-cores: wrap
addShutDownHook in privileged block
Modified:
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/MultiIndex.java
===================================================================
---
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/MultiIndex.java 2011-02-07
17:56:22 UTC (rev 3935)
+++
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/MultiIndex.java 2011-02-07
18:54:11 UTC (rev 3936)
@@ -345,13 +345,21 @@
setReadWrite();
}
this.indexNames.setMultiIndex(this);
+
// Add a hook that will stop the threads if they are still running
- Runtime.getRuntime().addShutdownHook(new Thread()
+ SecurityHelper.doPrivilegedAction(new PrivilegedAction<Object>()
{
- @Override
- public void run()
+ public Void run()
{
- stopped = true;
+ Runtime.getRuntime().addShutdownHook(new Thread()
+ {
+ @Override
+ public void run()
+ {
+ stopped = true;
+ }
+ });
+ return null;
}
});
}
@@ -425,15 +433,13 @@
executeAndLog(new Start(Action.INTERNAL_TRANSACTION));
// NodeData rootState = (NodeData) stateMgr.getItemData(rootId);
-
// check if we have deal with JDBC indexing mechanism
Indexable indexableComponent =
(Indexable)handler.getContext().getContainer().getComponent(Indexable.class);
+ long count = createIndex(indexingTree.getIndexingRoot(), stateMgr);
// long count =
// indexableComponent == null ?
createIndex(indexingTree.getIndexingRoot(), stateMgr) : createIndex(
// indexableComponent, indexingTree.getIndexingRoot());
- long count = createIndex(indexingTree.getIndexingRoot(), stateMgr);
-
executeAndLog(new Commit(getTransactionId()));
log.info("Created initial index for {} nodes", new Long(count));
releaseMultiReader();
@@ -1527,7 +1533,7 @@
}
/**
- * Recursively creates an index starting with the NodeState
+ * Creates an index.
* <code>node</code>.
*
* @param indexableComponent
@@ -1566,7 +1572,7 @@
continue;
}
- executeAndLog(new AddNode(getTransactionId(), node));
+ executeAndLog(new AddNode(getTransactionId(), node, true));
if (++count % 100 == 0)
{
@@ -2103,6 +2109,9 @@
*/
private Document doc;
+ /**
+ * Indicates if need to execute command in synchronize mode.
+ */
private boolean synch;
/**
@@ -2127,9 +2136,11 @@
* Creates a new AddNode action.
*
* @param transactionId
- * the id of the transaction that executes this action.
+ * the id of the transaction that executes this action
* @param uuid
- * the uuid of the node to add.
+ * the uuid of the node to add
+ * @param synch
+ * indicates if need to execute command in synchronize mode
*/
AddNode(long transactionId, String uuid, boolean synch)
{
@@ -2145,10 +2156,12 @@
* the id of the transaction that executes this action.
* @param uuid
* the uuid of the node to add.
+ * @param synch
+ * indicates if need to execute command in synchronize mode
*/
- AddNode(long transactionId, NodeDataIndexing node)
+ AddNode(long transactionId, NodeDataIndexing node, boolean synch)
{
- this(transactionId, node.getIdentifier());
+ this(transactionId, node.getIdentifier(), synch);
this.node = node;
}
@@ -3014,7 +3027,8 @@
* Launches the indexing
* @param asynchronous indicates whether or not the current thread needs to wait
until the
* end of the indexing
- * @return the total amount of nodes that have been indexed.
<code>-1</code> in case of an
+
+ * @return the total amount of nodes that have been indexed.
<code>-1</code> in case of an
* asynchronous indexing
* @throws IOException
* if an error occurs while writing to the index.
Show replies by date