LP #1017719: Include port number in pt-deadlock-logger output

Description

**Reported in Launchpad by Geoffrey Anderson last update 24-05-2013 12:50:38

When generating the deadlocks output, please include the port number along with the hostname for cases in which multiple instances may be running on a host.

Environment

None

Smart Checklist

Activity

lpjirasync January 24, 2018 at 6:47 PM

**Comment from Launchpad by: Peter (Stig) Edwards on: 24-05-2013 12:50:38

Hello and thank you for percona-toolkit-2.2.2/bin/pt-deadlock-logger,

I also needed the port for the source server in the destination table, instead of adding a 'port' field, my hack was to append it to the server name if a port is supplied:

  1. ########################################################################

  2. Start looking for and logging deadlocks.

  3. ########################################################################
    my $sep = $o->get('tab') ? "\t" : ' ';
    my $last_fingerprint = '';
    my $tmp_server = $src->dsn->{h} || $src->{hostname};
    my $tmp_port = $src->dsn->{P} || $src->{port};
    if(defined $tmp_port){
    $tmp_server .= q{:} . $tmp_port;
    }
    my $parse_deadlocks_options = {
    'server' => $tmp_server,
    'numeric-ip' => $o->got('numeric-ip'),
    };


But after finding and reading this bug I think it would be better to ask the mysqld instance for the 'hostname' and 'port', for the reason Baron provided (connection via socket), (but also potentially a VIP or iptable rule), especially if variables are already being queried, I noticed the sub fill_in_dsn(), but I could not see it being used.

Adding the port to the server name (if you think it would help others) probably needs to be an option that is off by default to preserve backwards compatibility. Maybe:

--port-in-servername

to enable it?

Thanks for your consideration,

Peter (Stig) Edwards

lpjirasync January 24, 2018 at 6:47 PM

**Comment from Launchpad by: Baron Schwartz on: 29-06-2012 19:19:46

We should probably get the server's port from the 'port' variable in SHOW VARIABLES instead of getting it from the DSN. The DSN may not be accurate; if we connect via a socket to a server that isn't listening on 3306, then the default suggested in the patch won't be correct.

Likewise, we should change this line too:

2254 $txn->{server} = $source_dsn->{h} || '';

We have some functionality to get a hostname in other tools, though I don't remember where or how. I know it's in pt-table-checksum, and we use it when we're displaying which replica is lagging, for example. We can use that same technique here.

lpjirasync January 24, 2018 at 6:47 PM

**Comment from Launchpad by: Geoffrey Anderson on: 25-06-2012 22:34:33

Here's a patch I put together for this change.

Details

Assignee

Reporter

Priority

Smart Checklist

Created January 24, 2018 at 6:46 PM
Updated December 21, 2019 at 2:32 PM