Author: tolusha
Date: 2011-02-18 06:11:00 -0500 (Fri, 18 Feb 2011)
New Revision: 3991
Modified:
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/backup/Suspendable.java
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/IndexRecovery.java
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/IndexRecoveryImpl.java
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/SearchManager.java
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/dataflow/persistent/CacheableWorkspaceDataManager.java
Log:
EXOJCR-1193: Index retrieval from coordinator node
Modified:
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/backup/Suspendable.java
===================================================================
---
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/backup/Suspendable.java 2011-02-18
10:09:17 UTC (rev 3990)
+++
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/backup/Suspendable.java 2011-02-18
11:11:00 UTC (rev 3991)
@@ -29,13 +29,13 @@
*
* @throws SuspendException of error occurred
*/
- void suspend(boolean isSuspendCoordinatorOnly) throws SuspendException;
+ void suspend() throws SuspendException;
/**
* Resume component.
*
* @throws ResumeException of error occurred
*/
- void resume(boolean isResumeCoordinatorOnly) throws ResumeException;
+ void resume() throws ResumeException;
}
Modified:
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/IndexRecovery.java
===================================================================
---
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/IndexRecovery.java 2011-02-18
10:09:17 UTC (rev 3990)
+++
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/IndexRecovery.java 2011-02-18
11:11:00 UTC (rev 3991)
@@ -31,7 +31,18 @@
*/
public interface IndexRecovery
{
+
/**
+ * Switch index between RO/RW states.
+ *
+ * @param isReadOnly
+ * boolean, indicates if need to switch index to RO or RW mode
+ * @throws RepositoryException
+ * if any exception occurred
+ */
+ public void setIndexReadOnly(boolean isReadOnly) throws RepositoryException;
+
+ /**
* Get list of relative paths of all files from index directory.
*
* @return List
Modified:
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/IndexRecoveryImpl.java
===================================================================
---
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/IndexRecoveryImpl.java 2011-02-18
10:09:17 UTC (rev 3990)
+++
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/IndexRecoveryImpl.java 2011-02-18
11:11:00 UTC (rev 3991)
@@ -17,6 +17,7 @@
package org.exoplatform.services.jcr.impl.core.query;
import org.exoplatform.commons.utils.PrivilegedFileHelper;
+import org.exoplatform.services.jcr.config.RepositoryConfigurationException;
import org.exoplatform.services.jcr.impl.util.io.DirectoryHelper;
import org.exoplatform.services.rpc.RPCException;
import org.exoplatform.services.rpc.RPCService;
@@ -64,18 +65,45 @@
private RemoteCommand getIndexFile;
/**
+ * Remote command to switch index between RO/RW state.
+ */
+ private RemoteCommand setReadOnly;
+
+ /**
* Constructor IndexRetrieveImpl.
+ *
+ * @throws RepositoryConfigurationException
*/
- public IndexRecoveryImpl(RPCService rpcService, final String wsId, final boolean
isSystem, final File indexDirectory)
+ public IndexRecoveryImpl(RPCService rpcService, final SearchManager searchManager)
+ throws RepositoryConfigurationException
{
this.rpcService = rpcService;
+ final String commandSuffix = searchManager.getWsId() + "-" +
(searchManager.parentSearchManager == null);
+ final File indexDirectory = searchManager.getIndexDirectory();
+
+ setReadOnly = rpcService.registerCommand(new RemoteCommand()
+ {
+ public String getId()
+ {
+ return
"org.exoplatform.services.jcr.impl.core.query.IndexRecoveryImpl-setReadOnly-" +
commandSuffix;
+ }
+
+ public Serializable execute(Serializable[] args) throws Throwable
+ {
+ boolean isReadOnly = (Boolean)args[0];
+
+ // TODO searchManager.setReadOnly(isReadOnly);
+
+ return null;
+ }
+ });
+
getIndexList = rpcService.registerCommand(new RemoteCommand()
{
public String getId()
{
- return
"org.exoplatform.services.jcr.impl.core.query.IndexRetrieveImpl-getIndexList-" +
wsId + "-"
- + isSystem;
+ return
"org.exoplatform.services.jcr.impl.core.query.IndexRecoveryImpl-getIndexList-" +
commandSuffix;
}
public Serializable execute(Serializable[] args) throws Throwable
@@ -99,8 +127,7 @@
{
public String getId()
{
- return
"org.exoplatform.services.jcr.impl.core.query.IndexRetrieveImpl-getIndexFile-" +
wsId + "-"
- + isSystem;
+ return
"org.exoplatform.services.jcr.impl.core.query.IndexRecoveryImpl-getIndexFile-" +
commandSuffix;
}
public Serializable execute(Serializable[] args) throws Throwable
@@ -151,6 +178,27 @@
/**
* {@inheritDoc}
*/
+ public void setIndexReadOnly(boolean isReadOnly) throws RepositoryException
+ {
+ try
+ {
+ rpcService.executeCommandOnCoordinator(setReadOnly, true, isReadOnly);
+
+ // TODO failover
+ }
+ catch (SecurityException e)
+ {
+ throw new RepositoryException(e);
+ }
+ catch (RPCException e)
+ {
+ throw new RepositoryException(e);
+ }
+ }
+
+ /**
+ * {@inheritDoc}
+ */
public InputStream getIndexFile(String filePath) throws RepositoryException
{
try
Modified:
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/SearchManager.java
===================================================================
---
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/SearchManager.java 2011-02-18
10:09:17 UTC (rev 3990)
+++
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/SearchManager.java 2011-02-18
11:11:00 UTC (rev 3991)
@@ -688,9 +688,7 @@
throw new RepositoryConfigurationException(e);
}
- IndexRecovery indexRecovery =
- rpcService == null ? null : new IndexRecoveryImpl(rpcService, getWsId(),
parentHandler == null,
- getIndexDirectory());
+ IndexRecovery indexRecovery = rpcService == null ? null : new
IndexRecoveryImpl(rpcService, this);
QueryHandlerContext context =
new QueryHandlerContext(container, itemMgr, indexingTree, nodeTypeDataManager,
nsReg, parentHandler,
@@ -980,7 +978,7 @@
/**
* {@inheritDoc}
*/
- public void suspend(boolean isSuspendCoordinatorOnly) throws SuspendException
+ public void suspend() throws SuspendException
{
isResponsibleForResuming = true;
@@ -988,14 +986,7 @@
{
try
{
- if (isSuspendCoordinatorOnly)
- {
- rpcService.executeCommandOnCoordinator(suspend, true);
- }
- else
- {
- rpcService.executeCommandOnAllNodes(suspend, true);
- }
+ rpcService.executeCommandOnAllNodes(suspend, true);
}
catch (SecurityException e)
{
@@ -1015,20 +1006,13 @@
/**
* {@inheritDoc}
*/
- public void resume(boolean isResumeCoordinatorOnly) throws ResumeException
+ public void resume() throws ResumeException
{
if (rpcService != null)
{
try
{
- if (isResumeCoordinatorOnly)
- {
- rpcService.executeCommandOnCoordinator(resume, true);
- }
- else
- {
- rpcService.executeCommandOnAllNodes(resume, true);
- }
+ rpcService.executeCommandOnAllNodes(resume, true);
}
catch (SecurityException e)
{
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-18
10:09:17 UTC (rev 3990)
+++
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/MultiIndex.java 2011-02-18
11:11:00 UTC (rev 3991)
@@ -28,9 +28,8 @@
import org.exoplatform.services.jcr.datamodel.NodeData;
import org.exoplatform.services.jcr.datamodel.NodeDataIndexing;
import org.exoplatform.services.jcr.impl.Constants;
-import org.exoplatform.services.jcr.impl.backup.ResumeException;
import org.exoplatform.services.jcr.impl.backup.SuspendException;
-import org.exoplatform.services.jcr.impl.backup.Suspendable;
+import org.exoplatform.services.jcr.impl.core.query.IndexRecovery;
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;
@@ -3350,23 +3349,13 @@
private void recoveryIndexFromCoordinator() throws FileNotFoundException,
RepositoryException, IOException,
SuspendException
{
- List<Suspendable> suspendableComponents =
-
handler.getContext().getContainer().getComponentInstancesOfType(Suspendable.class);
-
- // the list of components to resume
- List<Suspendable> resumeComponents = new ArrayList<Suspendable>();
-
try
{
- // suspend all components
- for (Suspendable component : suspendableComponents)
- {
- component.suspend(true);
- resumeComponents.add(component);
- }
+ IndexRecovery indexRecovery = handler.getContext().getIndexRecovery();
+ indexRecovery.setIndexReadOnly(true);
File indexDirectory = new File(handler.getContext().getIndexDirectory());
- for (String filePath : handler.getContext().getIndexRecovery().getIndexList())
+ for (String filePath : indexRecovery.getIndexList())
{
File indexFile = new File(indexDirectory, filePath);
if (!PrivilegedFileHelper.exists(indexFile.getParentFile()))
@@ -3375,7 +3364,7 @@
}
// transfer file
- InputStream in =
handler.getContext().getIndexRecovery().getIndexFile(filePath);
+ InputStream in = indexRecovery.getIndexFile(filePath);
OutputStream out = PrivilegedFileHelper.fileOutputStream(indexFile);
try
{
@@ -3399,21 +3388,12 @@
out.close();
}
}
+
+ indexRecovery.setIndexReadOnly(false);
}
}
finally
{
- for (Suspendable component : resumeComponents)
- {
- try
- {
- component.resume(true);
- }
- catch (ResumeException e)
- {
- log.error("Can't resume component", e);
- }
- }
}
}
}
\ No newline at end of file
Modified:
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/CacheableWorkspaceDataManager.java
===================================================================
---
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/CacheableWorkspaceDataManager.java 2011-02-18
10:09:17 UTC (rev 3990)
+++
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/CacheableWorkspaceDataManager.java 2011-02-18
11:11:00 UTC (rev 3991)
@@ -1095,7 +1095,7 @@
/**
* {@inheritDoc}
*/
- public void suspend(boolean isSuspendCoordinatorOnly) throws SuspendException
+ public void suspend() throws SuspendException
{
isResponsibleForResuming = true;
@@ -1103,14 +1103,7 @@
{
try
{
- if (isSuspendCoordinatorOnly)
- {
- rpcService.executeCommandOnCoordinator(suspend, true);
- }
- else
- {
- rpcService.executeCommandOnAllNodes(suspend, true);
- }
+ rpcService.executeCommandOnAllNodes(suspend, true);
}
catch (SecurityException e)
{
@@ -1130,20 +1123,13 @@
/**
* {@inheritDoc}
*/
- public void resume(boolean isResumeCoordinatorOnly) throws ResumeException
+ public void resume() throws ResumeException
{
if (rpcService != null)
{
try
{
- if (isResumeCoordinatorOnly)
- {
- rpcService.executeCommandOnCoordinator(resume, true);
- }
- else
- {
- rpcService.executeCommandOnAllNodes(resume, true);
- }
+ rpcService.executeCommandOnAllNodes(resume, true);
}
catch (SecurityException e)
{