You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by at...@apache.org on 2025/04/17 18:28:37 UTC

(lucene) 18/18: intermittent commit

This is an automated email from the ASF dual-hosted git repository.

atri pushed a commit to branch new_index_query_include
in repository https://gitbox.apache.org/repos/asf/lucene.git

commit 915c76816c0f31f9755816c59575870467919e5d
Author: Atri Sharma <at...@192.168.1.25>
AuthorDate: Thu Apr 17 23:56:37 2025 +0530

    intermittent commit
---
 .../org/apache/lucene/codecs/BinMapWriter.java     | 148 ++++++++++-----------
 .../codecs/lucene101/Lucene101PostingsFormat.java  |  10 +-
 2 files changed, 80 insertions(+), 78 deletions(-)

diff --git a/lucene/core/src/java/org/apache/lucene/codecs/BinMapWriter.java b/lucene/core/src/java/org/apache/lucene/codecs/BinMapWriter.java
index 35ba8690380..1eb3810d03a 100644
--- a/lucene/core/src/java/org/apache/lucene/codecs/BinMapWriter.java
+++ b/lucene/core/src/java/org/apache/lucene/codecs/BinMapWriter.java
@@ -17,7 +17,6 @@
 package org.apache.lucene.codecs;
 
 import java.io.IOException;
-
 import org.apache.lucene.index.IndexFileNames;
 import org.apache.lucene.index.SegmentWriteState;
 import org.apache.lucene.store.Directory;
