From do-not-reply at jboss.org Fri Feb 18 08:38:34 2011 Content-Type: multipart/mixed; boundary="===============2865426651051488831==" MIME-Version: 1.0 From: do-not-reply at jboss.org To: exo-jcr-commits at lists.jboss.org Subject: [exo-jcr-commits] exo-jcr SVN: r3994 - in jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query: lucene and 1 other directory. Date: Fri, 18 Feb 2011 08:38:34 -0500 Message-ID: <201102181338.p1IDcYm4025367@svn01.web.mwc.hst.phx2.redhat.com> --===============2865426651051488831== Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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/se= rvices/jcr/impl/core/query/IndexRecovery.java =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- 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 m= ode * @throws RepositoryException * if any exception occurred */ - public void setIndexReadOnly(boolean isReadOnly) throws RepositoryExcep= tion; + 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/se= rvices/jcr/impl/core/query/IndexRecoveryImpl.java =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- 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 39= 93) +++ 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 39= 94) @@ -19,9 +19,13 @@ import org.exoplatform.commons.utils.PrivilegedFileHelper; import org.exoplatform.services.jcr.config.RepositoryConfigurationExceptio= n; 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 Anatoliy= Bazko * @version $Id: IndexRetrievalImpl.java 34360 2010-11-11 11:11:11Z tolush= a $ */ -public class IndexRecoveryImpl implements IndexRecovery +public class IndexRecoveryImpl implements IndexRecovery, TopologyChangeLis= tener { = /** + * Logger instance for this class. + */ + private static final Log log =3D ExoLogger.getLogger("exo.jcr.component= .core.IndexRecoveryImpl"); + + /** * Buffer size. */ public static final int BUFFER_SIZE =3D 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 lea= ve the cluster. = + */ + private RemoteCommand requestForResponsibleToSetIndexOnline; + + /** + * Indicates that node keep responsible to set index online. + */ + protected Boolean isResponsibleToSetIndexOnline =3D false; + + /** * Constructor IndexRetrieveImpl. * = * @throws RepositoryConfigurationException = @@ -82,16 +101,16 @@ final String commandSuffix =3D searchManager.getWsId() + "-" + (sear= chManager.parentSearchManager =3D=3D null); final File indexDirectory =3D searchManager.getIndexDirectory(); = - setReadOnly =3D rpcService.registerCommand(new RemoteCommand() + changeIndexMode =3D rpcService.registerCommand(new RemoteCommand() { public String getId() { - return "org.exoplatform.services.jcr.impl.core.query.IndexReco= veryImpl-setReadOnly-" + commandSuffix; + return "org.exoplatform.services.jcr.impl.core.query.IndexReco= veryImpl-changeIndexMode-" + commandSuffix; } = public Serializable execute(Serializable[] args) throws Throwable { - boolean isReadOnly =3D (Boolean)args[0]; + boolean isOnline =3D (Boolean)args[0]; = // TODO searchManager.setReadOnly(isReadOnly); = @@ -154,6 +173,23 @@ } } }); + + requestForResponsibleToSetIndexOnline =3D rpcService.registerCommand= (new RemoteCommand() + { + + public String getId() + { + return "org.exoplatform.services.jcr.impl.core.query.IndexReco= veryImpl-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 RepositoryExcep= tion + public void setIndexOffline() throws RepositoryException { try { - rpcService.executeCommandOnCoordinator(setReadOnly, true, isReadO= nly); + isResponsibleToSetIndexOnline =3D true; + rpcService.executeCommandOnCoordinator(changeIndexMode, true, fal= se); + } + 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, tru= e); + isResponsibleToSetIndexOnline =3D 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 s= upported"); + throw new UnsupportedOperationException("RemoteStream.read() meth= od 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 results =3D + rpcService.executeCommandOnAllNodes(requestForResp= onsibleToSetIndexOnline, 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 c= ommand", 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/se= rvices/jcr/impl/core/query/lucene/MultiIndex.java =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- 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 39= 93) +++ 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 39= 94) @@ -3352,7 +3352,7 @@ try { IndexRecovery indexRecovery =3D handler.getContext().getIndexReco= very(); - indexRecovery.setIndexReadOnly(true); + indexRecovery.setIndexOffline(); = File indexDirectory =3D new File(handler.getContext().getIndexDir= ectory()); for (String filePath : indexRecovery.getIndexList()) @@ -3389,7 +3389,7 @@ } } = - indexRecovery.setIndexReadOnly(false); + indexRecovery.setIndexOnline(); } } finally --===============2865426651051488831==--