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(); + } } }