Commit 238ffd1e authored by Flavio Paiva Junqueira's avatar Flavio Paiva Junqueira
Browse files

ZOOKEEPER-1844. TruncateTest fails on windows (Rakesh R via fpj)



git-svn-id: https://svn.apache.org/repos/asf/zookeeper/branches/branch-3.4@1567661 13f79535-47bb-0310-9956-ffa450edef68
parent 6a872142
......@@ -244,6 +244,8 @@ BUGFIXES:
ZOOKEEPER-1873. Unnecessarily InstanceNotFoundException is coming when
unregister failed jmxbeans (Rakesh R via michim)
ZOOKEEPER-1844. TruncateTest fails on windows (Rakesh R via fpj)
IMPROVEMENTS:
ZOOKEEPER-1564. Allow JUnit test build with IBM Java
......
......@@ -285,9 +285,10 @@ public class FileTxnLog implements TxnLog {
// if a log file is more recent we must scan it to find
// the highest zxid
long zxid = maxLog;
TxnIterator itr = null;
try {
FileTxnLog txn = new FileTxnLog(logDir);
TxnIterator itr = txn.read(maxLog);
itr = txn.read(maxLog);
while (true) {
if(!itr.next())
break;
......@@ -296,10 +297,22 @@ public class FileTxnLog implements TxnLog {
}
} catch (IOException e) {
LOG.warn("Unexpected exception", e);
} finally {
close(itr);
}
return zxid;
}
private void close(TxnIterator itr) {
if (itr != null) {
try {
itr.close();
} catch (IOException ioe) {
LOG.warn("Error closing file iterator", ioe);
}
}
}
/**
* commit the logs. make sure that evertyhing hits the
* disk
......@@ -347,17 +360,22 @@ public class FileTxnLog implements TxnLog {
* @return true if successful false if not
*/
public boolean truncate(long zxid) throws IOException {
FileTxnIterator itr = new FileTxnIterator(this.logDir, zxid);
PositionInputStream input = itr.inputStream;
long pos = input.getPosition();
// now, truncate at the current position
RandomAccessFile raf=new RandomAccessFile(itr.logFile,"rw");
raf.setLength(pos);
raf.close();
while(itr.goToNextLog()) {
if (!itr.logFile.delete()) {
LOG.warn("Unable to truncate " + itr.logFile);
FileTxnIterator itr = null;
try {
itr = new FileTxnIterator(this.logDir, zxid);
PositionInputStream input = itr.inputStream;
long pos = input.getPosition();
// now, truncate at the current position
RandomAccessFile raf = new RandomAccessFile(itr.logFile, "rw");
raf.setLength(pos);
raf.close();
while (itr.goToNextLog()) {
if (!itr.logFile.delete()) {
LOG.warn("Unable to truncate {}", itr.logFile);
}
}
} finally {
close(itr);
}
return true;
}
......@@ -657,7 +675,9 @@ public class FileTxnLog implements TxnLog {
* and release the resources.
*/
public void close() throws IOException {
inputStream.close();
if (inputStream != null) {
inputStream.close();
}
}
}
......
......@@ -132,30 +132,36 @@ public class FileTxnSnapLog {
TxnIterator itr = txnLog.read(dt.lastProcessedZxid+1);
long highestZxid = dt.lastProcessedZxid;
TxnHeader hdr;
while (true) {
// iterator points to
// the first valid txn when initialized
hdr = itr.getHeader();
if (hdr == null) {
//empty logs
return dt.lastProcessedZxid;
try {
while (true) {
// iterator points to
// the first valid txn when initialized
hdr = itr.getHeader();
if (hdr == null) {
//empty logs
return dt.lastProcessedZxid;
}
if (hdr.getZxid() < highestZxid && highestZxid != 0) {
LOG.error("{}(higestZxid) > {}(next log) for type {}",
new Object[] { highestZxid, hdr.getZxid(),
hdr.getType() });
} else {
highestZxid = hdr.getZxid();
}
try {
processTransaction(hdr,dt,sessions, itr.getTxn());
} catch(KeeperException.NoNodeException e) {
throw new IOException("Failed to process transaction type: " +
hdr.getType() + " error: " + e.getMessage(), e);
}
listener.onTxnLoaded(hdr, itr.getTxn());
if (!itr.next())
break;
}
if (hdr.getZxid() < highestZxid && highestZxid != 0) {
LOG.error(highestZxid + "(higestZxid) > "
+ hdr.getZxid() + "(next log) for type "
+ hdr.getType());
} else {
highestZxid = hdr.getZxid();
} finally {
if (itr != null) {
itr.close();
}
try {
processTransaction(hdr,dt,sessions, itr.getTxn());
} catch(KeeperException.NoNodeException e) {
throw new IOException("Failed to process transaction type: " +
hdr.getType() + " error: " + e.getMessage(), e);
}
listener.onTxnLoaded(hdr, itr.getTxn());
if (!itr.next())
break;
}
return highestZxid;
}
......
......@@ -111,6 +111,8 @@ public class TruncateTest extends ZKTestCase {
txn = iter.getTxn();
Assert.assertEquals(200, hdr.getZxid());
Assert.assertTrue(txn instanceof SetDataTxn);
iter.close();
ClientBase.recursiveDelete(tmpdir);
}
private void append(ZKDatabase zkdb, int i) throws IOException {
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment