From 9667977b907d8aad996a0fdb8449e598f3b50c49 Mon Sep 17 00:00:00 2001 From: Michael McCandless Date: Thu, 26 May 2011 15:57:43 +0000 Subject: [PATCH] LUCENE-3148: if VarIntBlockIO hits exc during write, don't stuff 0s during close git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1127977 13f79535-47bb-0310-9956-ffa450edef68 --- .../intblock/VariableIntBlockIndexOutput.java | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/lucene/src/java/org/apache/lucene/index/codecs/intblock/VariableIntBlockIndexOutput.java b/lucene/src/java/org/apache/lucene/index/codecs/intblock/VariableIntBlockIndexOutput.java index d39db6cd750..46112404636 100644 --- a/lucene/src/java/org/apache/lucene/index/codecs/intblock/VariableIntBlockIndexOutput.java +++ b/lucene/src/java/org/apache/lucene/index/codecs/intblock/VariableIntBlockIndexOutput.java @@ -41,6 +41,7 @@ public abstract class VariableIntBlockIndexOutput extends IntIndexOutput { protected final IndexOutput out; private int upto; + private boolean hitExcDuringWrite; // TODO what Var-Var codecs exist in practice... and what are there blocksizes like? // if its less than 128 we should set that as max and use byte? @@ -105,19 +106,23 @@ public abstract class VariableIntBlockIndexOutput extends IntIndexOutput { @Override public void write(int v) throws IOException { + hitExcDuringWrite = true; upto -= add(v)-1; + hitExcDuringWrite = false; assert upto >= 0; } @Override public void close() throws IOException { try { - // stuff 0s in until the "real" data is flushed: - int stuffed = 0; - while(upto > stuffed) { - upto -= add(0)-1; - assert upto >= 0; - stuffed += 1; + if (!hitExcDuringWrite) { + // stuff 0s in until the "real" data is flushed: + int stuffed = 0; + while(upto > stuffed) { + upto -= add(0)-1; + assert upto >= 0; + stuffed += 1; + } } } finally { out.close();