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


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.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s