From 8b6c2ebf42b6ed4e2c9fced2e29a31483d9ac840 Mon Sep 17 00:00:00 2001 From: Aditya Agarwal Date: Fri, 31 Aug 2007 07:54:40 +0000 Subject: [PATCH] -- 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 --- lib/cpp/src/transport/TFileTransport.cpp | 5 +++++ 1 file changed, 5 insertions(+) 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"); -- 2.17.1