mirror of https://github.com/apache/lucene.git
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
This commit is contained in:
parent
969afcf642
commit
32bfbfe380
|
@ -355,7 +355,6 @@ class TransactionLog {
|
||||||
OutputStream os;
|
OutputStream os;
|
||||||
FastOutputStream fos;
|
FastOutputStream fos;
|
||||||
InputStream is;
|
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)
|
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) {
|
public long writeData(Object o) {
|
||||||
LogCodec codec = new LogCodec();
|
LogCodec codec = new LogCodec();
|
||||||
try {
|
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.init(fos);
|
||||||
codec.writeVal(o);
|
codec.writeVal(o);
|
||||||
return pos;
|
return pos;
|
||||||
|
@ -430,7 +429,12 @@ class TransactionLog {
|
||||||
try {
|
try {
|
||||||
this.tlogFile = tlogFile;
|
this.tlogFile = tlogFile;
|
||||||
raf = new RandomAccessFile(this.tlogFile, "rw");
|
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);
|
// System.out.println("###start= "+start);
|
||||||
channel = raf.getChannel();
|
channel = raf.getChannel();
|
||||||
os = Channels.newOutputStream(channel);
|
os = Channels.newOutputStream(channel);
|
||||||
|
@ -474,12 +478,12 @@ class TransactionLog {
|
||||||
LogCodec codec = new LogCodec();
|
LogCodec codec = new LogCodec();
|
||||||
synchronized (fos) {
|
synchronized (fos) {
|
||||||
try {
|
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();
|
SolrInputDocument sdoc = cmd.getSolrInputDocument();
|
||||||
|
|
||||||
if (pos == 0) { // TODO: needs to be changed if we start writing a header first
|
if (pos == 0) { // TODO: needs to be changed if we start writing a header first
|
||||||
addGlobalStrings(sdoc.getFieldNames());
|
addGlobalStrings(sdoc.getFieldNames());
|
||||||
pos = start + fos.size();
|
pos = fos.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
/***
|
/***
|
||||||
|
@ -496,6 +500,7 @@ class TransactionLog {
|
||||||
codec.writeSolrInputDocument(cmd.getSolrInputDocument());
|
codec.writeSolrInputDocument(cmd.getSolrInputDocument());
|
||||||
// fos.flushBuffer(); // flush later
|
// fos.flushBuffer(); // flush later
|
||||||
|
|
||||||
|
assert pos < fos.size();
|
||||||
return pos;
|
return pos;
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, e);
|
throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, e);
|
||||||
|
@ -507,10 +512,10 @@ class TransactionLog {
|
||||||
LogCodec codec = new LogCodec();
|
LogCodec codec = new LogCodec();
|
||||||
synchronized (fos) {
|
synchronized (fos) {
|
||||||
try {
|
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) {
|
if (pos == 0) {
|
||||||
writeLogHeader(codec);
|
writeLogHeader(codec);
|
||||||
pos = start + fos.size();
|
pos = fos.size();
|
||||||
}
|
}
|
||||||
codec.init(fos);
|
codec.init(fos);
|
||||||
codec.writeTag(JavaBinCodec.ARR, 3);
|
codec.writeTag(JavaBinCodec.ARR, 3);
|
||||||
|
@ -519,6 +524,7 @@ class TransactionLog {
|
||||||
BytesRef br = cmd.getIndexedId();
|
BytesRef br = cmd.getIndexedId();
|
||||||
codec.writeByteArray(br.bytes, br.offset, br.length);
|
codec.writeByteArray(br.bytes, br.offset, br.length);
|
||||||
// fos.flushBuffer(); // flush later
|
// fos.flushBuffer(); // flush later
|
||||||
|
assert pos < fos.size();
|
||||||
return pos;
|
return pos;
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, e);
|
throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, e);
|
||||||
|
@ -530,10 +536,10 @@ class TransactionLog {
|
||||||
LogCodec codec = new LogCodec();
|
LogCodec codec = new LogCodec();
|
||||||
synchronized (fos) {
|
synchronized (fos) {
|
||||||
try {
|
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) {
|
if (pos == 0) {
|
||||||
writeLogHeader(codec);
|
writeLogHeader(codec);
|
||||||
pos = start + fos.size();
|
pos = fos.size();
|
||||||
}
|
}
|
||||||
codec.init(fos);
|
codec.init(fos);
|
||||||
codec.writeTag(JavaBinCodec.ARR, 3);
|
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.writeLong(0); // the version... should also just be one byte if 0
|
||||||
codec.writeStr(cmd.query);
|
codec.writeStr(cmd.query);
|
||||||
// fos.flushBuffer(); // flush later
|
// fos.flushBuffer(); // flush later
|
||||||
|
assert pos < fos.size();
|
||||||
return pos;
|
return pos;
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, e);
|
throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, e);
|
||||||
|
|
Loading…
Reference in New Issue