You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jackrabbit.apache.org by mr...@apache.org on 2005/08/09 10:46:41 UTC
svn commit: r231015 - in /incubator/jackrabbit/trunk/core:
applications/test/repository.xml src/conf/repository.xml
src/java/org/apache/jackrabbit/core/query/lucene/MultiIndex.java
src/java/org/apache/jackrabbit/core/query/lucene/SearchIndex.java
Author: mreutegg
Date: Tue Aug 9 01:46:33 2005
New Revision: 231015
URL: http://svn.apache.org/viewcvs?rev=231015&view=rev
Log:
JCR-177: Commit volatile index to disc after some configurable idle time
Modified:
incubator/jackrabbit/trunk/core/applications/test/repository.xml
incubator/jackrabbit/trunk/core/src/conf/repository.xml
incubator/jackrabbit/trunk/core/src/java/org/apache/jackrabbit/core/query/lucene/MultiIndex.java
incubator/jackrabbit/trunk/core/src/java/org/apache/jackrabbit/core/query/lucene/SearchIndex.java
Modified: incubator/jackrabbit/trunk/core/applications/test/repository.xml
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/core/applications/test/repository.xml?rev=231015&r1=231014&r2=231015&view=diff
==============================================================================
--- incubator/jackrabbit/trunk/core/applications/test/repository.xml (original)
+++ incubator/jackrabbit/trunk/core/applications/test/repository.xml Tue Aug 9 01:46:33 2005
@@ -75,7 +75,7 @@
<!ATTLIST LoginModule
class CDATA #REQUIRED>
- <!--
+ <!--
the Workspaces element specifies the workspaces root directory
(rootPath attribute) and the name of the default workspace
(defaultWorkspace attribute).
@@ -198,6 +198,8 @@
Supported parameters for lucene search index:
- useCompoundFile: advises lucene to use compound files for the index files
- minMergeDocs: minimum number of nodes in an index until segments are merged
+ - volatileIdleTime: idle time in seconds until the volatile index is
+ moved to persistent index even though minMergeDocs is not reached.
- maxMergeDocs: maximum number of nodes in segments that will be merged
- mergeFactor: determines how often segment indices are merged
- bufferSize: maximum number of documents that are held in a pending
@@ -211,6 +213,7 @@
<SearchIndex class="org.apache.jackrabbit.core.query.lucene.SearchIndex">
<param name="useCompoundFile" value="true"/>
<param name="minMergeDocs" value="1000"/>
+ <param name="volatileIdleTime" value="3"/>
<param name="maxMergeDocs" value="100000"/>
<param name="mergeFactor" value="10"/>
<param name="bufferSize" value="10"/>
Modified: incubator/jackrabbit/trunk/core/src/conf/repository.xml
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/core/src/conf/repository.xml?rev=231015&r1=231014&r2=231015&view=diff
==============================================================================
--- incubator/jackrabbit/trunk/core/src/conf/repository.xml (original)
+++ incubator/jackrabbit/trunk/core/src/conf/repository.xml Tue Aug 9 01:46:33 2005
@@ -198,6 +198,8 @@
Supported parameters for lucene search index:
- useCompoundFile: advises lucene to use compound files for the index files
- minMergeDocs: minimum number of nodes in an index until segments are merged
+ - volatileIdleTime: idle time in seconds until the volatile index is
+ moved to persistent index even though minMergeDocs is not reached.
- maxMergeDocs: maximum number of nodes in segments that will be merged
- mergeFactor: determines how often segment indices are merged
- bufferSize: maximum number of documents that are held in a pending
@@ -211,6 +213,7 @@
<SearchIndex class="org.apache.jackrabbit.core.query.lucene.SearchIndex">
<param name="useCompoundFile" value="true"/>
<param name="minMergeDocs" value="1000"/>
+ <param name="volatileIdleTime" value="3"/>
<param name="maxMergeDocs" value="100000"/>
<param name="mergeFactor" value="10"/>
<param name="bufferSize" value="10"/>
Modified: incubator/jackrabbit/trunk/core/src/java/org/apache/jackrabbit/core/query/lucene/MultiIndex.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/core/src/java/org/apache/jackrabbit/core/query/lucene/MultiIndex.java?rev=231015&r1=231014&r2=231015&view=diff
==============================================================================
--- incubator/jackrabbit/trunk/core/src/java/org/apache/jackrabbit/core/query/lucene/MultiIndex.java (original)
+++ incubator/jackrabbit/trunk/core/src/java/org/apache/jackrabbit/core/query/lucene/MultiIndex.java Tue Aug 9 01:46:33 2005
@@ -37,15 +37,19 @@
import java.util.Iterator;
import java.util.List;
import java.util.Set;
+import java.util.Timer;
+import java.util.TimerTask;
/**
* A <code>MultiIndex</code> consists of a {@link VolatileIndex} and multiple
* {@link PersistentIndex}es. The goal is to keep most parts of the index open
* with index readers and write new index data to the volatile index. When
- * the volatile index reaches a certain size (see {@link SearchIndex#setMinMergeDocs(int)} a
- * new persistent index is created with the index data from the volatile index.
- * the new persistent index is then added to the list of already existing
- * persistent indexes. Furhter operations on the new persistent index will
+ * the volatile index reaches a certain size (see {@link SearchIndex#setMinMergeDocs(int)})
+ * a new persistent index is created with the index data from the volatile index,
+ * the same happens when the volatile index has been idle for some time (see
+ * {@link SearchIndex#setVolatileIdleTime(int)}).
+ * The new persistent index is then added to the list of already existing
+ * persistent indexes. Further operations on the new persistent index will
* however only require an <code>IndexReader</code> which serves for queries
* but also for delete operations on the index.
* <p/>
@@ -126,6 +130,17 @@
private boolean redoLogApplied = false;
/**
+ * The last time this index was modified. That is, a document was added
+ * or removed.
+ */
+ private long lastModificationTime;
+
+ /**
+ * Timer to schedule commits of the volatile index after some idle time.
+ */
+ private final Timer commitTimer = new Timer(true);
+
+ /**
* Creates a new MultiIndex.
*
* @param fs the base file system
@@ -213,6 +228,8 @@
} catch (RepositoryException e) {
throw new IOException("Error indexing root node: " + e.getMessage());
}
+ lastModificationTime = System.currentTimeMillis();
+ startCommitTimer();
}
/**
@@ -223,6 +240,7 @@
* index.
*/
synchronized void addDocument(Document doc) throws IOException {
+ lastModificationTime = System.currentTimeMillis();
multiReader = null;
volatileIndex.addDocument(doc);
if (volatileIndex.getRedoLog().getSize() >= handler.getMinMergeDocs()) {
@@ -239,6 +257,7 @@
* @throws IOException if an error occurs while deleting the document.
*/
synchronized int removeDocument(Term idTerm) throws IOException {
+ lastModificationTime = System.currentTimeMillis();
// flush multi reader if it does not have deletions yet
if (multiReader != null && !multiReader.hasDeletions()) {
multiReader = null;
@@ -269,6 +288,7 @@
* @throws IOException if an error occurs while deleting documents.
*/
synchronized int removeAllDocuments(Term idTerm) throws IOException {
+ lastModificationTime = System.currentTimeMillis();
// flush multi reader if it does not have deletions yet
if (multiReader != null && !multiReader.hasDeletions()) {
multiReader = null;
@@ -305,6 +325,10 @@
* Closes this <code>MultiIndex</code>.
*/
synchronized void close() {
+ // stop timer
+ commitTimer.cancel();
+
+ // commit / close indexes
multiReader = null;
try {
if (volatileIndex.getRedoLog().hasEntries()) {
@@ -587,6 +611,41 @@
indexNames.write(fs);
} catch (FileSystemException e) {
throw new IOException(e.getMessage());
+ }
+ }
+
+ /**
+ * Starts the commit timer that periodically checks if the volatile index
+ * should be committed. The timer task will call {@link #checkCommit()}.
+ */
+ private void startCommitTimer() {
+ commitTimer.schedule(new TimerTask() {
+ public void run() {
+ checkCommit();
+ }
+ }, 0, 1000);
+ }
+
+ /**
+ * Checks the duration between the last modification to this index and the
+ * current time and commits the volatile index (if there are changes at all)
+ * if the duration (idle time) is more than {@link SearchIndex#getVolatileIdleTime()}
+ * seconds.
+ */
+ private synchronized void checkCommit() {
+ long idleTime = System.currentTimeMillis() - lastModificationTime;
+ // do not commit if volatileIdleTime is zero or negative
+ if (handler.getVolatileIdleTime() > 0
+ && idleTime > handler.getVolatileIdleTime() * 1000) {
+ try {
+ if (volatileIndex.getRedoLog().hasEntries()) {
+ log.info("Committing in-memory index after being idle for " +
+ idleTime + " ms.");
+ commit();
+ }
+ } catch (IOException e) {
+ log.error("Unable to commit volatile index", e);
+ }
}
}
Modified: incubator/jackrabbit/trunk/core/src/java/org/apache/jackrabbit/core/query/lucene/SearchIndex.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/core/src/java/org/apache/jackrabbit/core/query/lucene/SearchIndex.java?rev=231015&r1=231014&r2=231015&view=diff
==============================================================================
--- incubator/jackrabbit/trunk/core/src/java/org/apache/jackrabbit/core/query/lucene/SearchIndex.java (original)
+++ incubator/jackrabbit/trunk/core/src/java/org/apache/jackrabbit/core/query/lucene/SearchIndex.java Tue Aug 9 01:46:33 2005
@@ -74,6 +74,11 @@
private int minMergeDocs = 1000;
/**
+ * volatileIdleTime config parameter.
+ */
+ private int volatileIdleTime = 3;
+
+ /**
* maxMergeDocs config parameter
*/
private int maxMergeDocs = 100000;
@@ -352,6 +357,24 @@
*/
public int getMinMergeDocs() {
return minMergeDocs;
+ }
+
+ /**
+ * Sets the property: volatileIdleTime
+ *
+ * @param volatileIdleTime idle time in seconds
+ */
+ public void setVolatileIdleTime(int volatileIdleTime) {
+ this.volatileIdleTime = volatileIdleTime;
+ }
+
+ /**
+ * Returns the current value for volatileIdleTime.
+ *
+ * @return the current value for volatileIdleTime.
+ */
+ public int getVolatileIdleTime() {
+ return volatileIdleTime;
}
/**