Index: src/main/java/org/apache/jackrabbit/core/query/lucene/AbstractIndex.java
===================================================================
--- src/main/java/org/apache/jackrabbit/core/query/lucene/AbstractIndex.java (revision 696655)
+++ src/main/java/org/apache/jackrabbit/core/query/lucene/AbstractIndex.java (working copy)
@@ -154,9 +154,8 @@
* in the constructor.
*
* @return the directory instance passed in the constructor
- * @throws IOException
*/
- Directory getDirectory() throws IOException {
+ Directory getDirectory() {
return directory;
}
@@ -418,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.
Index: src/main/java/org/apache/jackrabbit/core/query/lucene/MultiIndex.java
===================================================================
--- src/main/java/org/apache/jackrabbit/core/query/lucene/MultiIndex.java (revision 696656)
+++ src/main/java/org/apache/jackrabbit/core/query/lucene/MultiIndex.java (working copy)
@@ -412,6 +412,7 @@
* next() on this iterator may return
* null, to indicate that a node could not be
* indexed successfully.
+ * @throws IOException if an error occurs while updating the index.
*/
synchronized void update(Iterator remove, Iterator add) throws IOException {
synchronized (updateMonitor) {
@@ -989,7 +990,7 @@
/**
* Checks if it is needed to commit the volatile index according to {@link
- * SearchIndex#getMinMergeDocs()}.
+ * SearchIndex#getMaxVolatileIndexSize()}.
*
* @return true if the volatile index has been committed,
* false otherwise.
@@ -997,7 +998,7 @@
* index.
*/
private boolean checkVolatileCommit() throws IOException {
- if (volatileIndex.getNumDocuments() >= handler.getMinMergeDocs()) {
+ if (volatileIndex.getRamSizeInBytes() >= handler.getMaxVolatileIndexSize()) {
commitVolatileIndex();
return true;
}
Index: src/main/java/org/apache/jackrabbit/core/query/lucene/SearchIndex.java
===================================================================
--- src/main/java/org/apache/jackrabbit/core/query/lucene/SearchIndex.java (revision 696655)
+++ src/main/java/org/apache/jackrabbit/core/query/lucene/SearchIndex.java (working copy)
@@ -217,6 +217,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;
@@ -1866,6 +1872,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 >----------------------------------
/**
Index: src/main/java/org/apache/jackrabbit/core/query/lucene/VolatileIndex.java
===================================================================
--- src/main/java/org/apache/jackrabbit/core/query/lucene/VolatileIndex.java (revision 696655)
+++ src/main/java/org/apache/jackrabbit/core/query/lucene/VolatileIndex.java (working copy)
@@ -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()) {