List:Commits« Previous MessageNext Message »
From:Stewart Smith Date:November 2 2006 3:12pm
Subject:bk commit into 5.1 tree (stewart:1.2336) BUG#22313
View as plain text  
Below is the list of changes that have just been committed into a local
5.1 repository of stewart. When stewart does a push these changes will
be propagated to the main repository and, within 24 hours after the
push, to the public repository.
For information on how to access the public repository
see http://dev.mysql.com/doc/mysql/en/installing-source-tree.html

ChangeSet@stripped, 2006-11-03 01:12:30+11:00, stewart@willster.(none) +4 -0
  BUG#22309  	FileLogHandler::createNewFile() isn't thread safe - may loose log messages
  BUG#22305  	SysLogHandler not thread safe
  BUG#22313  	can get duplicate log messages in cluster log
  
  Fix all these problems with one patch. Make Logger, hence EventLogger (with a 
  bit more) thread safe.

  storage/ndb/include/debugger/EventLogger.hpp@stripped, 2006-11-03 01:12:26+11:00,
stewart@willster.(none) +0 -1
    remove m_text to make thread safe

  storage/ndb/include/logger/Logger.hpp@stripped, 2006-11-03 01:12:26+11:00,
stewart@willster.(none) +4 -0
    Use mutex to protect member variables for multithreaded use.

  storage/ndb/src/common/debugger/EventLogger.cpp@stripped, 2006-11-03 01:12:26+11:00,
stewart@willster.(none) +9 -12
    use a string on the stack instead of member variable to make class thread safe

  storage/ndb/src/common/logger/Logger.cpp@stripped, 2006-11-03 01:12:27+11:00,
stewart@willster.(none) +21 -1
    use mutexes to Guard member variables. makes class therad safe

# This is a BitKeeper patch.  What follows are the unified diffs for the
# set of deltas contained in the patch.  The rest of the patch, the part
# that BitKeeper cares about, is below these diffs.
# User:	stewart
# Host:	willster.(none)
# Root:	/home/stewart/Documents/MySQL/5.1/ndb-mgm-work

--- 1.11/storage/ndb/include/debugger/EventLogger.hpp	2005-09-15 18:42:02 +10:00
+++ 1.12/storage/ndb/include/debugger/EventLogger.hpp	2006-11-03 01:12:26 +11:00
@@ -172,7 +172,6 @@
   Uint32 m_filterLevel;
 
   STATIC_CONST(MAX_TEXT_LENGTH = 256);
-  char m_text[MAX_TEXT_LENGTH];
 };
 
 

--- 1.8/storage/ndb/include/logger/Logger.hpp	2006-02-03 07:20:21 +11:00
+++ 1.9/storage/ndb/include/logger/Logger.hpp	2006-11-03 01:12:26 +11:00
@@ -276,6 +276,8 @@
 
 protected:
 
+  NdbMutex *m_mutex;
+
   void log(LoggerLevel logLevel, const char* msg, va_list ap) const;
 
 private:
@@ -290,7 +292,9 @@
   
   LogHandlerList* m_pHandlerList;
   const char* m_pCategory;
+
   /* Default handlers */
+  NdbMutex *m_handler_mutex;
   LogHandler* m_pConsoleHandler;
   LogHandler* m_pFileHandler;
   LogHandler* m_pSyslogHandler;

--- 1.28/storage/ndb/src/common/debugger/EventLogger.cpp	2006-10-13 20:10:18 +10:00
+++ 1.29/storage/ndb/src/common/debugger/EventLogger.cpp	2006-11-03 01:12:26 +11:00
@@ -1004,6 +1004,7 @@
   Logger::LoggerLevel severity = Logger::LL_WARNING;
   LogLevel::EventCategory cat= LogLevel::llInvalid;
   EventTextFunction textF;
+  char log_text[MAX_TEXT_LENGTH];
 
   DBUG_ENTER("EventLogger::log");
   DBUG_PRINT("enter",("eventType=%d, nodeid=%d", eventType, nodeId));
@@ -1017,29 +1018,29 @@
     DBUG_PRINT("info",("m_logLevel.getLogLevel=%d", m_logLevel.getLogLevel(cat)));
 
   if (threshold <= set){
-    getText(m_text,sizeof(m_text),textF,theData,nodeId);
+    getText(log_text,sizeof(log_text),textF,theData,nodeId);
 
     switch (severity){
     case Logger::LL_ALERT:
-      alert(m_text);
+      alert(log_text);
       break;
     case Logger::LL_CRITICAL:
-      critical(m_text); 
+      critical(log_text); 
       break;
     case Logger::LL_WARNING:
-      warning(m_text); 
+      warning(log_text); 
       break;
     case Logger::LL_ERROR:
-      error(m_text); 
+      error(log_text); 
       break;
     case Logger::LL_INFO:
-      info(m_text); 
+      info(log_text); 
       break;
     case Logger::LL_DEBUG:
-      debug(m_text); 
+      debug(log_text); 
       break;
     default:
-      info(m_text); 
+      info(log_text); 
       break;
     }
   } // if (..
