WEEK SIX & SEVEN

This week I worked on fixing some Perl dependency Issues that came up when I tested my  MHA branch on Ubuntu 14.04. I Looked for a way round this issue of MHA perl dependencies and how this can be improved. Actually setting up  MHA is really stressful because of this issue. There are lots of packages that need to be installed for things to work. I also improved on our master monitor script. I added

#!/usr/bin/perl -w

use lib '../lib';
use MHA::MasterMonitor;

$num_args = $#ARGV + 1;
if ($num_args != 4) {
 print "\nUsage: master_monitor username password ip port\n";
 exit;
}

MHA::MasterMonitor::main( @ARGV );

This script uses the MasterMonitor script to connect to a master server.  It regularly checks the availability of mysqld at the given master server specified by the IP parameter and Prints an error message when mysqld is unavailable or is not running on that server.
Commits can be found on github here.

WEEK 4 & 5

During week 4, I was writing my semester exams and prepared my defense which all went well. I did not do much on this project during week 4. Work done during week 5 includes creating a new branch from most maintained MHA repository and pushed my commits to it. I named the branch mha-gtid . With support for getting the most up to date slave added in the third week, I went on to add support for reading and parsing slave  configuration file line by line. This file contains

user
password
ip
port

Which are parsed and used to setup a new slave. A sample code snippet is shown below:

my %domainHash = (); #Hash map for each Domain
 my $confFileName = "$dirname/../../slaves.cnf";
 open(CONF_HANDLE, "<$confFileName") or die "$!\n";
 while (<CONF_HANDLE>) {
 # Read config file line by line
 my @slaveEntry = split(',' , $_);
 my %slaveInfo = ();
 foreach my $confVar (@slaveEntry) {
 chomp $confVar;
 if ($confVar =~ m/(\S*) => (\S*)/) { 
 $slaveInfo{$1} = $2;
 }
 }
 $slave = new MHA::Slave(
 user => $slaveInfo{'user'},
 password => $slaveInfo{'password'},
 ip => $slaveInfo{'ip'},
 port => $slaveInfo{'port'},
 );

$gtid = $slave->getLatestGTID();
 my @values = split('-', $gtid);
 if( exists($domainHash{$values[0]}) ) {
 my $oldSeq = $domainHash{$values[0]}{'gtid'};
 my $newSeq = $values[2];
 if($newSeq > $oldSeq) {
 $domainHash{$values[0]}{'slaveIP'} = $slaveInfo{'ip'};
 $domainHash{$values[0]}{'gtid'} = $newSeq;
 }
 }
 else {
 $domainHash{$values[0]}{'slaveIP'} = $slaveInfo{'ip'};
 $domainHash{$values[0]}{'gtid'} = $values[2];
 }
 
 }
 close( CONF_HANDLE );
 foreach my $domain (keys %domainHash ) {
 print "Latest Slave in domain $domain, is: $domainHash{$domain}{'slaveIP'} with GTID Sequence: $domainHash{$domain}{'gtid'}\n";
 }

Full commits of work done during week 5 can be found HERE.

WEEK 3

This week, I worked on some GTID code. Like we saw in Week 2, MariaDB global transaction ID, or GTID for short, consists of three numbers separated with dashes ‘-‘. For example:
      0-1-11

With each section defined accordingly. The work I did was to write a query to be executed on a slave server to fetch the Latest GTID transaction applied there. To obtain this value, we need to execute the query

SELECT @@GLOBAL.gtid_slave_pos;

The sequence number part of a GTID represent the transaction number so parsing it to get the GTID with the highest sequence number identifies the most up to date slave and so we will need to return the IP of the domain ID. This will be done in the next milestone of the project.
All commits for the GTID query to get most up to date master can be found on Github here.

 

WEEK 2

This Week was a busy one for me in School. I had a couple of Continuous assessments and projects to submit. I also took out some time to work on our MHA project.
So far I have created a new package to check and Monitor Master Health. The Commits are found on my Github here. First, I created a package to Implement checking Masters Health  then wrote a main script to use it. It has nothing to do with SSH yet but we will improve on it later.

# Main script to Monitor Master using CheckHealth Package.

       package MHA::MasterMonitor;
       use MHA::CheckHealth;
       sub main {
       my ($user, $password, $ip, $port) = @_;

       $master_health = new MHA::CheckHealth(
       user => $user,
       password => $password,
       ip => $ip,
       port => $port,
       );
 
         $master_health->test_until_disconnects();
       }


Next Week I will be studying more of the MHA code for MYSQL GTID to git more insights for MariaDB GTIDs.

WEEK 1

Understanding MariaDB GTID  Implementation.

MariaDB global transaction ID, or GTID for short, consists of three numbers separated with dashes ‘-‘. For example:

       0-1-11

  • The first number 0 is the domain ID, which is specific for global transaction ID. It is a 32-bit unsigned integer.
  • The second number is the server ID, the same as is also used in old-style replication. It is a 32-bit unsigned integer.
  • The third number is the sequence number. This is a 64-bit unsigned integer that is monotonically increasing for each new event group logged into the binlog.

GTIDs are defined in the server sql/rpl_gtid.xx source tree as follows

    struct rpl_gtid
{
uint32 domain_id;
uint32 server_id;
uint64 seq_no;
};

 

The server ID is set to the server ID of the server where the event group is first logged into the binlog. The sequence number is increased on a server for every event group logged. Since server IDs must be unique for every server, this makes the (server_id, sequence_number) pair, and hence the whole GTID, globally unique.

Using a 64-bit number provides a wide range that there should be no risk of it overflowing in the foreseeable future.

MHA Implementation.

This Week, I have studied how the GTID is Implemented in the Server code and what each number in a GTID represents.

A Github project HERE  has been created where I will be pushing my code.

I have also set up 5 MariaDB instances on OS X for testing following this blogpost.