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 2008/10/21 20:07:17 UTC
svn commit: r706697 - in
/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene:
AbstractIndex.java MultiIndex.java SearchIndex.java VolatileIndex.java
Author: mreutegg
Date: Tue Oct 21 11:07:16 2008
New Revision: 706697
URL: http://svn.apache.org/viewvc?rev=706697&view=rev
Log:
JCR-1741: Flush volatile index when size limit is reached
Modified:
jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/AbstractIndex.java
jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/MultiIndex.java
jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/SearchIndex.java
jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/VolatileIndex.java
Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/AbstractIndex.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/AbstractIndex.java?rev=706697&r1=706696&r2=706697&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/AbstractIndex.java (original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/AbstractIndex.java Tue Oct 21 11:07:16 2008
@@ -417,6 +417,17 @@
}
/**
+ * @return the number of bytes this index occupies in memory.
+ */
+ synchronized long getRamSizeInBytes() {
+ if (indexWriter != null) {
+ return indexWriter.ramSizeInBytes();
+ } else {
+ return 0;
+ }
+ }
+
+ /**
* Closes the shared reader.
*
* @throws IOException if an error occurs while closing the reader.
Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/MultiIndex.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/MultiIndex.java?rev=706697&r1=706696&r2=706697&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/MultiIndex.java (original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/MultiIndex.java Tue Oct 21 11:07:16 2008
@@ -411,6 +411,7 @@
* @param add collection of <code>Document</code>s to add. Some of the
* elements in this collection may be <code>null</code>, to
* indicate that a node could not be indexed successfully.
+ * @throws IOException if an error occurs while updating the index.
*/
synchronized void update(Collection remove, Collection add) throws IOException {
// make sure a reader is available during long updates
@@ -985,7 +986,7 @@
/**
* Checks if it is needed to commit the volatile index according to {@link
- * SearchIndex#getMinMergeDocs()}.
+ * SearchIndex#getMaxVolatileIndexSize()}.
*
* @return <code>true</code> if the volatile index has been committed,
* <code>false</code> otherwise.
@@ -993,7 +994,7 @@
* index.
*/
private boolean checkVolatileCommit() throws IOException {
- if (volatileIndex.getNumDocuments() >= handler.getMinMergeDocs()) {
+ if (volatileIndex.getRamSizeInBytes() >= handler.getMaxVolatileIndexSize()) {
commitVolatileIndex();
return true;
}
Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/SearchIndex.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/SearchIndex.java?rev=706697&r1=706696&r2=706697&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/SearchIndex.java (original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/SearchIndex.java Tue Oct 21 11:07:16 2008
@@ -223,6 +223,12 @@
private int minMergeDocs = DEFAULT_MIN_MERGE_DOCS;
/**
+ * The maximum volatile index size in bytes until it is written to disk.
+ * The default value is 1048576 (1MB).
+ */
+ private long maxVolatileIndexSize = 1024 * 1024;
+
+ /**
* volatileIdleTime config parameter.
*/
private int volatileIdleTime = 3;
@@ -1876,6 +1882,22 @@
return similarity.getClass().getName();
}
+ /**
+ * Sets a new maxVolatileIndexSize value.
+ *
+ * @param maxVolatileIndexSize the new value.
+ */
+ public void setMaxVolatileIndexSize(long maxVolatileIndexSize) {
+ this.maxVolatileIndexSize = maxVolatileIndexSize;
+ }
+
+ /**
+ * @return the maxVolatileIndexSize in bytes.
+ */
+ public long getMaxVolatileIndexSize() {
+ return maxVolatileIndexSize;
+ }
+
//----------------------------< internal >----------------------------------
/**
Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/VolatileIndex.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/VolatileIndex.java?rev=706697&r1=706696&r2=706697&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/VolatileIndex.java (original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/VolatileIndex.java Tue Oct 21 11:07:16 2008
@@ -115,7 +115,7 @@
*
* @return the number of valid documents in this index.
*/
- int getNumDocuments() throws IOException {
+ int getNumDocuments() {
return numDocs;
}
@@ -142,6 +142,13 @@
}
/**
+ * {@inheritDoc}
+ */
+ long getRamSizeInBytes() {
+ return super.getRamSizeInBytes() + ((RAMDirectory) getDirectory()).sizeInBytes();
+ }
+
+ /**
* Sets a new buffer size for pending documents to add to the index.
* Higher values consume more memory, but help to avoid multiple index
* cycles when a node is changed / saved multiple times.
@@ -154,6 +161,8 @@
/**
* Commits pending documents to the index.
+ *
+ * @throws IOException if committing pending documents fails.
*/
private void commitPending() throws IOException {
if (pending.isEmpty()) {