@@ -1057,7 +1058,3 @@
 {
   m_filterLevel = filterLevel;
 }
-
-//
-// PRIVATE
-//

--- 1.14/storage/ndb/src/common/logger/Logger.cpp	2006-02-03 07:20:21 +11:00
+++ 1.15/storage/ndb/src/common/logger/Logger.cpp	2006-11-03 01:12:27 +11:00
@@ -46,6 +46,8 @@
   m_pSyslogHandler(NULL)
 {
   m_pHandlerList = new LogHandlerList();
+  m_mutex= NdbMutex_Create();
+  m_handler_mutex= NdbMutex_Create();
   disable(LL_ALL);
   enable(LL_ON);
   enable(LL_INFO);
@@ -53,20 +55,25 @@
 
 Logger::~Logger()
 {
-  removeAllHandlers();  
+  removeAllHandlers();
   delete m_pHandlerList;
+  NdbMutex_Destroy(m_handler_mutex);
+  NdbMutex_Destroy(m_mutex);
 }
 
 void 
 Logger::setCategory(const char* pCategory)
 {
+  Guard g(m_mutex);
   m_pCategory = pCategory;
 }
 
 bool
 Logger::createConsoleHandler()
 {
+  Guard g(m_handler_mutex);
   bool rc = true;
+
   if (m_pConsoleHandler == NULL)
   {
     m_pConsoleHandler = new ConsoleLogHandler(); 
@@ -84,6 +91,7 @@
 void 
 Logger::removeConsoleHandler()
 {
+  Guard g(m_handler_mutex);
   if (removeHandler(m_pConsoleHandler))
   {
     m_pConsoleHandler = NULL;
@@ -93,6 +101,7 @@
 bool
 Logger::createFileHandler()
 {
+  Guard g(m_handler_mutex);
   bool rc = true;
   if (m_pFileHandler == NULL)
   {
@@ -111,6 +120,7 @@
 void 
 Logger::removeFileHandler()
 {
+  Guard g(m_handler_mutex);
   if (removeHandler(m_pFileHandler))
   {
     m_pFileHandler = NULL;
@@ -120,6 +130,7 @@
 bool
 Logger::createSyslogHandler()
 {
+  Guard g(m_handler_mutex);
   bool rc = true;
   if (m_pSyslogHandler == NULL)
   {
@@ -142,6 +153,7 @@
 void 
 Logger::removeSyslogHandler()
 {
+  Guard g(m_handler_mutex);
   if (removeHandler(m_pSyslogHandler))
   {
     m_pSyslogHandler = NULL;
@@ -151,6 +163,7 @@
 bool
 Logger::addHandler(LogHandler* pHandler)
 {
+  Guard g(m_mutex);
   assert(pHandler != NULL);
 
   bool rc = pHandler->open();	
@@ -224,6 +237,7 @@
 bool
 Logger::removeHandler(LogHandler* pHandler)
 {
+  Guard g(m_mutex);
   int rc = false;
   if (pHandler != NULL)
   {
@@ -236,12 +250,14 @@
 void
 Logger::removeAllHandlers()
 {
+  Guard g(m_mutex);
   m_pHandlerList->removeAll();
 }
 
 bool
 Logger::isEnable(LoggerLevel logLevel) const
 {
+  Guard g(m_mutex);
   if (logLevel == LL_ALL)
   {
     for (unsigned i = 1; i < MAX_LOG_LEVELS; i++)
@@ -255,6 +271,7 @@
 void
 Logger::enable(LoggerLevel logLevel)
 {
+  Guard g(m_mutex);
   if (logLevel == LL_ALL)
   {
     for (unsigned i = 0; i < MAX_LOG_LEVELS; i++)
@@ -271,6 +288,7 @@
 void 
 Logger::enable(LoggerLevel fromLogLevel, LoggerLevel toLogLevel)
 {
+  Guard g(m_mutex);
   if (fromLogLevel > toLogLevel)
   {
     LoggerLevel tmp = toLogLevel;
@@ -287,6 +305,7 @@
 void
 Logger::disable(LoggerLevel logLevel)
 {
+  Guard g(m_mutex);
   if (logLevel == LL_ALL)
   {
     for (unsigned i = 0; i < MAX_LOG_LEVELS; i++)
@@ -359,6 +378,7 @@
 void 
 Logger::log(LoggerLevel logLevel, const char* pMsg, va_list ap) const
 {
+  Guard g(m_mutex);
   if (m_logLevels[LL_ON] && m_logLevels[logLevel])
   {
     char buf[MAX_LOG_MESSAGE_SIZE];
Thread
bk commit into 5.1 tree (stewart:1.2336) BUG#22313Stewart Smith2 Nov