[exo-jcr-commits] exo-jcr SVN: r1164 - in jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query: lucene and 1 other directory.

do-not-reply at jboss.org do-not-reply at jboss.org
Thu Dec 24 07:52:48 EST 2009


Author: nzamosenchuk
Date: 2009-12-24 07:52:48 -0500 (Thu, 24 Dec 2009)
New Revision: 1164

Modified:
   jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/jbosscache/JbossCacheIndexInfos.java
   jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/IndexInfos.java
Log:
EXOJCR-327: Updated indexInfos: removed method exists and added check on read(). Updated JbossCacheIndexInfos

Modified: jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/jbosscache/JbossCacheIndexInfos.java
===================================================================
--- jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/jbosscache/JbossCacheIndexInfos.java	2009-12-24 12:42:02 UTC (rev 1163)
+++ jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/jbosscache/JbossCacheIndexInfos.java	2009-12-24 12:52:48 UTC (rev 1164)
@@ -33,6 +33,15 @@
 import java.util.Set;
 
 /**
+ * List of indexes is stored in FS and all operations with it are wrapped by IndexInfos class. In
+ * standalone mode index and so the list of indexes are managed by indexer and can't be changed 
+ * externally. 
+ * But in cluster environment all JCR Indexers are reading from shared file system and only one
+ * cluster node is writing this index. So read-only cluster nodes should be notified when content
+ * of index (actually list of index segments) is changed. 
+ * This class is responsible for storing list of segments (indexes) in distributed JBoss Cache 
+ * instance.
+ * 
  * @author <a href="mailto:nikolazius at gmail.com">Nikolay Zamosenchuk</a>
  * @version $Id: JbossCacheIndexInfos.java 34360 2009-07-22 23:58:59Z nzamosenchuk $
  *
@@ -47,7 +56,7 @@
 
    private static final String SYSINDEX_NAMES = "$sysNames".intern();
 
-   private static final String LIST = "$list".intern();
+   private static final String LIST_KEY = "$list".intern();
 
    private final Cache<Serializable, Object> cache;
 
@@ -82,60 +91,25 @@
    {
       super(fileName);
       this.cache = cache;
+      // store parsed FQN to avoid it's parsing each time cache event is generated
       namesFqn = Fqn.fromString(system ? SYSINDEX_NAMES : INDEX_NAMES);
       if (ioMode == IndexerIoMode.READ_ONLY)
       {
          // Currently READ_ONLY is set, so new lists should be fired to multiIndex.
          cache.addCacheListener(this);
       }
+      log.info("/!\\ created jboss cache index infos");
    }
 
    /**
-    * CacheListener method, that accepts event, when cache node changed. This class is registered as cache listener, 
-    * only in READ_ONLY mode.
-    * @param event
+    * @see org.exoplatform.services.jcr.impl.core.query.lucene.IndexInfos#setIoMode(org.exoplatform.services.jcr.impl.core.query.IndexerIoMode)
     */
