-- reset all state when seeking to a chunk
Summary:
- this was causing some bizarre issues with seeking to a particular point in the log
- I can't believe we haven't run into this before
Reviewed By: jwang
Test Plan: replayed log file from a partiicular point
git-svn-id: https://svn.apache.org/repos/asf/incubator/thrift/trunk@665242 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/lib/cpp/src/transport/TFileTransport.cpp b/lib/cpp/src/transport/TFileTransport.cpp
index 56c8c92..191ec25 100644
--- a/lib/cpp/src/transport/TFileTransport.cpp
+++ b/lib/cpp/src/transport/TFileTransport.cpp
@@ -499,6 +499,7 @@
// read error
if (readState_.bufferLen_ == -1) {
readState_.resetAllValues();
+ currentEvent_ = NULL;
GlobalOutput("TFileTransport: error while reading from file");
throw TTransportException("TFileTransport: error while reading from file");
} else if (readState_.bufferLen_ == 0) { // EOF
@@ -509,11 +510,13 @@
} else if (readTimeout_ == NO_TAIL_READ_TIMEOUT) {
// reset state
readState_.resetState(0);
+ currentEvent_ = NULL;
return false;
} else if (readTimeout_ > 0) {
// timeout already expired once
if (readTries > 0) {
readState_.resetState(0);
+ currentEvent_ = NULL;
return false;
} else {
usleep(readTimeout_ * 1000);
@@ -652,6 +655,7 @@
// pretty hosed at this stage, rewind the file back to the last successful
// point and punt on the error
readState_.resetState(readState_.lastDispatchPtr_);
+ currentEvent_ = NULL;
char errorMsg[1024];
sprintf(errorMsg, "TFileTransport: log file corrupted at offset: %lu",
offset_ + readState_.lastDispatchPtr_);
@@ -699,6 +703,7 @@
off_t newOffset = off_t(chunk) * chunkSize_;
offset_ = lseek(fd_, newOffset, SEEK_SET);
readState_.resetAllValues();
+ currentEvent_ = NULL;
if (offset_ == -1) {
GlobalOutput("TFileTransport: lseek error in seekToChunk");
throw TTransportException("TFileTransport: lseek error in seekToChunk");