Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Gtid tracking support #151

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 23 additions & 7 deletions lib/puppet/provider/proxy_mysql_server/proxysql.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,18 @@ def self.instances
# one big swoop.
servers.each do |line|
hostname, port, hostgroup_id = line.split(%r{\t})
query = 'SELECT `hostname`, `port`, `hostgroup_id`, `status`, `weight`, `compression`, '
query << ' `max_connections`, `max_replication_lag`, `use_ssl`, `max_latency_ms`, `comment` '
query = 'SELECT `hostname`, `port`, `hostgroup_id`, '
if has_gtid_tracking?
query << ' `gtid_port`, '
else
query << " NULL AS 'gtid_port', "
end
query << ' `status`, `weight`, `compression`, `max_connections`, '
query << ' `max_replication_lag`, `use_ssl`, `max_latency_ms`, `comment` '
query << ' FROM `mysql_servers`'
query << " WHERE `hostname` = '#{hostname}' AND `port` = #{port} AND `hostgroup_id` = '#{hostgroup_id}'"

@hostname, @port, @hostgroup_id, @status, @weight, @compression,
@hostname, @port, @hostgroup_id, @gtid_port, @status, @weight, @compression,
@max_connections, @max_replication_lag, @use_ssl, @max_latency_ms,
@comment = mysql([defaults_file, '-NBe', query].compact).chomp.split(%r{\t})
name = "#{hostname}:#{port}-#{hostgroup_id}"
Expand All @@ -29,6 +35,7 @@ def self.instances
ensure: :present,
hostname: @hostname,
port: @port,
gtid_port: @gtid_port,
hostgroup_id: @hostgroup_id,
status: @status,
weight: @weight,
Expand Down Expand Up @@ -57,6 +64,7 @@ def create
_name = @resource[:name]
hostname = @resource.value(:hostname)
port = @resource.value(:port) || 3306
gtid_port = @resource.value(:gtid_port)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this will need a default value to fix failing tests

hostgroup_id = @resource.value(:hostgroup_id) || 0
status = @resource.value(:status) || 'ONLINE'
weight = @resource.value(:weight) || 1
Expand All @@ -67,10 +75,14 @@ def create
max_latency_ms = @resource.value(:max_latency_ms) || 0
comment = @resource.value(:comment) || ''

query = 'INSERT INTO mysql_servers (`hostname`, `port`, `hostgroup_id`, `status`, `weight`, `compression`, '
query << ' `max_connections`, `max_replication_lag`, `use_ssl`, `max_latency_ms`, `comment`)'
query << " VALUES ('#{hostname}', #{port}, #{hostgroup_id}, '#{status}', #{weight}, #{compression}, "
query << " #{max_connections}, #{max_replication_lag}, #{use_ssl}, #{max_latency_ms}, '#{comment}')"
query = 'INSERT INTO mysql_servers (`hostname`, `port`, `hostgroup_id`, '
query << ' `gtid_port`, ' if has_gtid_tracking?
query << ' `status`, `weight`, `compression`, `max_connections`, '
query << ' `max_replication_lag`, `use_ssl`, `max_latency_ms`, `comment`)'
query << " VALUES ('#{hostname}', #{port}, #{hostgroup_id}, "
query << " #{gtid_port}, " if has_gtid_tracking?
query << " '#{status}', #{weight}, #{compression}, #{max_connections}, "
query << " #{max_replication_lag}, #{use_ssl}, #{max_latency_ms}, '#{comment}')"
mysql([defaults_file, '-e', query].compact)
@property_hash[:ensure] = :present

Expand Down Expand Up @@ -164,4 +176,8 @@ def max_latency_ms=(value)
def comment=(value)
@property_flush[:comment] = value
end

def gtid_port=(value)
@property_flush[:gtid_port] = value
end
end
30 changes: 23 additions & 7 deletions lib/puppet/provider/proxy_mysql_server_no_hostgroup/proxysql.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,18 @@ def self.instances
# one big swoop.
servers.each do |line|
hostname, port = line.split(%r{\t})
query = 'SELECT `hostname`, `port`, `hostgroup_id`, `status`, `weight`, `compression`, '
query << ' `max_connections`, `max_replication_lag`, `use_ssl`, `max_latency_ms`, `comment` '
query = 'SELECT `hostname`, `port`, `hostgroup_id`, '
if has_gtid_tracking?
query << ' `gtid_port`, '
else
query << " NULL AS 'gtid_port', "
end
query << ' `status`, `weight`, `compression`, `max_connections`, '
query << ' `max_replication_lag`, `use_ssl`, `max_latency_ms`, `comment` '
query << ' FROM `mysql_servers`'
query << " WHERE `hostname` = '#{hostname}' AND `port` = #{port}"

