Bug #49724 LockPagesInMainMemory failure should give error code
Submitted: 15 Dec 2009 20:49 Modified: 25 Jan 2010 10:24
Reporter: Andrew Hutchings Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Cluster: Cluster (NDB) storage engine Severity:S4 (Feature request)
Version: OS:Any
Assigned to: Andrew Hutchings CPU Architecture:Any
Tags: Contribution

[15 Dec 2009 20:49] Andrew Hutchings
Description:
When we use mlockall() and it fails we just return "Failed to memlock pages".  It would be nice to catch the OS error code so we can diagnose the cause of the failure.

How to repeat:
.

Suggested fix:
Report the result of strerror(errno) as follows (for EPERM):

Failed to memlock pages: Operation not permitted
[22 Jan 2010 0:20] Bugs System
A patch for this bug has been committed. After review, it may
be pushed to the relevant source trees for release in the next
version. You can access the patch from:

  http://lists.mysql.com/commits/97787

3359 Andrew Hutchings	2010-01-22
      Bug #49724  	LockPagesInMainMemory failure should give error code
      
      Add strerror(errno) to the error message, for example:
      
      2010-01-21 23:59:17 [ndbd] WARNING  -- Failed to memlock pages: Operation not permitted
[22 Jan 2010 9:30] Magnus Blåudd
Please include the raw  errno in error message as well.
[22 Jan 2010 9:52] Bugs System
A patch for this bug has been committed. After review, it may
be pushed to the relevant source trees for release in the next
version. You can access the patch from:

  http://lists.mysql.com/commits/97822

3360 Andrew Hutchings	2010-01-22
      Bug #49724  	LockPagesInMainMemory failure should give error code
      
      Add errno and strerror(errno) to the error message, for example:
      
      2010-01-22 09:48:18 [ndbd] WARNING  -- Failed to memlock pages, error: 12 (Cannot allocate memory)
[22 Jan 2010 10:40] Magnus Blåudd
Few more comments:

1) The pointer returned by 'strerror' point to an operating system buffer and may be reset/modified by functions called from g_eventLogger->warning() (it can log to console, file or syslog). Suggest allocating a buffer on the stack and formatting the message there before calling the two functions.

2) The call to 'warningEvent' will pack the message into a signal and distribute it to all event listeners(i.e it will end up in the cluster log of ndb_mgmd) -> the buffer can be limited to 100 byte since the max message length in 'warningEvent' is 96.

3) There is a tab in front of 'warningEvent', please convert it to spaces.

4) Do "bzr uncommit" two times and start from scratch 

Example:
=== modified file 'storage/ndb/src/kernel/blocks/cmvmi/Cmvmi.cpp'
--- storage/ndb/src/kernel/blocks/cmvmi/Cmvmi.cpp	2009-11-12 21:25:49 +0000
+++ storage/ndb/src/kernel/blocks/cmvmi/Cmvmi.cpp	2010-01-22 10:25:36 +0000
@@ -428,8 +428,12 @@
       refresh_watch_dog(9);
       int res = NdbMem_MemLockAll(0);
       if(res != 0){
-        g_eventLogger->warning("Failed to memlock pages");
-	warningEvent("Failed to memlock pages");
+        char buf[100];
+        BaseString::snprintf(buf, sizeof(buf),
+                             "Failed to memlock pages %d  xxxx %s",
+                             errno, strerror(errno));
+        g_eventLogger->warning("%s", buf);
+        warningEvent("%s", buf);
       }
     }
[22 Jan 2010 12:38] Bugs System
A patch for this bug has been committed. After review, it may
be pushed to the relevant source trees for release in the next
version. You can access the patch from:

  http://lists.mysql.com/commits/97868

3359 Andrew Hutchings	2010-01-22
      Bug #49724  	LockPagesInMainMemory failure should give error code
      
      Add errno and strerror(errno) to the error message, for example:
      
      2010-01-22 09:48:18 [ndbd] WARNING  -- Failed to memlock pages, error: 12 (Cannot allocate memory)
[25 Jan 2010 8:54] Bugs System
A patch for this bug has been committed. After review, it may
be pushed to the relevant source trees for release in the next
version. You can access the patch from:

  http://lists.mysql.com/commits/98016
[25 Jan 2010 8:57] Magnus Blåudd
Pushed to 6.3.31 and 7.0.11
[25 Jan 2010 10:24] Jon Stephens
Documented in the NDB-6.3.31 and 7.0.11 changelogs as follows:

      When setting LockPagesInMainMemory failed, only the error -Failed to 
      memlock pages...- was returned. Now in such cases the operating 
      system error code is also returned.

Closed.