From 32bfbfe380fb576f5da812b285ceeb1551075e91 Mon Sep 17 00:00:00 2001 From: Yonik Seeley Date: Thu, 10 Nov 2011 17:23:42 +0000 Subject: [PATCH] add more asserts to catch EOF, ensure that tlog files start at pos 0 git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1200438 13f79535-47bb-0310-9956-ffa450edef68 --- .../org/apache/solr/update/FSUpdateLog.java | 25 ++++++++++++------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/solr/core/src/java/org/apache/solr/update/FSUpdateLog.java b/solr/core/src/java/org/apache/solr/update/FSUpdateLog.java index f945cdd2bd9..2f260f47c14 100644 --- a/solr/core/src/java/org/apache/solr/update/FSUpdateLog.java +++ b/solr/core/src/java/org/apache/solr/update/FSUpdateLog.java @@ -355,7 +355,6 @@ class TransactionLog { OutputStream os; FastOutputStream fos; InputStream is; - long start; volatile boolean deleteOnClose = true; // we can delete old tlogs since they are currently only used for real-time-get (and in the future, recovery) @@ -417,7 +416,7 @@ class TransactionLog { public long writeData(Object o) { LogCodec codec = new LogCodec(); try { - long pos = start + fos.size(); // if we had flushed, this should be equal to channel.position() + long pos = fos.size(); // if we had flushed, this should be equal to channel.position() codec.init(fos); codec.writeVal(o); return pos; @@ -430,7 +429,12 @@ class TransactionLog { try { this.tlogFile = tlogFile; raf = new RandomAccessFile(this.tlogFile, "rw"); - start = raf.length(); + long start = raf.length(); + assert start==0; + if (start > 0) { + raf.setLength(0); + start = 0; + } // System.out.println("###start= "+start); channel = raf.getChannel(); os = Channels.newOutputStream(channel); @@ -474,12 +478,12 @@ class TransactionLog { LogCodec codec = new LogCodec(); synchronized (fos) { try { - long pos = start + fos.size(); // if we had flushed, this should be equal to channel.position() + long pos = fos.size(); // if we had flushed, this should be equal to channel.position() SolrInputDocument sdoc = cmd.getSolrInputDocument(); if (pos == 0) { // TODO: needs to be changed if we start writing a header first addGlobalStrings(sdoc.getFieldNames()); - pos = start + fos.size(); + pos = fos.size(); } /*** @@ -496,6 +500,7 @@ class TransactionLog { codec.writeSolrInputDocument(cmd.getSolrInputDocument()); // fos.flushBuffer(); // flush later + assert pos < fos.size(); return pos; } catch (IOException e) { throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, e); @@ -507,10 +512,10 @@ class TransactionLog { LogCodec codec = new LogCodec(); synchronized (fos) { try { - long pos = start + fos.size(); // if we had flushed, this should be equal to channel.position() + long pos = fos.size(); // if we had flushed, this should be equal to channel.position() if (pos == 0) { writeLogHeader(codec); - pos = start + fos.size(); + pos = fos.size(); } codec.init(fos); codec.writeTag(JavaBinCodec.ARR, 3); @@ -519,6 +524,7 @@ class TransactionLog { BytesRef br = cmd.getIndexedId(); codec.writeByteArray(br.bytes, br.offset, br.length); // fos.flushBuffer(); // flush later + assert pos < fos.size(); return pos; } catch (IOException e) { throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, e); @@ -530,10 +536,10 @@ class TransactionLog { LogCodec codec = new LogCodec(); synchronized (fos) { try { - long pos = start + fos.size(); // if we had flushed, this should be equal to channel.position() + long pos = fos.size(); // if we had flushed, this should be equal to channel.position() if (pos == 0) { writeLogHeader(codec); - pos = start + fos.size(); + pos = fos.size(); } codec.init(fos); codec.writeTag(JavaBinCodec.ARR, 3); @@ -541,6 +547,7 @@ class TransactionLog { codec.writeLong(0); // the version... should also just be one byte if 0 codec.writeStr(cmd.query); // fos.flushBuffer(); // flush later + assert pos < fos.size(); return pos; } catch (IOException e) { throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, e);