-
Notifications
You must be signed in to change notification settings - Fork 65
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add reconcile feature, incorporate code review comments from eric
- Loading branch information
1 parent
0373961
commit c8c49e3
Showing
6 changed files
with
48 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,3 @@ | ||
require 'set' | ||
require 'redis' | ||
require 'thread' | ||
require 'logger' | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,8 @@ module RedisFailover | |
class Node | ||
include Util | ||
|
||
BLPOP_WAIT_TIME = 3 | ||
|
||
attr_reader :host, :port | ||
|
||
def initialize(options = {}) | ||
|
@@ -19,13 +21,23 @@ def slave? | |
!master? | ||
end | ||
|
||
def slave_of?(master) | ||
current_master == master | ||
end | ||
|
||
def current_master | ||
info = fetch_info | ||
return unless info[:role] == 'slave' | ||
Node.new(:host => info[:master_host], :port => info[:master_port].to_i) | ||
end | ||
|
||
# Waits until something interesting happens. If the connection | ||
# with this node dies, the blpop call will raise an error. If | ||
# the blpop call returns without error, then this will be due to | ||
# a graceful shutdown signaled by #stop_waiting. | ||
# a graceful shutdown signaled by #stop_waiting or a timeout. | ||
def wait | ||
perform_operation do | ||
redis.blpop(wait_key, 0) | ||
redis.blpop(wait_key, 0, BLPOP_WAIT_TIME) | ||
redis.del(wait_key) | ||
end | ||
end | ||
|
@@ -103,7 +115,7 @@ def wait_key | |
end | ||
|
||
def redis | ||
Redis.new(:host => @host, :password => @password, :port => @port) | ||
@redis ||= Redis.new(:host => @host, :password => @password, :port => @port) | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
eric
Collaborator
|
||
rescue | ||
raise NodeUnavailableError.new(self) | ||
end | ||
|
@@ -113,12 +125,5 @@ def perform_operation | |
rescue | ||
raise NodeUnavailableError.new(self) | ||
end | ||
|
||
def slave_of?(master) | ||
info = fetch_info | ||
info[:role] == 'slave' && | ||
info[:master_host] == master.host && | ||
info[:master_port] == master.port.to_s | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
I believe doing this could cause a deadlock when
stop_waiting()
is called — there is a mutex that prevents multiple commands from happening on a redis connection at the same time, and theblpop()
call should have the lock at the time.This makes me realize that it would be pretty helpful if the tests were running against real local redis instances to catch issues like this that have to do with the implementation of the lower-level components.