From 9bd1494287093fa1e08fe8cb95f0e62b30dfc192 Mon Sep 17 00:00:00 2001 From: Ming LI Date: Thu, 4 Feb 2016 11:47:21 +0800 Subject: [PATCH] HAWQ-396. Fixed crashed at nested error report calling when close temp file at AbortTransaction() --- src/backend/executor/execWorkfile.c | 2 +- src/backend/storage/file/bfz.c | 6 +++--- src/backend/storage/file/fd.c | 20 ++++++++------------ src/include/storage/bfz.h | 2 +- src/include/storage/fd.h | 2 +- 5 files changed, 14 insertions(+), 18 deletions(-) diff --git a/src/backend/executor/execWorkfile.c b/src/backend/executor/execWorkfile.c index 05adea8984..ca65c428ff 100644 --- a/src/backend/executor/execWorkfile.c +++ b/src/backend/executor/execWorkfile.c @@ -463,7 +463,7 @@ ExecWorkFile_Close(ExecWorkFile *workfile) ExecWorkFile_AdjustBFZSize(workfile, file_size); } - bfz_close(bfz_file, true); + bfz_close(bfz_file, true, true); break; default: insist_log(false, "invalid work file type: %d", workfile->fileType); diff --git a/src/backend/storage/file/bfz.c b/src/backend/storage/file/bfz.c index 3654611e29..0599896f88 100644 --- a/src/backend/storage/file/bfz.c +++ b/src/backend/storage/file/bfz.c @@ -81,7 +81,7 @@ bfz_string_to_compression(const char *string) static void bfz_close_callback(XactEvent event, void *arg) { - bfz_close(arg, false); + bfz_close(arg, false, (event!=XACT_EVENT_ABORT)); } #define BFZ_CHECKSUM_EQ(c1, c2) EQ_CRC32(c1, c2) @@ -438,7 +438,7 @@ bfz_create_internal(bfz_t *bfz_handle, const char *fileName, bool open_existing, } void -bfz_close(bfz_t * thiz, bool unreg) +bfz_close(bfz_t * thiz, bool unreg, bool canReportError) { if (unreg) UnregisterXactCallbackOnce(bfz_close_callback, thiz); @@ -461,7 +461,7 @@ bfz_close(bfz_t * thiz, bool unreg) if (thiz->del_on_close && thiz->filename != NULL) { if (unlink(thiz->filename)) - ereport(ERROR, + ereport(canReportError?ERROR:WARNING, (errcode(ERRCODE_IO_ERROR), errmsg("could not close temporary file %s: %m", thiz->filename))); pfree(thiz->filename); diff --git a/src/backend/storage/file/fd.c b/src/backend/storage/file/fd.c index 57299419a9..1037a66843 100644 --- a/src/backend/storage/file/fd.c +++ b/src/backend/storage/file/fd.c @@ -1209,7 +1209,7 @@ OpenNamedFile(const char *fileName, * close a file when done with it */ void -LocalFileClose(File file) +LocalFileClose(File file, bool canReportError) { Vfd *vfdP; @@ -1227,7 +1227,7 @@ LocalFileClose(File file) /* close the file */ if (gp_retry_close(vfdP->fd)) - elog(ERROR, "could not close file \"%s\": %m", + elog(canReportError?ERROR:WARNING, "could not close file \"%s\": %m", vfdP->fileName); --nfile; @@ -2130,7 +2130,7 @@ CleanupTempFiles(bool isProcExit) { AssertImply( (fdstate & FD_TEMPORARY), VfdCache[i].fileName != NULL); if (IsLocalPath(VfdCache[i].fileName)) - LocalFileClose(i); + LocalFileClose(i, false); else HdfsFileClose(i, false); } @@ -2725,14 +2725,10 @@ HdfsFileClose(File file, bool canReportError) if (retval == -1) { - /* do not disconnect. */ - if (canReportError) - { - ereport(ERROR, - (errcode(ERRCODE_IO_ERROR), - errmsg("could not close file %d : (%s) errno %d", file, fileName, errno), - errdetail("%s", HdfsGetLastError()))); - } + ereport(canReportError?ERROR:WARNING, + (errcode(ERRCODE_IO_ERROR), + errmsg("could not close file %d : (%s) errno %d", file, fileName, errno), + errdetail("%s", HdfsGetLastError()))); } } @@ -3160,7 +3156,7 @@ PathNameOpenFile(FileName fileName, int fileFlags, int fileMode) { void FileClose(File file) { if (IsLocalPath(VfdCache[file].fileName)) - LocalFileClose(file); + LocalFileClose(file, true); else HdfsFileClose(file, true); } diff --git a/src/include/storage/bfz.h b/src/include/storage/bfz.h index 27e718af5a..ca9b85d9bc 100644 --- a/src/include/storage/bfz.h +++ b/src/include/storage/bfz.h @@ -97,7 +97,7 @@ extern bfz_t *bfz_create(const char *filePrefix, bool delOnClose, int compress); extern bfz_t *bfz_open(const char *fileName, bool delOnClose, int compress); extern int64 bfz_append_end(bfz_t * thiz); extern void bfz_scan_begin(bfz_t * thiz); -extern void bfz_close(bfz_t * thiz, bool unreg); +extern void bfz_close(bfz_t * thiz, bool unreg, bool canReportError); extern ssize_t readAndRetry(int fd, void *buffer, size_t size); extern ssize_t writeAndRetry(int fd, const void *buffer, size_t size); diff --git a/src/include/storage/fd.h b/src/include/storage/fd.h index 2015a565b7..d611894e34 100644 --- a/src/include/storage/fd.h +++ b/src/include/storage/fd.h @@ -82,7 +82,7 @@ extern bool enable_secure_filesystem; /* access local file system */ extern File LocalPathNameOpenFile(FileName fileName, int fileFlags, int fileMode); -extern void LocalFileClose(File file); +extern void LocalFileClose(File file, bool canReportError); extern int LocalFileRead(File file, char *buffer, int amount); extern int LocalFileWrite(File file, const char *buffer, int amount); extern int64 LocalFileSeek(File file, int64 offset, int whence);