1--perl
2use strict;
3
4use File::Basename;
5use IO::File;
6use lib "lib/";
7use 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#
24my $vardir = $ENV{MYSQLTEST_VARDIR} or die "Need MYSQLTEST_VARDIR";
25my $mysql_test_dir = $ENV{MYSQL_TEST_DIR} or die "Need MYSQL_TEST_DIR";
26my $basedir = dirname($mysql_test_dir);
27my $bindir = $ENV{MTR_BINDIR} || $basedir; # Out of source set MTR_BINDIR
28my $ndb_connectstring = $ENV{NDB_CONNECTSTRING} or die "Need NDB_CONNECTSTRING";
29
30#
31# Find ndb_config
32#
33my $ndb_config = my_find_file($bindir,
34                              ["storage/ndb/tools", "bin"],
35                              ["ndb_config", "ndb_config.exe"], NOT_REQUIRED);
36
37my $fields = "NoOfReplicas,MaxNoOfTables,MaxNoOfOrderedIndexes,DataMemory,IndexMemory";
38my $cmd = "$ndb_config --ndb-connectstring='$ndb_connectstring' -q '$fields' -f ',' -r '\\n'";
39print "Calling ndb_config: '$cmd'\n";
40my $output = `$cmd`;
41
42my $no_of_nodes = 0;
43my $no_of_replicas = 0;
44my $max_no_of_tables = 0;
45my $max_no_of_ordered_indexes = 0;
46my $data_memory = 0;
47my $index_memory = 0;
48
49foreach my $line (split("\n", $output)) {
50    # Skip empty lines
51    next if ($line =~ m/^,+$/g);
52
53    # One line per node
54    $no_of_nodes++;
55
56    # Same on each line (node)
57    ($no_of_replicas, $max_no_of_tables, $max_no_of_ordered_indexes, $data_memory, $index_memory) = split(',', $line);
58}
59
60my $usable_data_memory = 0;
61my $usable_index_memory = 0;
62
63if ($no_of_replicas > 0) {
64    $usable_data_memory = $no_of_nodes * $data_memory / $no_of_replicas;
65    $usable_index_memory = $no_of_nodes * $index_memory / $no_of_replicas;
66} else {
67    die "Failed to parse ndb_config output - could not get number of replicas";
68}
69
70sub get_first_last {
71  my $type = shift;
72
73  my $cmd = "$ndb_config --ndb-connectstring='$ndb_connectstring' -q 'NodeId' -f '' -r ',' --type=$type";
74  my $output = `$cmd`;
75  chomp($output);
76  my @nums = split(',', $output);
77  my @sorted = sort(@nums);
78  return ($sorted[0], $sorted[scalar(@sorted) - 1]);
79}
80
81my ($first_ndbd_nodeid, $last_ndbd_nodeid) = get_first_last('ndbd');
82my ($first_mgmd_nodeid, $last_mgmd_nodeid) = get_first_last('ndb_mgmd');
83
84my $file_name = "$vardir/tmp/ndb_info_result.inc";
85my $F = IO::File->new($file_name, 'w') or die "Could not open '$file_name' for writing";
86print $F "--let \$MTR_NDB_NO_OF_NODES= $no_of_nodes\n";
87print $F "--let \$MTR_NDB_NO_OF_REPLICAS= $no_of_replicas\n";
88print $F "--let \$MTR_NDB_MAX_NO_OF_TABLES= $max_no_of_tables\n";
89print $F "--let \$MTR_NDB_MAX_NO_OF_ORDERED_INDEXES= $max_no_of_ordered_indexes\n";
90print $F "--let \$MTR_NDB_DATA_MEMORY= $data_memory\n";
91print $F "--let \$MTR_NDB_INDEX_MEMORY= $index_memory\n";
92print $F "--let \$MTR_NDB_USABLE_DATA_MEMORY= $usable_data_memory\n";
93print $F "--let \$MTR_NDB_USABLE_INDEX_MEMORY= $usable_index_memory\n";
94print $F "--let \$MTR_NDB_FIRST_NDBD_NODEID= $first_ndbd_nodeid\n";
95print $F "--let \$MTR_NDB_LAST_NDBD_NODEID= $last_ndbd_nodeid\n";
96print $F "--let \$MTR_NDB_FIRST_MGMD_NODEID= $first_mgmd_nodeid\n";
97print $F "--let \$MTR_NDB_LAST_MGMD_NODEID= $last_mgmd_nodeid\n";
98$F->close();
99
100EOF
101
102--source $MYSQLTEST_VARDIR/tmp/ndb_info_result.inc
103