Permalink
Browse files

formatting cleanup

  • Loading branch information...
1 parent 77e5b4a commit 8cdf1404f8777c1901353cd638333fde65c55554 caryp committed Dec 16, 2011
Showing with 42 additions and 62 deletions.
  1. +42 −47 libraries/helper.rb
  2. +0 −15 providers/default.rb
View
@@ -32,60 +32,55 @@ def init(new_resource)
RightScale::Tools::Database.factory(:mysql, new_resource.user, new_resource.password, mount_point, Chef::Log)
end
- def self.load_replication_info(node)
- loadfile = ::File.join(node[:db][:data_dir], SNAPSHOT_POSITION_FILENAME)
- Chef::Log.info "Loading replication information from #{loadfile}"
- YAML::load_file(loadfile)
- end
+ def self.load_replication_info(node)
+ loadfile = ::File.join(node[:db][:data_dir], SNAPSHOT_POSITION_FILENAME)
+ Chef::Log.info "Loading replication information from #{loadfile}"
+ YAML::load_file(loadfile)
+ end
- def self.get_mysql_handle(node, hostname = 'localhost')
- info_msg = "MySQL connection to #{hostname}"
- info_msg << ": opening NEW MySQL connection."
- con = Mysql.new(hostname, node[:db][:admin][:user], node[:db][:admin][:password])
- Chef::Log.info info_msg
- # this raises if the connection has gone away
- con.ping
- return con
- end
+ def self.get_mysql_handle(node, hostname = 'localhost')
+ info_msg = "MySQL connection to #{hostname}"
+ info_msg << ": opening NEW MySQL connection."
+ con = Mysql.new(hostname, node[:db][:admin][:user], node[:db][:admin][:password])
+ Chef::Log.info info_msg
+ # this raises if the connection has gone away
+ con.ping
+ return con
+ end
- def self.do_query(node, query, hostname = 'localhost', timeout = nil, tries = 1)
- require 'mysql'
+ def self.do_query(node, query, hostname = 'localhost', timeout = nil, tries = 1)
+ require 'mysql'
- while(1) do
- begin
- info_msg = "Doing SQL Query: HOST=#{hostname}, QUERY=#{query}"
- info_msg << ", TIMEOUT=#{timeout}" if timeout
- info_msg << ", NUM_TRIES=#{tries}" if tries > 1
- Chef::Log.info info_msg
- result = nil
- if timeout
- SystemTimer.timeout_after(timeout) do
- con = get_mysql_handle(node, hostname)
- result = con.query(query)
- end
- else
- con = get_mysql_handle(node, hostname)
- result = con.query(query)
- end
- return result.fetch_hash if result
- return result
- rescue Timeout::Error => e
- Chef::Log.info("Timeout occured during mysql query:#{e}")
- tries -= 1
- raise "FATAL: retry count reached" if tries == 0
- end
- end
- end
+ while(1) do
+ begin
+ info_msg = "Doing SQL Query: HOST=#{hostname}, QUERY=#{query}"
+ info_msg << ", TIMEOUT=#{timeout}" if timeout
+ info_msg << ", NUM_TRIES=#{tries}" if tries > 1
+ Chef::Log.info info_msg
+ result = nil
+ if timeout
+ SystemTimer.timeout_after(timeout) do
+ con = get_mysql_handle(node, hostname)
+ result = con.query(query)
+ end
+ else
+ con = get_mysql_handle(node, hostname)
+ result = con.query(query)
+ end
+ return result.fetch_hash if result
+ return result
+ rescue Timeout::Error => e
+ Chef::Log.info("Timeout occured during mysql query:#{e}")
+ tries -= 1
+ raise "FATAL: retry count reached" if tries == 0
+ end
+ end
+ end
def self.reconfigure_replication(node, hostname = 'localhost', newmaster_host = nil, newmaster_logfile=nil, newmaster_position=nil)
-# These must be passed and not read from a file
-# master_info = RightScale::Database::MySQL::Helper.load_replication_info(node)
-# newmaster_host = master_info['Master_IP']
-# newmaster_logfile = master_info['File']
-# newmaster_position = master_info['Position']
Chef::Log.info "Configuring with #{newmaster_host} logfile #{newmaster_logfile} position #{newmaster_position}"
- # legacy did this twice, looks like slave stop can fail once (only throws warning if slave is already stopped)
+ # The slave stop can fail once (only throws warning if slave is already stopped)
RightScale::Database::MySQL::Helper.do_query(node, "STOP SLAVE", hostname)
RightScale::Database::MySQL::Helper.do_query(node, "STOP SLAVE", hostname)
View
@@ -91,8 +91,6 @@
action :post_restore_cleanup do
@db = init(new_resource)
@db.symlink_datadir("/var/lib/mysql", node[:db][:data_dir])
- # TODO: used for replication
- # @db.post_restore_sanity_check
@db.post_restore_cleanup
end
@@ -306,7 +304,6 @@
# - set config file localhost access w/ root and no password
# - disable the 'check_for_crashed_tables'.
#
-
remote_file "/etc/mysql/debian.cnf" do
only_if { node[:platform] == "ubuntu" }
mode "0600"
@@ -321,18 +318,6 @@
cookbook 'db_mysql'
end
-
- ## == Setup log rotation
- ##
- #rs_utils_logrotate_app "mysql-server" do
- # template "mysql-server.logrotate.erb"
- # cookbook "db_mysql"
- # path ["/var/log/mysql*.log", "/var/log/mysql*.err" ]
- # frequency "daily"
- # rotate 7
- # create "640 mysql adm"
- #end
-
# == Start MySQL
#
service "mysql" do

0 comments on commit 8cdf140

Please sign in to comment.