Author: tolusha
Date: 2011-02-18 08:38:33 -0500 (Fri, 18 Feb 2011)
New Revision: 3994
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/IndexRecoveryImpl.java
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/MultiIndex.java
Log:
EXOJCR-1193: Index retrieval from coordinator node
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
12:52:16 UTC (rev 3993)
+++
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/IndexRecovery.java 2011-02-18
13:38:33 UTC (rev 3994)
@@ -33,16 +33,22 @@
{
/**
- * Switch index between RO/RW states.
+ * Switch index offline.
*
- * @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;
+ public void setIndexOffline() throws RepositoryException;
/**
+ * Switch index online.
+ *
+ * @throws RepositoryException
+ * if any exception occurred
+ */
+ public void setIndexOnline() 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
12:52:16 UTC (rev 3993)
+++
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/IndexRecoveryImpl.java 2011-02-18
13:38:33 UTC (rev 3994)
@@ -19,9 +19,13 @@
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.log.ExoLogger;
+import org.exoplatform.services.log.Log;
import org.exoplatform.services.rpc.RPCException;
import org.exoplatform.services.rpc.RPCService;
import org.exoplatform.services.rpc.RemoteCommand;
+import org.exoplatform.services.rpc.TopologyChangeEvent;
+import org.exoplatform.services.rpc.TopologyChangeListener;
import java.io.File;
import java.io.IOException;
@@ -41,10 +45,15 @@
* @author <a href="mailto:anatoliy.bazko@exoplatform.com.ua">Anatoliy
Bazko</a>
* @version $Id: IndexRetrievalImpl.java 34360 2010-11-11 11:11:11Z tolusha $
*/
-public class IndexRecoveryImpl implements IndexRecovery
+public class IndexRecoveryImpl implements IndexRecovery, TopologyChangeListener
{
/**
+ * Logger instance for this class.
+ */
+ private static final Log log =
ExoLogger.getLogger("exo.jcr.component.core.IndexRecoveryImpl");
+
+ /**
* Buffer size.
*/
public static final int BUFFER_SIZE = 1024 * 1024;
@@ -67,9 +76,19 @@
/**
* Remote command to switch index between RO/RW state.
*/
- private RemoteCommand setReadOnly;
+ private RemoteCommand changeIndexMode;
/**
+ * Remote command to check if node responsible for set index online leave the cluster.
+ */
+ private RemoteCommand requestForResponsibleToSetIndexOnline;
+
+ /**
+ * Indicates that node keep responsible to set index online.
+ */
+ protected Boolean isResponsibleToSetIndexOnline = false;
+
+ /**
* Constructor IndexRetrieveImpl.
*
* @throws RepositoryConfigurationException
@@ -82,16 +101,16 @@
final String commandSuffix = searchManager.getWsId() + "-" +
(searchManager.parentSearchManager == null);
final File indexDirectory = searchManager.getIndexDirectory();
- setReadOnly = rpcService.registerCommand(new RemoteCommand()
+ changeIndexMode = rpcService.registerCommand(new RemoteCommand()
{
public String getId()
{
- return
"org.exoplatform.services.jcr.impl.core.query.IndexRecoveryImpl-setReadOnly-" +
commandSuffix;
+ return
"org.exoplatform.services.jcr.impl.core.query.IndexRecoveryImpl-changeIndexMode-"
+ commandSuffix;
}
public Serializable execute(Serializable[] args) throws Throwable
{
- boolean isReadOnly = (Boolean)args[0];
+ boolean isOnline = (Boolean)args[0];
// TODO searchManager.setReadOnly(isReadOnly);
@@ -154,6 +173,23 @@
}
}
});
+
+ requestForResponsibleToSetIndexOnline = rpcService.registerCommand(new
RemoteCommand()
+ {
+
+ public String getId()
+ {
+ return
"org.exoplatform.services.jcr.impl.core.query.IndexRecoveryImpl-requestForResponsibleToSetIndexOnline-"
+ + commandSuffix;
+ }
+
+ public Serializable execute(Serializable[] args) throws Throwable
+ {
+ return isResponsibleToSetIndexOnline;
+ }
+ });
+
+ rpcService.registerTopologyChangeListener(this);
}
/**
@@ -178,13 +214,32 @@
/**
* {@inheritDoc}
*/
- public void setIndexReadOnly(boolean isReadOnly) throws RepositoryException
+ public void setIndexOffline() throws RepositoryException
{
try
{
- rpcService.executeCommandOnCoordinator(setReadOnly, true, isReadOnly);
+ isResponsibleToSetIndexOnline = true;
+ rpcService.executeCommandOnCoordinator(changeIndexMode, true, false);
+ }
+ catch (SecurityException e)
+ {
+ throw new RepositoryException(e);
+ }
+ catch (RPCException e)
+ {
+ throw new RepositoryException(e);
+ }
+ }
- // TODO failover
+ /**
+ * {@inheritDoc}
+ */
+ public void setIndexOnline() throws RepositoryException
+ {
+ try
+ {
+ rpcService.executeCommandOnCoordinator(changeIndexMode, true, true);
+ isResponsibleToSetIndexOnline = false;
}
catch (SecurityException e)
{
@@ -240,8 +295,7 @@
@Override
public int read() throws IOException
{
- throw new UnsupportedOperationException(
- "RemoteStream.read(byte b[], int off, int len) method is not
supported");
+ throw new UnsupportedOperationException("RemoteStream.read() method is not
supported");
}
/**
@@ -311,4 +365,53 @@
}
}
}
+
+ /**
+ * {@inheritDoc}
+ */
+ public void onChange(TopologyChangeEvent event)
+ {
+ try
+ {
+ if (rpcService.isCoordinator())
+ {
+ new Thread()
+ {
+ @Override
+ public synchronized void run()
+ {
+ try
+ {
+ List<Object> results =
+
rpcService.executeCommandOnAllNodes(requestForResponsibleToSetIndexOnline, true);
+
+ for (Object result : results)
+ {
+ if ((Boolean)result)
+ {
+ return;
+ }
+ }
+
+ // node which was responsible for resuming leave the cluster, so
resume component
+ // TODO searchManager.setOnline();
+ }
+ catch (SecurityException e1)
+ {
+ log.error("You haven't privileges to execute remote
command", e1);
+ }
+ catch (RPCException e1)
+ {
+ log.error("Exception during command execution", e1);
+ }
+ }
+ }.start();
+ }
+ }
+ catch (RPCException e)
+ {
+ log.error("Can't check if node coordinator or not.");
+ }
+ }
+
}
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
12:52:16 UTC (rev 3993)
+++
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/MultiIndex.java 2011-02-18
13:38:33 UTC (rev 3994)
@@ -3352,7 +3352,7 @@
try
{
IndexRecovery indexRecovery = handler.getContext().getIndexRecovery();
- indexRecovery.setIndexReadOnly(true);
+ indexRecovery.setIndexOffline();
File indexDirectory = new File(handler.getContext().getIndexDirectory());
for (String filePath : indexRecovery.getIndexList())
@@ -3389,7 +3389,7 @@
}
}
- indexRecovery.setIndexReadOnly(false);
+ indexRecovery.setIndexOnline();
}
}
finally
Show replies by date