@hostname, @port, @hostgroup_id, @status, @weight, @compression,
@hostname, @port, @hostgroup_id, @gtid_port, @status, @weight, @compression,
@max_connections, @max_replication_lag, @use_ssl, @max_latency_ms,
@comment = mysql([defaults_file, '-NBe', query].compact).chomp.split(%r{\t})
name = "#{hostname}:#{port}"
Expand All @@ -29,6 +35,7 @@ def self.instances
ensure: :present,
hostname: @hostname,
port: @port,
gtid_port: @gtid_port,
hostgroup_id: @hostgroup_id,
status: @status,
weight: @weight,
Expand Down Expand Up @@ -57,6 +64,7 @@ def create
_name = @resource[:name]
hostname = @resource.value(:hostname)
port = @resource.value(:port) || 3306
gtid_port = @resource.value(:gtid_port)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this will need a default value to fix failing tests

hostgroup_id = @resource.value(:hostgroup_id) || 0
status = @resource.value(:status) || 'ONLINE'
weight = @resource.value(:weight) || 1
Expand All @@ -67,10 +75,14 @@ def create
max_latency_ms = @resource.value(:max_latency_ms) || 0
comment = @resource.value(:comment) || ''

query = 'INSERT INTO mysql_servers (`hostname`, `port`, `hostgroup_id`, `status`, `weight`, `compression`, '
query << ' `max_connections`, `max_replication_lag`, `use_ssl`, `max_latency_ms`, `comment`)'
query << " VALUES ('#{hostname}', #{port}, #{hostgroup_id}, '#{status}', #{weight}, #{compression}, "
query << " #{max_connections}, #{max_replication_lag}, #{use_ssl}, #{max_latency_ms}, '#{comment}')"
query = 'INSERT INTO mysql_servers (`hostname`, `port`, `hostgroup_id`, '
query << ' `gtid_port`, ' if has_gtid_tracking?
query << ' `status`, `weight`, `compression`, `max_connections`, '
query << ' `max_replication_lag`, `use_ssl`, `max_latency_ms`, `comment`)'
query << " VALUES ('#{hostname}', #{port}, #{hostgroup_id}, "
query << " #{gtid_port}, " if has_gtid_tracking?
query << " '#{status}', #{weight}, #{compression}, #{max_connections}, "
query << " #{max_replication_lag}, #{use_ssl}, #{max_latency_ms}, '#{comment}')"
mysql([defaults_file, '-e', query].compact)
@property_hash[:ensure] = :present

Expand Down Expand Up @@ -163,4 +175,8 @@ def max_latency_ms=(value)
def comment=(value)
@property_flush[:comment] = value
end

def gtid_port=(value)
@property_flush[:gtid_port] = value
end
end
9 changes: 9 additions & 0 deletions lib/puppet/provider/proxysql.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,15 @@ def defaults_file
self.class.defaults_file
end

# Check if we're running a version of ProxySQL that supports GTID tracking
def self.has_gtid_tracking?
Facter.value(:proxysql_version) && Puppet::Util::Package.versioncmp(Facter.value(:proxysql_version), '2.0.1') >= 0
end

def has_gtid_tracking?
self.class.has_gtid_tracking?
end

def make_sql_value(value)
if value.nil?
'NULL'
Expand Down
5 changes: 5 additions & 0 deletions lib/puppet/type/proxy_mysql_server.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,11 @@
newvalue(%r{\d+})
end

newproperty(:gtid_port) do
desc 'the backend server port where ProxySQL Binlog Reader listens on for GTID tracking. ProxySQL 2.0+ only.'
newvalue(%r{\d+})
end

newproperty(:status) do
desc 'Server status.'
newvalues(:ONLINE, :SHUNNED, :OFFLINE_SOFT, :OFFLINE_HARD)
Expand Down
5 changes: 5 additions & 0 deletions lib/puppet/type/proxy_mysql_server_no_hostgroup.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,11 @@
newvalue(%r{\d+})
end

newproperty(:gtid_port) do
desc 'the backend server port where ProxySQL Binlog Reader listens on for GTID tracking. ProxySQL 2.0+ only.'
newvalue(%r{\d+})
end

newproperty(:status) do
desc 'Server status.'
newvalues(:ONLINE, :SHUNNED, :OFFLINE_SOFT, :OFFLINE_HARD)
Expand Down
3 changes: 2 additions & 1 deletion types/server.pp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# lint:ignore:2sp_soft_tabs
type Proxysql::Server = Array[Hash[String, Struct[{ Optional[port] => Integer,
hostgroup_id => Integer,
Optional[gtid_port] => Integer,
Optional[status] => String[1],
Optional[weight] => Integer,
Optional[compression] => Integer,
Expand All @@ -9,4 +10,4 @@
Optional[use_ssl] => Integer[0,1],
Optional[max_latency_ms] => Integer,
Optional[comment] => String[1], }],1,1]]
# lint:endignore
# lint:endignore