From 4e7cad0fd4dc57372ddce8d05bc0bf01521221e0 Mon Sep 17 00:00:00 2001 From: "dli@dev3-76.dev.cn.tlan" <> Date: Tue, 29 Aug 2006 09:55:07 +0800 Subject: [PATCH] Fix for bug #21345: Error in cluster logfile rotation. Fixed the cluster logfile rotation code, let the cluster log file be renamed correctly when the main log file exceeds the configured maximum size. --- ndb/include/util/File.hpp | 8 ++++++++ ndb/src/common/logger/FileLogHandler.cpp | 11 ++++++++++- ndb/src/common/util/File.cpp | 12 ++++++++++++ 3 files changed, 30 insertions(+), 1 deletion(-) diff --git a/ndb/include/util/File.hpp b/ndb/include/util/File.hpp index 3ed0ad7a6f9..52b00f575f4 100644 --- a/ndb/include/util/File.hpp +++ b/ndb/include/util/File.hpp @@ -28,6 +28,14 @@ class File_class { public: + /** + * Returns time for last contents modification of a file. + * + * @param aFileName a filename to check. + * @return the time for last contents modificaton of the file. + */ + static time_t mtime(const char* aFileName); + /** * Returns true if the file exist. * diff --git a/ndb/src/common/logger/FileLogHandler.cpp b/ndb/src/common/logger/FileLogHandler.cpp index 3d29e63ac1f..b8859630406 100644 --- a/ndb/src/common/logger/FileLogHandler.cpp +++ b/ndb/src/common/logger/FileLogHandler.cpp @@ -147,6 +147,7 @@ FileLogHandler::createNewFile() bool rc = true; int fileNo = 1; char newName[PATH_MAX]; + time_t newMtime, preMtime = 0; do { @@ -159,7 +160,15 @@ FileLogHandler::createNewFile() } BaseString::snprintf(newName, sizeof(newName), "%s.%d", m_pLogFile->getName(), fileNo++); - + newMtime = File_class::mtime(newName); + if (newMtime < preMtime) + { + break; + } + else + { + preMtime = newMtime; + } } while (File_class::exists(newName)); m_pLogFile->close(); diff --git a/ndb/src/common/util/File.cpp b/ndb/src/common/util/File.cpp index e514ad8e122..12626f29e7d 100644 --- a/ndb/src/common/util/File.cpp +++ b/ndb/src/common/util/File.cpp @@ -24,6 +24,18 @@ // // PUBLIC // +time_t +File_class::mtime(const char* aFileName) +{ + MY_STAT stmp; + time_t rc = 0; + + if (my_stat(aFileName, &stmp, MYF(0)) != NULL) { + rc = stmp.st_mtime; + } + + return rc; +} bool File_class::exists(const char* aFileName)