Made this a complete no-op if IndexWriterRAMManager is not specified

This commit is contained in:
Marc D'Mello 2024-12-10 22:44:43 +00:00
parent 1657e49154
commit 00ec37f32b
2 changed files with 14 additions and 2 deletions

View File

@ -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();

View File

@ -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;