Bug #69736 Wasted work in method NdbRestarter::waitNodesState()
Submitted: 13 Jul 2013 2:33 Modified: 16 Sep 2013 14:25
Reporter: Po-Chun Chang (OCA) Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Cluster: Cluster (NDB) storage engine Severity:S5 (Performance)
Version:5.6, 5.7 OS:Any
Assigned to: CPU Architecture:Any
Tags: patch, performance

[13 Jul 2013 2:33] Po-Chun Chang
Description:
The problem appears in version 5.6 and in the revision 5216 in version 5.7.
I attached a two-line patch that fixes it.

In method NdbRestarter::waitNodesState() in NdbRestarter.cpp, the loop in line 429 keeps overriding "ndbNode" with "&ndbNodes[n]" when 'ndbNodes[n].node_id' equals '_nodes[i]'.  Therefore, only the last written value is visible out of the loop and all the other writes and iterations are not necessary. The patch iterates from the end of "n" and breaks the first time when "ndbNode" is set.

How to repeat:
Once NdbRestarter::waitNodesState() is executed.

Suggested fix:
=== modified file 'storage/ndb/test/src/NdbRestarter.cpp'
--- storage/ndb/test/src/NdbRestarter.cpp	2013-02-26 06:21:48 +0000
+++ storage/ndb/test/src/NdbRestarter.cpp	2013-07-13 02:32:02 +0000
@@ -426,9 +426,11 @@
 
     for (int i = 0; i < _num_nodes; i++){
       ndb_mgm_node_state* ndbNode = NULL;
-      for (unsigned n = 0; n < ndbNodes.size(); n++){
-	if (ndbNodes[n].node_id == _nodes[i])
+      for (unsigned n = ndbNodes.size() - 1; n >= 0; n--){
+	if (ndbNodes[n].node_id == _nodes[i]) {
 	  ndbNode = &ndbNodes[n];
+	  break;
+	}
       }
 
       if(ndbNode == NULL){
[13 Jul 2013 2:33] Po-Chun Chang
Suggested patch

(*) I confirm the code being submitted is offered under the terms of the OCA, and that I am authorized to contribute it.

Contribution: patch.diff (text/plain), 583 bytes.

[13 Jul 2013 2:38] Po-Chun Chang
Suggested patch

(*) I confirm the code being submitted is offered under the terms of the OCA, and that I am authorized to contribute it.

Contribution: patch.diff (text/plain), 578 bytes.

[14 Jul 2013 6:38] MySQL Verification Team
Hello Chang,

Thank you for the report and contribution.

Thanks,
Umesh
[16 Sep 2013 14:25] Jon Stephens
Fixed in 7.0.40, 7.1.29, 7.2.14, 7.3.3.

See BUG#69610 for documentation info.

Closed.