Skip to content

Commit

Permalink
Set lsn_location as private attributes
Browse files Browse the repository at this point in the history
This patch replace every call of "crm_attribute" to set lsn_location by a
call to "attrd_updater --private". This avoid breaking a transition by
setting resource attributes as private attribute do not land inside the
CIB.

This takes part of the cleanup for gh issue #18.
  • Loading branch information
ioguix committed Apr 27, 2016
1 parent 6e86284 commit f60f43a
Showing 1 changed file with 28 additions and 14 deletions.
42 changes: 28 additions & 14 deletions script/pgsqlms
Original file line number Diff line number Diff line change
Expand Up @@ -59,16 +59,35 @@ my $PGPSQL = "$bindir/psql";
my $PGCTRLDATA = "$bindir/pg_controldata";
my $PGISREADY = "$bindir/pg_isready";

# crm* commands path
# pacemaker commands path
my $CRM_MASTER = "$HA_SBIN_DIR/crm_master --lifetime reboot";
my $CRM_ATTRIBUTE = "$HA_SBIN_DIR/crm_attribute --lifetime reboot --type status";
my $CRM_NODE = "$HA_SBIN_DIR/crm_node";
my $CRM_RESOURCE = "$HA_SBIN_DIR/crm_resource";
my $ATTRD_PRIV = "$HA_SBIN_DIR/attrd_updater --private --lifetime reboot";

# Global vars
my $nodename;
my $exit_code = 0;

# Get, parse and return the value of the given private attribute name
# Returns an empty string if not found.
sub _get_priv_attrd_value {
my ( $name, $node ) = @_;
my $ans;

$node = '' unless defined $node;
$node = "--node $node" if $node ne '';

$ans = qx{ $ATTRD_PRIV --name $name $node --query };

$ans =~ m/^name=".*" host=".*" value="(.*)"$/;

return $1 if defined $1;

return '';
}

# Run the given command as the "system_user" given as parameter.
# It basically forks and seteuid/setuid away from root.
#
Expand Down Expand Up @@ -1306,20 +1325,18 @@ sub pgsql_promote {
# Get the "lsn_location" attribute value for the current node, as set
# during the "pre-promote" action.
# It should be the greatest among the secondary instances.
$max_lsn = qx{ $CRM_ATTRIBUTE -q --node $nodename \\
--quiet --query --name lsn_location };
$max_lsn = _get_priv_attrd_value( 'lsn_location' );

if ( $? != 0 or not $max_lsn ) {
if ( $max_lsn eq '' ) {
# This should not happen as the "lsn_location" attribute should have
# been updated during the "pre-promote" action.
ocf_log( 'crit',
'pgsql_promote: can not get current node LSN location');
return $OCF_ERR_GENERIC;
}

chomp $max_lsn;

# convert location to decimal
chomp $max_lsn;
($wal_num, $wal_off) = split m@/@ => $max_lsn;
$max_lsn_dec = ( 4294967296 * hex( $wal_num ) ) + hex( $wal_off );

Expand All @@ -1334,20 +1351,18 @@ sub pgsql_promote {

# Get the "lsn_location" attribute value for the node, as set during
# the "pre-promote" action.
$node_lsn = qx{ $CRM_ATTRIBUTE -q --node "$node" \\
--query --name lsn_location };
$node_lsn = _get_priv_attrd_value( 'lsn_location', $node );

if ( $? != 0 or not $node_lsn ) {
if ( $node_lsn eq '' ) {
# This should not happen as the "lsn_location" attribute should
# have been updated during the "pre-promote" action.
ocf_log( 'crit',
'pgsql_promote: can not get LSN location for "%s"', $node );
return $OCF_ERR_GENERIC;
}

chomp $node_lsn;

# convert location to decimal
chomp $node_lsn;
($wal_num, $wal_off) = split m@/@ => $node_lsn;
$node_lsn_dec = ( 4294967296 * hex( $wal_num ) ) + hex( $wal_off );

Expand Down Expand Up @@ -1482,8 +1497,7 @@ sub pgsql_notify {

# Set the "lsn_location" attribute value for this node so we can use it
# during the following "promote" action.
qx{ $CRM_ATTRIBUTE --node "$nodename" \\
--name lsn_location --update "$node_lsn" };
qx{ $ATTRD_PRIV --name lsn_location --update "$node_lsn" };

ocf_log( 'warning', sprintf
'pgsql_notify: could not set the current node LSN' )
Expand All @@ -1498,7 +1512,7 @@ sub pgsql_notify {
$notify_env{'promote'}[0]{'uname'} );
# We have a new master (or the previous one recovered).
# Delete "lsn_location" values on all nodes
qx{ $CRM_ATTRIBUTE --node "$nodename" --name lsn_location --delete };
qx{ $ATTRD_PRIV --name lsn_location --delete };
}

return $OCF_SUCCESS;
Expand Down

0 comments on commit f60f43a

Please sign in to comment.