-
Notifications
You must be signed in to change notification settings - Fork 148
Zk leader election (sequence) #28
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
Changes from 5 commits
23deb83
341b3cd
0d94fac
9f1822f
a43e82d
22da3d1
766f1a4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -10,10 +10,18 @@ def initialize(opts) | |
| raise ArgumentError, "you need to specify required argument #{required}" unless opts[required] | ||
| end | ||
|
|
||
| defaults = { | ||
| :sequential => false, | ||
| } | ||
| opts = defaults.merge(opts) | ||
|
|
||
| @path = opts['hosts'].shuffle.join(',') + opts['path'] | ||
| @data = parse_data(opts['data'] || '') | ||
| @key = opts['key'] | ||
| @key.insert(0,'/') unless @key[0] == '/' | ||
| @sequential = opts['sequential'] | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. you should do |
||
| @key.insert('-') if @sequential | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. is this necessary?
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. it is not, i added it to help visualize the sequence and separate it from the port
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the '-' is inserted to help visualize the sequence and separate from the port in the node path/key |
||
| @full_key = @key | ||
| end | ||
|
|
||
| def start() | ||
|
|
@@ -23,7 +31,7 @@ def start() | |
| log.info "nerve: successfully created zk connection to #{@path}" | ||
| end | ||
|
|
||
| def report_up() | ||
| def report_up | ||
| zk_save | ||
| end | ||
|
|
||
|
|
@@ -43,15 +51,17 @@ def ping? | |
| private | ||
|
|
||
| def zk_delete | ||
| @zk.delete(@key, :ignore => :no_node) | ||
| @zk.delete(@full_key, :ignore => :no_node) | ||
| end | ||
|
|
||
| def zk_save | ||
| log.debug "nerve: writing data #{@data.class} to zk at #{@key} with #{@data.inspect}" | ||
| log.debug "nerve: writing data #{@data.class} to zk at #{@key} with #{@data.inspect} and sequential | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this would put weird whitespace in the debug message; you should do a continuation line instead -- i prefer the style where you end the line with a |
||
| flag is #{@sequential}" | ||
| begin | ||
| @zk.set(@key,@data) | ||
| @zk.set(@full_key, @data) | ||
| rescue ZK::Exceptions::NoNode => e | ||
| @zk.create(@key,:data => @data, :mode => :ephemeral) | ||
| @full_key = @zk.create(@key,:data => @data, :ephemeral => true, | ||
| :sequential => @sequential) | ||
| end | ||
| end | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -23,6 +23,7 @@ def initialize(service={}) | |
| 'path' => service['zk_path'], | ||
| 'key' => "#{service['instance_id']}_#{@name}", | ||
| 'data' => {'host' => service['host'], 'port' => service['port']}, | ||
| 'sequential' => service['sequential'] | false | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i think you meant |
||
| }) | ||
|
|
||
| # instantiate the checks for this service | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no reason to do this; just do an
||on the line where you set@sequential