From: Aditya Agarwal Date: Fri, 31 Aug 2007 07:54:40 +0000 (+0000) Subject: -- reset all state when seeking to a chunk X-Git-Tag: 0.2.0~1230 X-Git-Url: https://source.supwisdom.com/gerrit/gitweb?a=commitdiff_plain;h=8b6c2ebf42b6ed4e2c9fced2e29a31483d9ac840;p=common%2Fthrift.git -- 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 56c8c926..191ec259 100644 --- a/lib/cpp/src/transport/TFileTransport.cpp +++ b/lib/cpp/src/transport/TFileTransport.cpp @@ -499,6 +499,7 @@ bool TFileTransport::readEvent() { // 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 @@ bool TFileTransport::readEvent() { } 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 @@ void TFileTransport::performRecovery() { // 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 @@ void TFileTransport::seekToChunk(int32_t chunk) { 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");