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

Use Chef search (role:cassandra) to look up seed nodes #205

Merged
merged 10 commits into from
Aug 7, 2015
9 changes: 8 additions & 1 deletion attributes/default.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,14 @@
default['cassandra']['log_dir'] = '/var/log/cassandra'
default['cassandra']['rootlogger'] = 'INFO,stdout,R'

# Seed node discovery
default['cassandra']['seeds'] = node['ipaddress']

default['cassandra']['seed_discovery']['use_chef_search'] = false
default['cassandra']['seed_discovery']['count'] = 3
default['cassandra']['seed_discovery']['search_role'] = 'cassandra-seed'
default['cassandra']['seed_discovery']['search_query'] = nil

default['cassandra']['jbod']['slices'] = nil
default['cassandra']['jbod']['dir_name_prefix'] = 'data'

Expand Down Expand Up @@ -129,7 +137,6 @@
default['cassandra']['xss'] = '256k'
default['cassandra']['vnodes'] = true
default['cassandra']['num_tokens'] = 256
default['cassandra']['seeds'] = node['ipaddress']
default['cassandra']['enable_assertions'] = true
default['cassandra']['internode_compression'] = 'all' # all, dc, none
default['cassandra']['jmx_server_hostname'] = false
Expand Down
33 changes: 33 additions & 0 deletions libraries/config_helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,36 @@ def cassandra_bool_config(config_val)
def hash_to_yaml_string(hash)
hash.to_hash.to_yaml
end

def discover_seed_nodes
# use chef search for seed nodes
if node['cassandra']['seed_discovery']['use_chef_search']
if Chef::Config[:solo]
Chef::Log.warn("Chef Solo does not support search, provide the seed nodes via node attribute node['cassandra']['seeds']")
node['ipaddress']
else
Chef::Log.info("Cassandra seed discovery using Chef search is enabled")
q = if search_query = node['cassandra']['seed_discovery']['search_query']
search_query
else
"chef_environment:#{node.chef_environment} AND role:#{node['cassandra']['seed_discovery']['search_role']} AND cassandra_cluster_name:#{node['cassandra']['cluster_name']}"
end
Chef::Log.info("Will discover Cassandra seeds using query '#{q}'")
xs = search(:node, q).map(&:ipaddress).sort.uniq
Chef::Log.debug("Discovered #{xs.size} Cassandra seeds using query '#{q}'")

if xs.empty?
node['ipaddress']
else
xs.take(node['cassandra']['seed_discovery']['count']).join(',')
end
end
else
# user defined seed nodes
if node['cassandra']['seeds'].is_a?(Array)
node['cassandra']['seeds'].join(',')
else
node['cassandra']['seeds']
end
end
end
2 changes: 2 additions & 0 deletions recipes/default.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,6 @@
node.default['cassandra']['jamm']['sha256sum'] = '79d44f1b911a603f0a249aa59ad6ea22aac9c9b211719e86f357646cdf361a42'
end

node.default['cassandra']['seeds'] = discover_seed_nodes

include_recipe "cassandra-dse::#{node['cassandra']['install_method']}"
2 changes: 1 addition & 1 deletion templates/default/cassandra.yaml.erb
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ seed_provider:
# seeds is actually a comma-delimited list of addresses.
# Ex: "<ip1>,<ip2>,<ip3>"
#- seeds: "127.0.0.1"
- seeds: "<%= if node['cassandra']['seeds'].kind_of?(Array) then node['cassandra']['seeds'].join(",") else node['cassandra']['seeds'] end %>"
- seeds: "<%= node['cassandra']['seeds'] %>"

# emergency pressure valve: each time heap usage after a full (CMS)
# garbage collection is above this fraction of the max, Cassandra will
Expand Down