mirror of https://github.com/apache/lucene.git
Made this a complete no-op if IndexWriterRAMManager is not specified
This commit is contained in:
parent
1657e49154
commit
00ec37f32b
|
@ -57,7 +57,8 @@ class FlushByRamOrCountsPolicy extends FlushPolicy {
|
|||
@Override
|
||||
public void flushRamManager(IndexWriter writer) throws IOException {
|
||||
IndexWriterRAMManager ramManager = writer.getConfig().indexWriterRAMManager;
|
||||
if (ramManager.getRamBufferSizeMB() != IndexWriterConfig.DISABLE_AUTO_FLUSH) {
|
||||
if (ramManager.getRamBufferSizeMB() != IndexWriterConfig.DISABLE_AUTO_FLUSH
|
||||
&& ramManager.getWriterCount() > 1) {
|
||||
long totalBytes = ramManager.updateAndGetCurrentBytesUsed(writer.ramManagerId);
|
||||
if (totalBytes > ramManager.getRamBufferSizeMB() * 1024 * 1024) {
|
||||
ramManager.flushRoundRobin();
|
||||
|
|
|
@ -37,7 +37,7 @@ public class IndexWriterRAMManager {
|
|||
* @param ramBufferSizeMB the RAM buffer size to use between all registered {@link IndexWriter}
|
||||
* instances
|
||||
*/
|
||||
IndexWriterRAMManager(double ramBufferSizeMB) {
|
||||
public IndexWriterRAMManager(double ramBufferSizeMB) {
|
||||
if (ramBufferSizeMB != IndexWriterConfig.DISABLE_AUTO_FLUSH && ramBufferSizeMB <= 0.0) {
|
||||
throw new IllegalArgumentException("ramBufferSize should be > 0.0 MB when enabled");
|
||||
}
|
||||
|
@ -63,6 +63,11 @@ public class IndexWriterRAMManager {
|
|||
return idToWriter.flushRoundRobin();
|
||||
}
|
||||
|
||||
/** Gets the number of writers registered with this ram manager */
|
||||
public int getWriterCount() {
|
||||
return idToWriter.size();
|
||||
}
|
||||
|
||||
/** Registers a writer can returns the associated ID */
|
||||
protected int registerWriter(IndexWriter writer) {
|
||||
int id = idGenerator.incrementAndGet();
|
||||
|
@ -170,6 +175,12 @@ public class IndexWriterRAMManager {
|
|||
}
|
||||
}
|
||||
|
||||
int size() {
|
||||
synchronized (lock) {
|
||||
return idToWriterNode.size();
|
||||
}
|
||||
}
|
||||
|
||||
private static class IndexWriterNode {
|
||||
IndexWriter writer;
|
||||
int id;
|
||||
|
|
Loading…
Reference in New Issue