@@ -32,84 +31,85 @@ import org.apache.lucene.util.IOUtils;
  */
 public final class BinMapWriter implements AutoCloseable {
 
-    /**
-     * File extension for binmap files.
-     */
-    public static final String EXTENSION = "binmap";
+  /** File extension for binmap files. */
+  public static final String EXTENSION = "binmap";
 
-    /**
-     * Initial file format version.
-     */
-    public static final int VERSION_START = 0;
+  /** Initial file format version. */
+  public static final int VERSION_START = 0;
 
-    private static final String CODEC_NAME = "BinMap";
+  private static final String CODEC_NAME = "BinMap";
 
-    private final Directory directory;
-    private final SegmentWriteState state;
-    private final int maxDoc;
-    private final int binCount;
-    private final int[] bins;
+  private final Directory directory;
+  private final SegmentWriteState state;
+  private final int maxDoc;
+  private final int binCount;
+  private final int[] bins;
 
-    /**
-     * Creates a new {@link BinMapWriter} instance.
-     *
-     * @param directory output directory
-     * @param state     current segment write state
-     * @param docToBin  mapping from docID to bin ID
-     * @param binCount  total number of bins
-     */
-    public BinMapWriter(Directory directory, SegmentWriteState state, int[] docToBin, int binCount) {
-        this.directory = directory;
-        this.state = state;
-        this.maxDoc = state.segmentInfo.maxDoc();
-        this.binCount = binCount;
-        this.bins = docToBin;
-    }
+  private boolean closed = false;
+
+  /**
+   * Creates a new {@link BinMapWriter} instance.
+   *
+   * @param directory output directory
+   * @param state current segment write state
+   * @param docToBin mapping from docID to bin ID
+   * @param binCount total number of bins
+   */
+  public BinMapWriter(Directory directory, SegmentWriteState state, int[] docToBin, int binCount) {
+    this.directory = directory;
+    this.state = state;
+    this.maxDoc = state.segmentInfo.maxDoc();
+    this.binCount = binCount;
+    this.bins = docToBin;
+  }
 
-    /**
-     * Writes the binmap file to the index output directory.
-     *
-     * <p>The format is:
-     *
-     * <ul>
-     *   <li>Header (versioned with {@link org.apache.lucene.codecs.CodecUtil})
-     *   <li>maxDoc (int)
-     *   <li>binCount (int)
-     *   <li>{@code maxDoc} bin IDs, one int per document
-     *   <li>Footer
-     * </ul>
-     */
-    @Override
-    public void close() throws IOException {
-        final String fileName =
-                IndexFileNames.segmentFileName(state.segmentInfo.name, state.segmentSuffix, EXTENSION);
+  /**
+   * Writes the binmap file to the index output directory.
+   *
+   * <p>The format is:
+   *
+   * <ul>
+   *   <li>Header (versioned with {@link org.apache.lucene.codecs.CodecUtil})
+   *   <li>maxDoc (int)
+   *   <li>binCount (int)
+   *   <li>{@code maxDoc} bin IDs, one int per document
+   *   <li>Footer
+   * </ul>
+   */
+  @Override
+  public void close() throws IOException {
+    final String fileName =
+        IndexFileNames.segmentFileName(state.segmentInfo.name, state.segmentSuffix, EXTENSION);
 
-        // Prevent double-write in case close() is called multiple times
-        for (String existing : directory.listAll()) {
-            if (existing.equals(fileName)) {
-                return; // already written
-            }
-        }
-        IndexOutput out = null;
-        boolean success = false;
-        try {
-            out = directory.createOutput(fileName, state.context);
-            CodecUtil.writeIndexHeader(
-                    out, CODEC_NAME, VERSION_START, state.segmentInfo.getId(), state.segmentSuffix);
-            out.writeInt(maxDoc);
-            out.writeInt(binCount);
-            for (int i = 0; i < maxDoc; i++) {
-                out.writeInt(bins[i]);
-            }
-            CodecUtil.writeFooter(out);
-            success = true;
-        } finally {
-            if (success) {
-                IOUtils.close(out);
-            } else {
-                IOUtils.closeWhileHandlingException(out);
-                IOUtils.deleteFilesIgnoringExceptions(directory, fileName);
-            }
-        }
+    if (closed) return;
+    closed = true;
+
+    // Prevent double-write in case close() is called multiple times
+    for (String existing : directory.listAll()) {
+      if (existing.equals(fileName)) {
+        return; // already written
+      }
+    }
+    IndexOutput out = null;
+    boolean success = false;
+    try {
+      out = directory.createOutput(fileName, state.context);
+      CodecUtil.writeIndexHeader(
+          out, CODEC_NAME, VERSION_START, state.segmentInfo.getId(), state.segmentSuffix);
+      out.writeInt(maxDoc);
+      out.writeInt(binCount);
+      for (int i = 0; i < maxDoc; i++) {
+        out.writeInt(bins[i]);
+      }
+      CodecUtil.writeFooter(out);
+      success = true;
+    } finally {
+      if (success) {
+        IOUtils.close(out);
+      } else {
+        IOUtils.closeWhileHandlingException(out);
+        IOUtils.deleteFilesIgnoringExceptions(directory, fileName);
+      }
     }
+  }
 }
diff --git a/lucene/core/src/java/org/apache/lucene/codecs/lucene101/Lucene101PostingsFormat.java b/lucene/core/src/java/org/apache/lucene/codecs/lucene101/Lucene101PostingsFormat.java
index 55d39307ea3..2031a93e522 100644
--- a/lucene/core/src/java/org/apache/lucene/codecs/lucene101/Lucene101PostingsFormat.java
+++ b/lucene/core/src/java/org/apache/lucene/codecs/lucene101/Lucene101PostingsFormat.java
@@ -502,8 +502,10 @@ public final class Lucene101PostingsFormat extends PostingsFormat {
           }
         }
 
-        BinMapWriter writer = new BinMapWriter(state.directory, state, docToBin, binCount);
-        writer.close();
+        try (BinMapWriter writer = new BinMapWriter(state.directory, state, docToBin, binCount)) {
+          // Trigger side-effect and keep compiler happy
+          assert writer != null;
+        }
       }
     }
   }
@@ -530,7 +532,7 @@ public final class Lucene101PostingsFormat extends PostingsFormat {
           prior = e;
         }
 
-        try {
+        /*try {
           if (prior == null) {
             // Now that all outputs are flushed, perform binning safely
             maybeWriteDocBinning(state);
@@ -542,7 +544,7 @@ public final class Lucene101PostingsFormat extends PostingsFormat {
           } else {
             throw e;
           }
-        }
+        }*/
 
         if (prior != null) {
           throw prior;