From ec9cfe7eb71a9e4938b78419ca1e68b00ecfbb86 Mon Sep 17 00:00:00 2001 From: Annapurna Date: Thu, 14 Feb 2013 17:00:59 +0530 Subject: [PATCH] closing fileSys is file openWrite/flush fails --- src/HdfsFile.cpp | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/src/HdfsFile.cpp b/src/HdfsFile.cpp index 010c8119..cbf98e9d 100644 --- a/src/HdfsFile.cpp +++ b/src/HdfsFile.cpp @@ -47,6 +47,8 @@ bool HdfsFile::openRead() { if (hfile) { LOG_OPER("[hdfs] opened for read %s", filename.c_str()); return true; + } else { + close(); } return false; } @@ -78,7 +80,11 @@ bool HdfsFile::openWrite() { LOG_OPER("[hdfs] opened for write %s", filename.c_str()); } return true; + } else { + LOG_OPER("[hdfs] Failed to openWrite() hdfs file [%s]", filename.c_str()); + close(); } + return false; } @@ -105,7 +111,10 @@ void HdfsFile::close() { // Close the file system LOG_OPER("[hdfs] disconnecting fileSys for %s", filename.c_str()); - hdfsDisconnect(fileSys); + int retval = hdfsDisconnect(fileSys); + if(retval != 0) { + LOG_OPER("[hdfs] Failed to disconnect filesystem for [%s]", filename.c_str()); + } LOG_OPER("[hdfs] disconnected fileSys for %s", filename.c_str()); fileSys = 0; } @@ -125,7 +134,8 @@ bool HdfsFile::write(const std::string& data) { if (retVal) { int val = hdfsHFlush(fileSys, hfile); if (val == -1) { - LOG_OPER("[hdfs] flush failed"); + LOG_OPER("[hdfs] flush failed, closing file [%s]", filename.c_str()); + close(); retVal = false; } } @@ -134,7 +144,11 @@ bool HdfsFile::write(const std::string& data) { void HdfsFile::flush() { if (hfile) { - hdfsHFlush(fileSys, hfile); + int val = hdfsHFlush(fileSys, hfile); + if (val == -1) { + LOG_OPER("[hdfs] flush failed, closing file %s", filename.c_str()); + close(); + } } }