forked from cadence-workflow/cadence
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Summary: This revision creates a layer on top of ringpop primitives. The plan is to use one ringpop ring for membership of all services, and use this layer to shard keys for every individual service. Reviewers: nx, maxim, sivakk, aravindv, samar Reviewed By: sivakk, aravindv, samar Subscribers: jenkins Differential Revision: https://code.uberinternal.com/D690749
- Loading branch information
Tamer Eldeeb
committed
Jan 11, 2017
1 parent
51d479e
commit 07738de
Showing
12 changed files
with
802 additions
and
57 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
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 |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package membership | ||
|
||
// HostInfo is a type that contains the info about a cadence host | ||
type HostInfo struct { | ||
addr string // ip:port | ||
labels map[string]string | ||
} | ||
|
||
// NewHostInfo creates a new HostInfo instance | ||
func NewHostInfo(addr string, labels map[string]string) *HostInfo { | ||
if labels == nil { | ||
labels = make(map[string]string) | ||
} | ||
return &HostInfo{ | ||
addr: addr, | ||
labels: labels, | ||
} | ||
} | ||
|
||
// GetAddress returns the ip:port address | ||
func (hi *HostInfo) GetAddress() string { | ||
return hi.addr | ||
} | ||
|
||
// Identity implements ringpop's Membership interface | ||
func (hi *HostInfo) Identity() string { | ||
// for now we just use the address as the identity | ||
return hi.addr | ||
} | ||
|
||
// Label implements ringpop's Membership interface | ||
func (hi *HostInfo) Label(key string) (value string, has bool) { | ||
value, has = hi.labels[key] | ||
return | ||
} | ||
|
||
// SetLabel sets the label. | ||
func (hi *HostInfo) SetLabel(key string, value string) { | ||
hi.labels[key] = value | ||
} |
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 |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package membership | ||
|
||
import "errors" | ||
|
||
// ErrUnknownService is thrown for a service that is not tracked by this instance | ||
var ErrUnknownService = errors.New("Service not tracked by Oracle") | ||
|
||
// ErrInsufficientHosts is thrown when there are not enough hosts to serve the request | ||
var ErrInsufficientHosts = errors.New("Not enough hosts to serve the request") | ||
|
||
// ErrListenerAlreadyExist is thrown on a duplicate AddListener call from the same listener | ||
var ErrListenerAlreadyExist = errors.New("Listener already exist for the service") | ||
|
||
type ( | ||
|
||
// ChangedEvent describes a change in membership | ||
ChangedEvent struct { | ||
HostsAdded []*HostInfo | ||
HostsUpdated []*HostInfo | ||
HostsRemoved []*HostInfo | ||
} | ||
|
||
// Monitor provides membership information for all cadence services. | ||
// It can be used to query which member host of a service is responsible for serving a given key. | ||
Monitor interface { | ||
Start() error | ||
Stop() | ||
Lookup(service string, key string) (*HostInfo, error) | ||
GetResolver(service string) (ServiceResolver, error) | ||
// AddListener adds a listener for this service. | ||
// The listener will get notified on the given | ||
// channel, whenever there is a membership change. | ||
// @service: The service to be listened on | ||
// @name: The name for identifying the listener | ||
// @notifyChannel: The channel on which the caller receives notifications | ||
AddListener(service string, name string, notifyChannel chan<- *ChangedEvent) error | ||
// RemoveListener removes a listener for this service. | ||
RemoveListener(service string, name string) error | ||
} | ||
|
||
// ServiceResolver provides membership information for a specific cadence service. | ||
// It can be used to resolve which member host is responsible for serving a given key. | ||
ServiceResolver interface { | ||
Lookup(key string) (*HostInfo, error) | ||
// AddListener adds a listener which will get notified on the given | ||
// channel, whenever membership changes. | ||
// @name: The name for identifying the listener | ||
// @notifyChannel: The channel on which the caller receives notifications | ||
AddListener(name string, notifyChannel chan<- *ChangedEvent) error | ||
// RemoveListener removes a listener for this service. | ||
RemoveListener(name string) error | ||
} | ||
) |
Oops, something went wrong.