Skip to content

Commit

Permalink
SelectedHost: added Token function
Browse files Browse the repository at this point in the history
This allows tokenAwareHostPolicy return token from ExecutableQuery.

Co-authored-by: Henrik Johansson <[email protected]>
Co-authored-by: Michał Matczuk <[email protected]>
  • Loading branch information
2 people authored and dahankzter committed Oct 10, 2018
1 parent 2900c39 commit 0cabf96
Showing 1 changed file with 19 additions and 7 deletions.
26 changes: 19 additions & 7 deletions policies.go
Original file line number Diff line number Diff line change
Expand Up @@ -312,16 +312,24 @@ type HostSelectionPolicy interface {
// selection policy.
type SelectedHost interface {
Info() *HostInfo
Token() token
Mark(error)
}

type selectedHost HostInfo
type selectedHost struct {
info *HostInfo
token token
}

func (host selectedHost) Info() *HostInfo {
return host.info
}

func (host *selectedHost) Info() *HostInfo {
return (*HostInfo)(host)
func (host selectedHost) Token() token {
return host.token
}

func (host *selectedHost) Mark(err error) {}
func (host selectedHost) Mark(err error) {}

// NextHost is an iteration function over picked hosts
type NextHost func() SelectedHost
Expand Down Expand Up @@ -361,7 +369,7 @@ func (r *roundRobinHostPolicy) Pick(qry ExecutableQuery) NextHost {
}
host := hosts[(pos)%uint32(len(hosts))]
i++
return (*selectedHost)(host)
return selectedHost{info: host}
}
}

Expand Down Expand Up @@ -568,7 +576,7 @@ func (t *tokenAwareHostPolicy) Pick(qry ExecutableQuery) NextHost {

if h.IsUp() && t.fallback.IsLocal(h) {
used[h] = true
return (*selectedHost)(h)
return selectedHost{info: h, token: token}
}
}

Expand Down Expand Up @@ -715,6 +723,10 @@ func (host selectedHostPoolHost) Info() *HostInfo {
return host.info
}

func (host selectedHostPoolHost) Token() token {
return nil
}

func (host selectedHostPoolHost) Mark(err error) {
ip := host.info.ConnectAddress().String()

Expand Down Expand Up @@ -794,7 +806,7 @@ func (d *dcAwareRR) Pick(q ExecutableQuery) NextHost {
}
host := hosts[(pos)%uint32(len(hosts))]
i++
return (*selectedHost)(host)
return selectedHost{info: host}
}
}

Expand Down

0 comments on commit 0cabf96

Please sign in to comment.