mirror of
https://github.com/nadoo/glider.git
synced 2025-02-23 17:35:40 +08:00
ha: change dialer when there's a forwarder enabled with higher priority
This commit is contained in:
parent
b9017ff70a
commit
4f69372656
@ -6,7 +6,7 @@ import (
|
|||||||
"github.com/nadoo/glider/proxy"
|
"github.com/nadoo/glider/proxy"
|
||||||
)
|
)
|
||||||
|
|
||||||
// high availability forwarder
|
// high availability dialer
|
||||||
type haDialer struct{ *rrDialer }
|
type haDialer struct{ *rrDialer }
|
||||||
|
|
||||||
// newHADialer .
|
// newHADialer .
|
||||||
@ -15,8 +15,8 @@ func newHADialer(dialers []*proxy.Forwarder, webhost string, duration int) proxy
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (ha *haDialer) nextDialer(dstAddr string) *proxy.Forwarder {
|
func (ha *haDialer) nextDialer(dstAddr string) *proxy.Forwarder {
|
||||||
d := ha.fwdrs[ha.index]
|
d := ha.fwdrs[ha.Index()]
|
||||||
if !d.Enabled() {
|
if !d.Enabled() || d.Priority() < ha.Priority() {
|
||||||
d = ha.nextDialer(dstAddr)
|
d = ha.nextDialer(dstAddr)
|
||||||
}
|
}
|
||||||
return d
|
return d
|
||||||
|
@ -6,7 +6,7 @@ import (
|
|||||||
"github.com/nadoo/glider/proxy"
|
"github.com/nadoo/glider/proxy"
|
||||||
)
|
)
|
||||||
|
|
||||||
// latency based high availability forwarder
|
// latency based high availability dialer
|
||||||
type lhaDialer struct{ *rrDialer }
|
type lhaDialer struct{ *rrDialer }
|
||||||
|
|
||||||
// newLHADialer .
|
// newLHADialer .
|
||||||
|
@ -95,6 +95,18 @@ func (rr *rrDialer) nextDialer(dstAddr string) *proxy.Forwarder {
|
|||||||
return rr.fwdrs[idx]
|
return rr.fwdrs[idx]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Index returns the active forwarder's Index of rrDialer
|
||||||
|
func (rr *rrDialer) Index() int32 { return atomic.LoadInt32(&rr.index) }
|
||||||
|
|
||||||
|
// SetIndex sets the active forwarder's Index of rrDialer
|
||||||
|
func (rr *rrDialer) SetIndex(p int32) { atomic.StoreInt32(&rr.index, p) }
|
||||||
|
|
||||||
|
// Priority returns the active priority of rrDialer
|
||||||
|
func (rr *rrDialer) Priority() uint32 { return atomic.LoadUint32(&rr.priority) }
|
||||||
|
|
||||||
|
// SetPriority sets the active priority of rrDialer
|
||||||
|
func (rr *rrDialer) SetPriority(p uint32) { atomic.StoreUint32(&rr.priority, p) }
|
||||||
|
|
||||||
// Check implements the Checker interface
|
// Check implements the Checker interface
|
||||||
func (rr *rrDialer) Check() {
|
func (rr *rrDialer) Check() {
|
||||||
for i := 0; i < len(rr.fwdrs); i++ {
|
for i := 0; i < len(rr.fwdrs); i++ {
|
||||||
@ -147,15 +159,3 @@ func (rr *rrDialer) check(i int) {
|
|||||||
rc.Close()
|
rc.Close()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Index returns the active forwarder's Index of rrDialer
|
|
||||||
func (rr *rrDialer) Index() int32 { return atomic.LoadInt32(&rr.index) }
|
|
||||||
|
|
||||||
// SetIndex sets the active forwarder's Index of rrDialer
|
|
||||||
func (rr *rrDialer) SetIndex(p int32) { atomic.StoreInt32(&rr.index, p) }
|
|
||||||
|
|
||||||
// Priority returns the active priority of rrDialer
|
|
||||||
func (rr *rrDialer) Priority() uint32 { return atomic.LoadUint32(&rr.priority) }
|
|
||||||
|
|
||||||
// SetPriority sets the active priority of rrDialer
|
|
||||||
func (rr *rrDialer) SetPriority(p uint32) { atomic.StoreUint32(&rr.priority, p) }
|
|
||||||
|
Loading…
Reference in New Issue
Block a user