Author: nzamosenchuk
Date: 2009-12-23 07:58:25 -0500 (Wed, 23 Dec 2009)
New Revision: 1152
Modified:
jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/AbstractQueryHandler.java
jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/DefaultChangesFilter.java
jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/QueryHandler.java
jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/jbosscache/JbossCacheIndexChangesFilter.java
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
jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/MultiIndex.java
jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/SearchIndex.java
Log:
EXOJCR-327: IndexInfos now gets IoMode and flag whether it is system. Changed fields and
methods visibility policy, updated JBossCacheIndexInfos.
Modified:
jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/AbstractQueryHandler.java
===================================================================
---
jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/AbstractQueryHandler.java 2009-12-23
10:44:33 UTC (rev 1151)
+++
jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/AbstractQueryHandler.java 2009-12-23
12:58:25 UTC (rev 1152)
@@ -70,7 +70,7 @@
/**
* {@link IndexInfos} instance that is passed to {@link MultiIndex}
*/
- protected IndexInfos indexInfos;
+ private IndexInfos indexInfos;
public boolean isInitialized()
{
@@ -220,4 +220,12 @@
this.indexInfos = indexInfos;
}
+ /**
+ * @see org.exoplatform.services.jcr.impl.core.query.QueryHandler#getIndexInfos()
+ */
+ public IndexInfos getIndexInfos()
+ {
+ return indexInfos;
+ }
+
}
Modified:
jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/DefaultChangesFilter.java
===================================================================
---
jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/DefaultChangesFilter.java 2009-12-23
10:44:33 UTC (rev 1151)
+++
jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/DefaultChangesFilter.java 2009-12-23
12:58:25 UTC (rev 1152)
@@ -59,12 +59,12 @@
if (!parentHandler.isInitialized())
{
- parentHandler.setIndexInfos(new IndexInfos());
+ parentHandler.setIndexInfos(new IndexInfos(true, IndexerIoMode.READ_WRITE));
parentHandler.init();
}
if (!handler.isInitialized())
{
- parentHandler.setIndexInfos(new IndexInfos());
+ handler.setIndexInfos(new IndexInfos(false, IndexerIoMode.READ_WRITE));
handler.init();
}
}
Modified:
jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/QueryHandler.java
===================================================================
---
jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/QueryHandler.java 2009-12-23
10:44:33 UTC (rev 1151)
+++
jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/QueryHandler.java 2009-12-23
12:58:25 UTC (rev 1152)
@@ -155,10 +155,16 @@
public QueryHits executeQuery(Query query) throws IOException;
/**
- * Sets {@link IndexInfos} instance to QueryHandler, which is later passed to {@link
MultiIndex}.
+ * Sets {@link IndexInfos} instance into QueryHandler, which is later passed to {@link
MultiIndex}.
*
* @param indexInfos
*/
public void setIndexInfos(IndexInfos indexInfos);
+
+ /**
+ * Returns {@link IndexInfos} instance that was set into QueryHandler.
+ * @return
+ */
+ public IndexInfos getIndexInfos();
}
Modified:
jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/jbosscache/JbossCacheIndexChangesFilter.java
===================================================================
---
jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/jbosscache/JbossCacheIndexChangesFilter.java 2009-12-23
10:44:33 UTC (rev 1151)
+++
jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/jbosscache/JbossCacheIndexChangesFilter.java 2009-12-23
12:58:25 UTC (rev 1152)
@@ -26,7 +26,6 @@
import org.exoplatform.services.jcr.impl.core.query.IndexingTree;
import org.exoplatform.services.jcr.impl.core.query.QueryHandler;
import org.exoplatform.services.jcr.impl.core.query.SearchManager;
-import org.exoplatform.services.jcr.impl.core.query.lucene.IndexInfos;
import org.exoplatform.services.jcr.util.IdGenerator;
import org.exoplatform.services.log.ExoLogger;
import org.exoplatform.services.log.Log;
@@ -59,16 +58,8 @@
private final Cache<Serializable, Object> cache;
- public static String ADDED = "$add".intern();
+ public static final String LISTWRAPPER = "$lists".intern();
- public static String REMOVED = "$remove".intern();
-
- public static String PARENT_ADDED = "$padd".intern();
-
- public static String PARENT_REMOVED = "$premove".intern();
-
- public static String LISTWRAPPER = "$lists".intern();
-
/**
* @param searchManager
* @param config
@@ -127,12 +118,12 @@
if (!parentHandler.isInitialized())
{
- parentHandler.setIndexInfos(new JbossCacheIndexInfos(cache));
+ parentHandler.setIndexInfos(new JbossCacheIndexInfos(cache, true, ioMode));
parentHandler.init();
}
if (!handler.isInitialized())
{
- handler.setIndexInfos(new JbossCacheIndexInfos(cache));
+ handler.setIndexInfos(new JbossCacheIndexInfos(cache, false, ioMode));
handler.init();
}
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-23
10:44:33 UTC (rev 1151)
+++
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-23
12:58:25 UTC (rev 1152)
@@ -18,49 +18,113 @@
*/
package org.exoplatform.services.jcr.impl.core.query.jbosscache;
-import org.apache.lucene.store.Directory;
+import org.exoplatform.services.jcr.impl.core.query.IndexerIoMode;
import org.exoplatform.services.jcr.impl.core.query.lucene.IndexInfos;
+import org.exoplatform.services.log.ExoLogger;
+import org.exoplatform.services.log.Log;
import org.jboss.cache.Cache;
+import org.jboss.cache.Fqn;
+import org.jboss.cache.notifications.annotation.CacheListener;
+import org.jboss.cache.notifications.annotation.NodeModified;
+import org.jboss.cache.notifications.event.NodeModifiedEvent;
+
import java.io.IOException;
import java.io.Serializable;
+import java.util.Set;
/**
* @author <a href="mailto:nikolazius@gmail.com">Nikolay
Zamosenchuk</a>
* @version $Id: JbossCacheIndexInfos.java 34360 2009-07-22 23:58:59Z nzamosenchuk $
*
*/
+@CacheListener
public class JbossCacheIndexInfos extends IndexInfos
{
+ private final Log log = ExoLogger.getLogger(this.getClass().getName());
+
+ public static final String INDEX_NAMES = "$names".intern();
+
+ public static final String SYSINDEX_NAMES = "$sysNames".intern();
+
+ public static final String LIST = "$list".intern();
+
private final Cache<Serializable, Object> cache;
/**
+ * This FQN points to cache node, where list of indexes for this {@link IndexInfos}
instance is stored.
+ */
+ private final Fqn namesFqn;
+
+ /**
* @param cache instance of JbossCache that is used to deliver index names
*/
- public JbossCacheIndexInfos(Cache<Serializable, Object> cache)
+ public JbossCacheIndexInfos(Cache<Serializable, Object> cache, boolean system,
IndexerIoMode ioMode)
{
- this(DEFALUT_NAME, cache);
+ this(DEFALUT_NAME, cache, system, ioMode);
}
/**
* @param fileName where index names are stored.
* @param cache instance of JbossCache that is used to deliver index names
*/
- public JbossCacheIndexInfos(String fileName, Cache<Serializable, Object> cache)
+ public JbossCacheIndexInfos(String fileName, Cache<Serializable, Object> cache,
boolean system, IndexerIoMode ioMode)
{
- super(fileName);
+ super(fileName, system, ioMode);
this.cache = cache;
+ namesFqn = Fqn.fromString(system ? SYSINDEX_NAMES : INDEX_NAMES);
}
@Override
public void write() throws IOException
{
- boolean dirty = this.dirty;
+ boolean dirty = isDirty();
+ // write to FS
super.write();
+ // write to cache
if (dirty)
{
// send to cache new list.
}
}
+ @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);
+ }
+ }
+ }
+
+ @Override
+ public void setIoMode(IndexerIoMode ioMode) throws IOException
+ {
+ if (getIoMode() != ioMode)
+ {
+ super.setIoMode(ioMode);
+ if (ioMode == IndexerIoMode.READ_WRITE)
+ {
+ // Now is read-write. Index list is actual and shouldn't be refreshed.
+ // Remove listener to avoid asserting if ioMode is RO on each cache event
+ cache.removeCacheListener(this);
+ }
+ else
+ {
+ // Currently READ_ONLY is set, so new lists should be fired to multiIndex.
+ cache.addCacheListener(this);
+ }
+ }
+ }
+
}
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-23
10:44:33 UTC (rev 1151)
+++
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-23
12:58:25 UTC (rev 1152)
@@ -16,6 +16,11 @@
*/
package org.exoplatform.services.jcr.impl.core.query.lucene;
+import org.apache.lucene.store.Directory;
+import org.exoplatform.services.jcr.impl.core.query.IndexerIoMode;
+import org.exoplatform.services.jcr.impl.core.query.lucene.directory.IndexInputStream;
+import org.exoplatform.services.jcr.impl.core.query.lucene.directory.IndexOutputStream;
+
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
@@ -26,10 +31,6 @@
import java.util.List;
import java.util.Set;
-import org.apache.lucene.store.Directory;
-import org.exoplatform.services.jcr.impl.core.query.lucene.directory.IndexInputStream;
-import org.exoplatform.services.jcr.impl.core.query.lucene.directory.IndexOutputStream;
-
/**
* Stores a sequence of index names.
*/
@@ -44,39 +45,51 @@
/**
* For new segment names.
*/
- protected int counter = 0;
+ private int counter = 0;
/**
* Flag that indicates if index infos needs to be written to disk.
*/
- protected boolean dirty = false;
+ private boolean dirty = false;
/**
* List of index names
*/
- protected List indexes = new ArrayList();
+ private List<String> indexes = new ArrayList<String>();
/**
* Set of names for quick lookup.
*/
- protected Set names = new HashSet();
+ private Set<String> names = new HashSet<String>();
/**
* Name of the file where the infos are stored.
*/
- protected final String name;
+ private final String name;
/**
* Directory, where index names file is stored.
*/
- protected Directory dir;
+ private Directory dir;
/**
+ * {@link MultiIndex} instance for callbacking when list of indexes changed
+ */
+ private MultiIndex multiIndex;
+
+ /**
+ * {@link IndexerIoMode} is used to define current mode.
+ */
+ private IndexerIoMode ioMode;
+
+ private final boolean system;
+
+ /**
* Creates a new IndexInfos using <code>"indexes"</code> as a
filename.
*/
- public IndexInfos()
+ public IndexInfos(boolean system, IndexerIoMode ioMode)
{
- this(DEFALUT_NAME);
+ this(DEFALUT_NAME, system, ioMode);
}
/**
@@ -84,9 +97,11 @@
*
* @param fileName the name of the file where infos are stored.
*/
- public IndexInfos(String fileName)
+ public IndexInfos(String fileName, boolean system, IndexerIoMode ioMode)
{
this.name = fileName;
+ this.system = system;
+ this.ioMode = ioMode;
}
/**
@@ -265,11 +280,89 @@
}
/**
- * Sets direcotry, where file with index names is stored.
+ * Sets directory, where file with index names is stored.
* @param dir
*/
- public void setDir(Directory dir)
+ public void setDirectory(Directory dir)
{
this.dir = dir;
}
+
+ /**
+ * Sets {@link IndexerIoMode} to indexInfos;
+ * @param ioMode
+ * @throws IOException
+ */
+ public void setIoMode(IndexerIoMode ioMode) throws IOException
+ {
+ if (this.ioMode != ioMode)
+ {
+ this.ioMode = ioMode;
+ if (ioMode == IndexerIoMode.READ_WRITE)
+ {
+ names.clear();
+ indexes.clear();
+ read();
+ }
+ }
+ }
+
+ /**
+ * Returns current mode.
+ * @return
+ */
+ public IndexerIoMode getIoMode()
+ {
+ return ioMode;
+ }
+
+ /**
+ * Sets new names, clearing existing.
+ * @param names
+ */
+ protected void setNames(Set<String> names)
+ {
+ this.names.clear();
+ this.indexes.clear();
+ this.names.addAll(names);
+ this.indexes.addAll(names);
+ // new list of indexes if thought to be up to date
+ dirty = false;
+ }
+
+ /**
+ * Sets {@link MultiIndex} instance.
+ * @param multiIndex
+ */
+ public void setMultiIndex(MultiIndex multiIndex)
+ {
+ this.multiIndex = multiIndex;
+ }
+
+ /**
+ * Returns multiIndex instance
+ * @return
+ */
+ public MultiIndex getMultiIndex()
+ {
+ return multiIndex;
+ }
+
+ /**
+ * Returns true if this {@link IndexInfos} corresponds to SystemSearchManager
+ * @return
+ */
+ public boolean isSystem()
+ {
+ return system;
+ }
+
+ /**
+ * Returns true, if changes weren't saved to FS.
+ * @return
+ */
+ protected boolean isDirty()
+ {
+ return dirty;
+ }
}
Modified:
jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/MultiIndex.java
===================================================================
---
jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/MultiIndex.java 2009-12-23
10:44:33 UTC (rev 1151)
+++
jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/MultiIndex.java 2009-12-23
12:58:25 UTC (rev 1152)
@@ -237,7 +237,7 @@
this.nsMappings = handler.getNamespaceMappings();
this.flushTask = null;
this.indexNames = indexInfos;
- this.indexNames.setDir(indexDir);
+ this.indexNames.setDirectory(indexDir);
if (indexNames.exists())
{
indexNames.read();
@@ -2355,6 +2355,7 @@
if (!this.ioMode.equals(ioMode))
{
this.ioMode = ioMode;
+ indexNames.setIoMode(ioMode);
switch (ioMode)
{
case READ_ONLY :
@@ -2433,7 +2434,8 @@
// release reader if any
releaseMultiReader();
// get new indexInfo
- IndexInfos newIndexNames = new IndexInfos();
+ IndexInfos newIndexNames = new IndexInfos(indexNames.isSystem(), ioMode);
+ newIndexNames.setMultiIndex(this);
if (newIndexNames.exists())
{
newIndexNames.read();
Modified:
jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/SearchIndex.java
===================================================================
---
jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/SearchIndex.java 2009-12-23
10:44:33 UTC (rev 1151)
+++
jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/SearchIndex.java 2009-12-23
12:58:25 UTC (rev 1152)
@@ -515,8 +515,7 @@
indexingConfig = createIndexingConfiguration(nsMappings);
analyzer.setIndexingConfig(indexingConfig);
- index =
- new MultiIndex(this, context.getIndexingTree(), ioMode, indexInfos == null ? new
IndexInfos() : indexInfos);
+ index = new MultiIndex(this, context.getIndexingTree(), ioMode, getIndexInfos());
// if RW mode, create initial index and start check
if (ioMode == IndexerIoMode.READ_WRITE)
{