Skip to content

Commit

Permalink
Made this a complete no-op if IndexWriterRAMManager is not specified
Browse files Browse the repository at this point in the history
  • Loading branch information
Marc D'Mello committed Dec 10, 2024
1 parent 1657e49 commit 4bf3b2a
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ && flushOnDocCount()
@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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
Expand All @@ -63,6 +63,13 @@ public int flushRoundRobin() throws IOException {
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();
Expand Down Expand Up @@ -170,6 +177,12 @@ long getTotalRamTracker(int id) {
}
}

int size() {
synchronized (lock) {
return idToWriterNode.size();
}
}

private static class IndexWriterNode {
IndexWriter writer;
int id;
Expand Down

0 comments on commit 4bf3b2a

Please sign in to comment.