-   @NodeModified
-   public void cacheNodeModified(NodeModifiedEvent event)
-   {
-      if (!event.isPre() && event.equals(namesFqn))
-      {
-         // update lists
-         setNames((Set<String>)cache.get(namesFqn, LIST));
-         // callback multiIndex to refresh lists
-         try
-         {
-            getMultiIndex().refreshIndexList();
-         }
-         catch (IOException e)
-         {
-            log.error("Failed to update indexes! " + e.getMessage(), e);
-         }
-      }
-   }
-
-   /**
-    * @see org.exoplatform.services.jcr.impl.core.query.lucene.IndexInfos#getIoMode()
-    */
-   public IndexerIoMode getIoMode()
-   {
-      return ioMode;
-   }
-
-   /**
-    * Returns true if this {@link IndexInfos} corresponds to SystemSearchManager
-    * @return
-    */
-   public boolean isSystem()
-   {
-      return system;
-   }
-
    @Override
    public void setIoMode(IndexerIoMode ioMode) throws IOException
    {
       if (this.ioMode != ioMode)
       {
+         log.info("New IoMode:"+ioMode);
          super.setIoMode(ioMode);
          if (ioMode == IndexerIoMode.READ_WRITE)
          {
@@ -143,7 +117,7 @@
             // Remove listener to avoid asserting if ioMode is RO on each cache event 
             cache.removeCacheListener(this);
             // re-read from FS current actual list.
-            refresh();
+            super.read();
          }
          else
          {
@@ -159,14 +133,41 @@
    @Override
    public void write() throws IOException
    {
-      boolean dirty = isDirty();
-      // write to FS
-      super.write();
-      // write to cache
-      if (dirty)
+      // if READ_WRITE and is dirty, then flush. 
+      if (isDirty() && ioMode == IndexerIoMode.READ_WRITE)
       {
-         // send to cache new list.
+         // write to FS
+         super.write();
+         // write to cache
+         cache.put(namesFqn, LIST_KEY, getNames());
       }
    }
 
+   /**
+    * CacheListener method, that accepts event, when cache node changed. This class is registered as cache listener, 
+    * only in READ_ONLY mode.
+    * @param event
+    */
+   @NodeModified
+   public void cacheNodeModified(NodeModifiedEvent event)
+   {
+      if (!event.isPre() && event.getFqn().equals(namesFqn))
+      {
+         // read from cache to update lists
+         Set<String> set = (Set<String>)cache.get(namesFqn, LIST_KEY);
+         if (set != null)
+         {
+            setNames(set);
+            // callback multiIndex to refresh lists
+            try
+            {
+               getMultiIndex().refreshIndexList();
+            }
+            catch (IOException e)
+            {
+               log.error("Failed to update indexes! " + e.getMessage(), e);
+            }
+         }
+      }
+   }
 }

Modified: jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/IndexInfos.java
===================================================================
--- jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/IndexInfos.java	2009-12-24 12:42:02 UTC (rev 1163)
+++ jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/IndexInfos.java	2009-12-24 12:52:48 UTC (rev 1164)
@@ -96,19 +96,6 @@
    }
 
    /**
-    * Returns <code>true</code> if this index infos exists in
-    * <code>dir</code>.
-    *
-    * @param dir the directory where to look for the index infos.
-    * @return <code>true</code> if it exists; <code>false</code> otherwise.
-    * @throws IOException if an error occurs while reading from the directory.
-    */
-   public boolean exists() throws IOException
-   {
-      return dir.fileExists(name);
-   }
-
-   /**
     * Returns the name of the file where infos are stored.
     *
     * @return the name of the file where infos are stored.
@@ -119,47 +106,38 @@
    }
 
    /**
-    * Reads the index infos.
+    * Reads the index infos. Before reading it checks if file exists
     *
     * @param dir the directory from where to read the index infos.
     * @throws IOException if an error occurs.
     */
    public void read() throws IOException
    {
-      // clear current lists
-      InputStream in = new IndexInputStream(dir.openInput(name));
-      try
+      names.clear();
+      indexes.clear();
+      if (dir.fileExists(name))
       {
-         DataInputStream di = new DataInputStream(in);
-         counter = di.readInt();
-         for (int i = di.readInt(); i > 0; i--)
+         // clear current lists
+         InputStream in = new IndexInputStream(dir.openInput(name));
+         try
          {
-            String indexName = di.readUTF();
-            indexes.add(indexName);
-            names.add(indexName);
+            DataInputStream di = new DataInputStream(in);
+            counter = di.readInt();
+            for (int i = di.readInt(); i > 0; i--)
+            {
+               String indexName = di.readUTF();
+               indexes.add(indexName);
+               names.add(indexName);
+            }
          }
+         finally
+         {
+            in.close();
+         }
       }
-      finally
-      {
-         in.close();
-      }
    }
 
    /**
-    * re-reads list of indexes from FS
-    * @throws IOException
-    */
-   public void refresh() throws IOException
-   {
-      names.clear();
-      indexes.clear();
-      if (exists())
-      {
-         read();
-      }
-   }
-
-   /**
     * Writes the index infos to disk if they are dirty.
     *
     * @param dir the directory where to write the index infos.
@@ -305,16 +283,9 @@
    }
 
    /**
-    * Returns current mode.
-    * @return
-    */
-   public IndexerIoMode getIoMode()
-   {
-      return IndexerIoMode.READ_WRITE;
-   }
-
-   /**
-    * Sets new names, clearing existing.
+    * Sets new names, clearing existing. It is thought to be used when list of indexes can
+    * be externally changed.
+    * 
     * @param names
     */
    protected void setNames(Set<String> names)



More information about the exo-jcr-commits mailing list