MySQL 5.6.14 Source Code Document
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
ndb_info.inc
1 --perl
2 use strict;
3 
4 use File::Basename;
5 use IO::File;
6 use lib "lib/";
7 use My::Find;
8 
9 #
10 # Include file that sets the following environment variables:
11 # MTR_NDB_NO_OF_NODES - Number of ndb[mt]d data nodes
12 # MTR_NDB_NO_OF_REPLICAS - Number of replicas
13 # MTR_NDB_MAX_NO_OF_TABLES - Max number of tables
14 # MTR_NDB_MAX_NO_OF_ORDERED_INDEXES - Max number of ordered indexes
15 # MTR_NDB_DATA_MEMORY - Data memory per node
16 # MTR_NDB_INDEX_MEMORY - Index memory per node
17 # MTR_NDB_USABLE_DATA_MEMORY - Data memory available for user (#nodes * data_memory / #replicas)
18 # MTR_NDB_USABLE_INDEX_MEMORY - Index memory available for user (#nodes * index_memory / #replicas)
19 #
20 
21 #
22 # Set up paths
23 #
24 my $vardir = $ENV{MYSQLTEST_VARDIR} or die "Need MYSQLTEST_VARDIR";
25 my $mysql_test_dir = $ENV{MYSQL_TEST_DIR} or die "Need MYSQL_TEST_DIR";
26 my $basedir = dirname($mysql_test_dir);
27 my $ndb_connectstring = $ENV{NDB_CONNECTSTRING} or die "Need NDB_CONNECTSTRING";
28 
29 #
30 # Check if the needed jars are available
31 #
32 my $ndb_config = my_find_file($basedir,
33  ["storage/ndb/tools", "bin"],
34  ["ndb_config", "ndb_config.exe"], NOT_REQUIRED);
35 
36 my $fields = "NoOfReplicas,MaxNoOfTables,MaxNoOfOrderedIndexes,DataMemory,IndexMemory";
37 my $cmd = "$ndb_config --ndb-connectstring='$ndb_connectstring' -q '$fields' -f ',' -r '\\n'";
38 print "Calling ndb_config: '$cmd'\n";
39 my $output = `$cmd`;
40 
41 my $no_of_nodes = 0;
42 my $no_of_replicas = 0;
43 my $max_no_of_tables = 0;
44 my $max_no_of_ordered_indexes = 0;
45 my $data_memory = 0;
46 my $index_memory = 0;
47 
48 foreach my $line (split("\n", $output)) {
49  # Skip empty lines
50  next if ($line =~ m/^,+$/g);
51 
52  # One line per node
53  $no_of_nodes++;
54 
55  # Same on each line (node)
56  ($no_of_replicas, $max_no_of_tables, $max_no_of_ordered_indexes, $data_memory, $index_memory) = split(',', $line);
57 }
58 
59 my $usable_data_memory = 0;
60 my $usable_index_memory = 0;
61 
62 if ($no_of_replicas > 0) {
63  $usable_data_memory = $no_of_nodes * $data_memory / $no_of_replicas;
64  $usable_index_memory = $no_of_nodes * $index_memory / $no_of_replicas;
65 } else {
66  die "Failed to parse ndb_config output - could not get number of replicas";
67 }
68 
69 sub get_first_last {
70  my $type = shift;
71 
72  my $cmd = "$ndb_config --ndb-connectstring='$ndb_connectstring' -q 'NodeId' -f '' -r ',' --type=$type";
73  my $output = `$cmd`;
74  chomp($output);
75  my @nums = split(',', $output);
76  my @sorted = sort(@nums);
77  return ($sorted[0], $sorted[scalar(@sorted) - 1]);
78 }
79 
80 my ($first_ndbd_nodeid, $last_ndbd_nodeid) = get_first_last('ndbd');
81 my ($first_mgmd_nodeid, $last_mgmd_nodeid) = get_first_last('ndb_mgmd');
82 
83 my $file_name = "$vardir/tmp/ndb_info_result.inc";
84 my $F = IO::File->new($file_name, 'w') or die "Could not open '$file_name' for writing";
85 print $F "--let \$MTR_NDB_NO_OF_NODES= $no_of_nodes\n";
86 print $F "--let \$MTR_NDB_NO_OF_REPLICAS= $no_of_replicas\n";
87 print $F "--let \$MTR_NDB_MAX_NO_OF_TABLES= $max_no_of_tables\n";
88 print $F "--let \$MTR_NDB_MAX_NO_OF_ORDERED_INDEXES= $max_no_of_ordered_indexes\n";
89 print $F "--let \$MTR_NDB_DATA_MEMORY= $data_memory\n";
90 print $F "--let \$MTR_NDB_INDEX_MEMORY= $index_memory\n";
91 print $F "--let \$MTR_NDB_USABLE_DATA_MEMORY= $usable_data_memory\n";
92 print $F "--let \$MTR_NDB_USABLE_INDEX_MEMORY= $usable_index_memory\n";
93 print $F "--let \$MTR_NDB_FIRST_NDBD_NODEID= $first_ndbd_nodeid\n";
94 print $F "--let \$MTR_NDB_LAST_NDBD_NODEID= $last_ndbd_nodeid\n";
95 print $F "--let \$MTR_NDB_FIRST_MGMD_NODEID= $first_mgmd_nodeid\n";
96 print $F "--let \$MTR_NDB_LAST_MGMD_NODEID= $last_mgmd_nodeid\n";
97 $F->close();
98 
99 EOF
100 
101 --source $MYSQLTEST_VARDIR/tmp/ndb_info_result.inc