List:Commits« Previous MessageNext Message »
From:Olav Sandstaa Date:March 5 2009 1:10pm
Subject:bzr commit into mysql-6.0-falcon-team branch (olav:3051) Bug#40155
View as plain text  
#At file:///home/os136802/mysql/develop/repo/falcon-bug40155/ based on revid:olav@stripped

 3051 Olav Sandstaa	2009-03-05
      Fix to Bug #40155 Error: assertion (ret == 0) failed at line 80 in file Mutex.cpp
            
      This crash was due to the Memory manager trying to lock the same mutex twice. It happened
      when the server run out of memory. The memory manager handles this by throwing an exception.
      Unfortunatly, when creating this exception there there was call both the JString and the
      Log class that did allocate memory leading to the second call to the memory manager's
      mutex.
            
      This patch fixes this by:
            
      -SQLError use an new method on JString that does not allocate memory for the text
       but just stores the pointer to the existing string
      -Simplified SQLError's use of the Log if the error is out-of-memory
     @ storage/falcon/JString.cpp
        Support for using an external string instead of copying the string to an internal buffer. 
        This is done to avoid having to allocate space in the JString object in situations where
        Falcon have run out of memory.
     @ storage/falcon/JString.h
        Add a method for setting the JSTring's string to use an externally allocated string
     @ storage/falcon/SQLError.cpp
        Special handle the OUT_OF_MEMORY_ERROR code so that this is handled without allocating memory.
     @ storage/falcon/SQLError.h
        Add the sql error code as a paramter to the error method.

    modified:
      storage/falcon/JString.cpp
      storage/falcon/JString.h
      storage/falcon/SQLError.cpp
      storage/falcon/SQLError.h
=== modified file 'storage/falcon/JString.cpp'
--- a/storage/falcon/JString.cpp	2008-04-09 01:36:46 +0000
+++ b/storage/falcon/JString.cpp	2009-03-05 13:10:34 +0000
@@ -56,6 +56,7 @@ JString::JString ()
  **************************************/
 
 	string = NULL;
+	isStaticString = false;
 }
 
 JString::JString (const char *stuff)
@@ -72,6 +73,7 @@ JString::JString (const char *stuff)
  **************************************/
 
 	string = NULL;
+	isStaticString = false;
 	setString (stuff);
 }
 
@@ -90,6 +92,7 @@ JString::JString (const JString& source)
 
 	if ((string = source.string))
 		++((int*) string)[-1];
+	isStaticString = false;
 }
 
 JString::~JString ()
@@ -349,6 +352,13 @@ void JString::release ()
 	if (!string)
 		return;
 
+	if (isStaticString)
+		{
+		string = NULL;
+		isStaticString = false;
+		return;
+		}
+
 	string -= sizeof (int);
 
 	if (--((int*) string)[0] == 0)
@@ -469,6 +479,13 @@ void JString::setString(const char * sou
 {
 	alloc (length);
 	memcpy (string, source, length);
+	isStaticString = false;
+}
+
+void JString::setStringStatic(const char* source)
+{
+	string = const_cast<char*>(source);
+	isStaticString = true;
 }
 
 int JString::findSubstring(const char * string, const char * sub)

=== modified file 'storage/falcon/JString.h'
--- a/storage/falcon/JString.h	2007-10-23 20:50:22 +0000
+++ b/storage/falcon/JString.h	2009-03-05 13:10:34 +0000
@@ -130,6 +130,7 @@ public:
 	void		append (const char*, int length);
 	void		setString (const char*);
 	void		setString (const char *source, int length);
+	void 		setStringStatic (const char *source);
 	void		Format (const char*, ...);
 	
 	inline const char	*getString()
@@ -155,6 +156,7 @@ protected:
 	void	release();
 
 	char	*string;
+	bool	isStaticString;
 };
 
 

=== modified file 'storage/falcon/SQLError.cpp'
--- a/storage/falcon/SQLError.cpp	2008-06-19 15:09:45 +0000
+++ b/storage/falcon/SQLError.cpp	2009-03-05 13:10:34 +0000
@@ -59,8 +59,15 @@ SQLError::SQLError (SqlCode code, const 
 	if (vsnprintf (temp, sizeof (temp) - 1, txt, args) < 0)
 		temp [sizeof (temp) - 1] = 0;
 
-	text = temp;
-	error (temp);
+	// Special handle how we deal with the error string for out-of-memory
+	// errors by using a static JString method to avoid memory allocations
+
+	if (code != OUT_OF_MEMORY_ERROR)
+		text = temp;
+	else
+		text.setStringStatic(txt);
+
+	error (code, temp);
 	sqlcode = (int) code;
 }
 
@@ -76,6 +83,8 @@ SQLError::SQLError(const char *trace, in
  *		SQL exception -- quite generic.
  *
  **************************************/
+	ASSERT(code != OUT_OF_MEMORY_ERROR);
+
 	va_list		args;
 	va_start	(args, txt);
 	char		temp [1024];
@@ -88,7 +97,7 @@ SQLError::SQLError(const char *trace, in
 		temp [sizeof (temp) - 1] = 0;
 
 	text = temp;
-	error (temp);
+	error (code, temp);
 	sqlcode = (int) code;
 }
 
@@ -166,7 +175,7 @@ SQLError::SQLError(int code, const char 
 		temp [sizeof (temp) - 1] = 0;
 
 	text = temp;
-	error (temp);
+	error (code, temp);
 	sqlcode = (int) code;
 }
 
@@ -175,11 +184,25 @@ const char* SQLError::getTrace()
 	return stackTrace;
 }
 
-void SQLError::error(const char *string)
+void SQLError::error(int code, const char *string)
 {
 #ifdef FALCONDB
-	LogLock logLock;
-	Log::log(LogException, "Exception: %s\n", string);
+	if (Log::isActive(LogException))
+		{
+		// We special handle out-memory-errors in order to reduce the
+		// likelyhood that a call to the Log will generate a new call
+		// back to the memory manager
+
+		if (code != OUT_OF_MEMORY_ERROR)
+			{
+			LogLock logLock;
+			Log::log(LogException, "Exception: %s\n", string);
+			}
+		else
+			{
+			Log::log(LogException, "Exception: OUT OF MEMORY ERROR");
+			}
+		}
 #endif
 }
 

=== modified file 'storage/falcon/SQLError.h'
--- a/storage/falcon/SQLError.h	2007-09-20 15:44:25 +0000
+++ b/storage/falcon/SQLError.h	2009-03-05 13:10:34 +0000
@@ -53,7 +53,7 @@ public:
 	JString		objectName;
 
 private:
-	void error (const char *string);
+	void error (int sqlcode, const char *string);
     };
 
 #endif


Attachment: [text/bzr-bundle] bzr/olav@sun.com-20090305131034-lluxk87dhtcqrs1g.bundle
Thread
bzr commit into mysql-6.0-falcon-team branch (olav:3051) Bug#40155Olav Sandstaa5 Mar