-
Notifications
You must be signed in to change notification settings - Fork 31
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
router: add callro methods based on node zone #391
base: master
Are you sure you want to change the base?
Changes from 1 commit
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 |
---|---|---|
|
@@ -577,13 +577,35 @@ local function replicaset_template_multicallro(prefer_replica, balance) | |
local function pick_next_replica(replicaset, now) | ||
local r | ||
local master = replicaset.master | ||
|
||
if balance then | ||
local prefered_zone = replicaset.priority_list[1].zone | ||
local i = #replicaset.priority_list | ||
while i > 0 do | ||
r = replicaset_balance_replica(replicaset) | ||
i = i - 1 | ||
if r:is_connected() and (not prefer_replica or r ~= master) and | ||
replica_check_backoff(r, now) then | ||
replica_check_backoff(r, now) | ||
then | ||
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. Please, revert unnecessary changes like these. These 3 lines didn't have to change at all. Besides, we never put |
||
-- Pick a replica according prefered zone (highest priority replica zone) in round-robin manner. | ||
if balance == 2 and prefered_zone then | ||
-- save current rr-cursor position | ||
local cbi = replicaset.balance_i | ||
-- find next replica | ||
local nr = replicaset_balance_replica(replicaset) | ||
|
||
if prefered_zone and r.zone and r.zone == prefered_zone -- current replica is in prefered_zone | ||
and nr.zone and nr.zone ~= prefered_zone -- next replica is from different zone (reached prefered_zone replicas) | ||
and (not prefer_replica or nr ~= master) | ||
then | ||
-- reset cursor to the main position | ||
replicaset.balance_i = 1 | ||
else | ||
-- restore rr-cursor position | ||
replicaset.balance_i = cbi | ||
end | ||
end | ||
|
||
return r | ||
end | ||
end | ||
|
@@ -637,6 +659,7 @@ local function replicaset_template_multicallro(prefer_replica, balance) | |
end | ||
end | ||
opts.timeout = timeout | ||
|
||
net_status, storage_status, retval, err = | ||
replica_call(replica, func, args, opts) | ||
now = fiber_clock() | ||
|
@@ -990,8 +1013,10 @@ local replicaset_mt = { | |
callrw = replicaset_master_call; | ||
callro = replicaset_template_multicallro(false, false); | ||
callbro = replicaset_template_multicallro(false, true); | ||
callbzro = replicaset_template_multicallro(false, 2); | ||
callre = replicaset_template_multicallro(true, false); | ||
callbre = replicaset_template_multicallro(true, true); | ||
callbzre = replicaset_template_multicallro(true, 2); | ||
map_call = replicaset_map_call, | ||
update_master = replicaset_update_master, | ||
}; | ||
|
@@ -1235,6 +1260,7 @@ local function buildall(sharding_cfg) | |
local function replica_cmp_weight(r1, r2) | ||
-- Master has priority over replicas with the same | ||
-- weight. | ||
|
||
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. Please, drop this line. |
||
if r1.weight == r2.weight then | ||
return r1 == new_replicaset.master | ||
else | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -576,11 +576,15 @@ local function router_call_impl(router, bucket_id, mode, prefer_replica, | |
local call | ||
if mode == 'read' then | ||
if prefer_replica then | ||
if balance then | ||
if balance == 2 then | ||
call = 'callbzre' | ||
elseif balance then | ||
call = 'callbre' | ||
else | ||
call = 'callre' | ||
end | ||
elseif balance == 2 then | ||
call = 'callbzro' | ||
elseif balance then | ||
call = 'callbro' | ||
else | ||
|
@@ -698,6 +702,10 @@ local function router_callbro(router, bucket_id, ...) | |
return router_call_impl(router, bucket_id, 'read', false, true, ...) | ||
end | ||
|
||
local function router_callbzro(router, bucket_id, ...) | ||
return router_call_impl(router, bucket_id, 'read', false, 2, ...) | ||
end | ||
|
||
local function router_callrw(router, bucket_id, ...) | ||
return router_call_impl(router, bucket_id, 'write', false, false, ...) | ||
end | ||
|
@@ -710,6 +718,10 @@ local function router_callbre(router, bucket_id, ...) | |
return router_call_impl(router, bucket_id, 'read', true, true, ...) | ||
end | ||
|
||
local function router_callbzre(router, bucket_id, ...) | ||
return router_call_impl(router, bucket_id, 'read', true, 2, ...) | ||
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. If we want to introduce such feature, we should probably make API more explicit. Using 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. Updated, thank you. |
||
end | ||
|
||
local function router_call(router, bucket_id, opts, ...) | ||
local mode, prefer_replica, balance | ||
if opts then | ||
|
@@ -1660,6 +1672,8 @@ local router_mt = { | |
call = router_make_api(router_call), | ||
callro = router_make_api(router_callro), | ||
callbro = router_make_api(router_callbro), | ||
callbzro = router_make_api(router_callbzro), | ||
callbzre = router_make_api(router_callbzre), | ||
callrw = router_make_api(router_callrw), | ||
callre = router_make_api(router_callre), | ||
callbre = router_make_api(router_callbre), | ||
|
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.
Please, drop not needed empty lines.