Documentation ¶
Overview ¶
Package ringpop is a library that maintains a consistent hash ring atop a gossip-based membership protocol. It can be used by applications to arbitrarily shard data in a scalable and fault-tolerant manner.
Index ¶
- Constants
- Variables
- func DeserializeThrift(b []byte, s athrift.TStruct) error
- func SerializeThrift(s athrift.TStruct) ([]byte, error)
- type Arg
- type IdentityResolver
- type Interface
- type Option
- func Channel(ch shared.TChannel) Option
- func Clock(c clock.Clock) Option
- func FaultyPeriod(period time.Duration) Option
- func HashRingConfig(c *hashring.Configuration) Option
- func Identity(hostport string) Option
- func IdentityResolverFunc(resolver IdentityResolver) Option
- func LogLevels(levels map[string]logging.Level) Option
- func Logger(l log.Logger) Option
- func MembershipChecksumStatPeriod(period time.Duration) Option
- func RingChecksumStatPeriod(period time.Duration) Option
- func Statter(s log.StatsReporter) Option
- func SuspectPeriod(period time.Duration) Option
- func TombstonePeriod(period time.Duration) Option
- type Ringpop
- func (rp *Ringpop) App() string
- func (rp *Ringpop) Bootstrap(bootstrapOpts *swim.BootstrapOptions) ([]string, error)
- func (rp *Ringpop) Checksum() (uint32, error)
- func (rp *Ringpop) CountReachableMembers() (int, error)
- func (rp *Ringpop) Destroy()
- func (rp *Ringpop) Forward(dest string, keys []string, request []byte, service, endpoint string, ...) ([]byte, error)
- func (rp *Ringpop) GetReachableMembers() ([]string, error)
- func (rp *Ringpop) HandleEvent(event events.Event)
- func (rp *Ringpop) HandleOrForward(key string, request []byte, response *[]byte, service, endpoint string, ...) (bool, error)
- func (rp *Ringpop) Lookup(key string) (string, error)
- func (rp *Ringpop) LookupN(key string, n int) ([]string, error)
- func (rp *Ringpop) Ready() bool
- func (rp *Ringpop) RegisterListener(l events.EventListener)
- func (rp *Ringpop) Uptime() (time.Duration, error)
- func (rp *Ringpop) WhoAmI() (string, error)
Constants ¶
const StatPeriodDefault = time.Duration(5 * time.Second)
StatPeriodDefault defines the default emission period for a periodic stat.
const StatPeriodNever = time.Duration(-1)
StatPeriodNever defines a "period" which disables a periodic stat emission.
Variables ¶
var ( // ErrNotBootstrapped is returned by public methods which require the ring to // be bootstrapped before they can operate correctly. ErrNotBootstrapped = errors.New("ringpop is not bootstrapped") // ErrEphemeralIdentity is returned by the identity resolver if TChannel is // using port 0 and is not listening (and thus has not been assigned a port by // the OS). ErrEphemeralIdentity = errors.New("unable to resolve this node's identity from channel that is not yet listening") )
Functions ¶
func DeserializeThrift ¶
DeserializeThrift takes a byte slice and attempts to write it into the given thrift struct using the thrift binary protocol. This is a temporary measure before frames can forwarded directly past the endpoint to the proper destinaiton.
func SerializeThrift ¶
SerializeThrift takes a thrift struct and returns the serialized bytes of that struct using the thrift binary protocol. This is a temporary measure before frames can forwarded directly past the endpoint to the proper destinaiton.
Types ¶
type IdentityResolver ¶
IdentityResolver is a function that returns the listen interface/port that Ringpop should identify as.
type Interface ¶
type Interface interface { Destroy() App() string WhoAmI() (string, error) Uptime() (time.Duration, error) RegisterListener(l events.EventListener) Bootstrap(opts *swim.BootstrapOptions) ([]string, error) Checksum() (uint32, error) Lookup(key string) (string, error) LookupN(key string, n int) ([]string, error) GetReachableMembers() ([]string, error) CountReachableMembers() (int, error) HandleOrForward(key string, request []byte, response *[]byte, service, endpoint string, format tchannel.Format, opts *forward.Options) (bool, error) Forward(dest string, keys []string, request []byte, service, endpoint string, format tchannel.Format, opts *forward.Options) ([]byte, error) }
Interface specifies the public facing methods a user of ringpop is able to use.
type Option ¶
An Option is a modifier functions that configure/modify a real Ringpop object.
There are typically two types of runtime options you can provide: flags (functions that modify the object) and value options (functions the accept user-specific arguments and then return a function that modifies the object).
For more information, see: http://commandcenter.blogspot.com/2014/01/self-referential-functions-and-design.html
func Channel ¶
Channel is used to provide a TChannel instance that Ringpop should use for all communication.
Example:
rp, err := ringpop.New("my-app", ringpop.Channel(myChannel))
Channel is a required option. The constructor will throw an error if this option is not present.
func Clock ¶ added in v0.3.0
Clock is used to set the Clock mechanism. Testing harnesses will typically replace this with a mocked clock.
func FaultyPeriod ¶ added in v0.4.0
FaultyPeriod configures the period Ringpop keeps a faulty node in its memberlist. Even though the node will not receive any traffic it is still present in the list in case it will come back online later. After this timeout ringpop will remove the node from its membership list permanently. If a node happens to come back after it has been removed from the membership Ringpop still allows it to join and take its old position in the hashring. To remove the node from the distributed membership it will mark it as a tombstone which can be removed from every members membership list independently.
func HashRingConfig ¶
func HashRingConfig(c *hashring.Configuration) Option
HashRingConfig takes a `HashRingConfiguration` struct that can be used to configure the hash ring.
Example:
rp, err := ringpop.New("my-app", ringpop.Channel(myChannel), ringpop.HashRingConfig(&HashRingConfiguration{ ReplicaPoints: 100, }), )
See documentation on the `HashRingConfiguration` struct for more information about what options are available.
func Identity ¶
Identity is used to specify a static hostport string as this Ringpop instance's identity.
Example:
ringpop.New("my-app", ringpop.Channel(myChannel), ringpop.Identity("10.32.12.2:21130"), )
You should make sure the identity matches the listening address of the TChannel object.
By default, you do not need to provide an identity. If you do not provide one, the identity will be resolved automatically by the default resolver.
func IdentityResolverFunc ¶
func IdentityResolverFunc(resolver IdentityResolver) Option
IdentityResolverFunc is used to specify a function that will called when the Ringpop instance needs to resolve its identity (typically, on bootstrap).
func LogLevels ¶ added in v0.3.0
LogLevels is used to set the severity log level for all Ringpop named loggers.
func Logger ¶
Logger is used to specify a bark-compatible logger that will be used for all Ringpop logging. If a logger is not provided, one will be created automatically.
func MembershipChecksumStatPeriod ¶ added in v0.3.0
MembershipChecksumStatPeriod configures the period between emissions of the stat 'membership.checksum-periodic'. Using a value <=0 (or StatPeriodNever) will disable emission of this stat. Using a value in (0, 10ms) will return an error, as that value is unrealistically small. Normal values must therefore be >=10ms. StatPeriodDefault defines the default.
func RingChecksumStatPeriod ¶ added in v0.3.0
RingChecksumStatPeriod configures the period between emissions of the stat 'ring.checksum-periodic'. Using a value <=0 (or StatPeriodNever) will disable emission of this stat. Using a value in (0, 10ms) will return an error, as that value is unrealistically small. Normal values must therefore be >=10ms. StatPeriodDefault defines the default.
func Statter ¶
func Statter(s log.StatsReporter) Option
Statter is used to specify a bark-compatible (bark.StatsReporter) stats reporter that will be used to record ringpop stats. If a statter is not provided, stats will be emitted to a null stats-reporter.
func SuspectPeriod ¶ added in v0.4.0
SuspectPeriod configures the period it takes ringpop to declare a node faulty after ringpop has first detected the node to be unresponsive to a healthcheck. When a node is declared faulty it is removed from the consistent hashring and stops forwarding traffic to that node. All keys previously routed to that node will then be routed to the new owner of the key
func TombstonePeriod ¶ added in v0.4.0
TombstonePeriod configures the period of the last time of the lifecycle in of a node in the membership list. This period should give the gossip protocol the time it needs to disseminate this change. If configured too short the node in question might show up again in faulty state in the distributed memberlist of Ringpop.
type Ringpop ¶
type Ringpop struct {
// contains filtered or unexported fields
}
Ringpop is a consistent hashring that uses a gossip protocol to disseminate changes around the ring.
func (*Ringpop) App ¶
App returns the name of the application this Ringpop instance belongs to. The application name is set in the constructor when the Ringpop instance is created.
func (*Ringpop) Bootstrap ¶
func (rp *Ringpop) Bootstrap(bootstrapOpts *swim.BootstrapOptions) ([]string, error)
Bootstrap starts communication for this Ringpop instance.
When Bootstrap is called, this Ringpop instance will attempt to contact other instances from the DiscoverProvider.
If no seed hosts are provided, a single-node cluster will be created.
func (*Ringpop) Checksum ¶
Checksum returns the current checksum of this Ringpop instance's hashring.
func (*Ringpop) CountReachableMembers ¶
CountReachableMembers returns the number of members currently in this instance's membership list that aren't faulty.
func (*Ringpop) Destroy ¶
func (rp *Ringpop) Destroy()
Destroy stops all communication. Note that this does not close the TChannel instance that was passed to Ringpop in the constructor. Once an instance is destroyed, it cannot be restarted.
func (*Ringpop) Forward ¶
func (rp *Ringpop) Forward(dest string, keys []string, request []byte, service, endpoint string, format tchannel.Format, opts *forward.Options) ([]byte, error)
Forward forwards the request to given destination host and returns the response.
func (*Ringpop) GetReachableMembers ¶
GetReachableMembers returns a slice of members currently in this instance's membership list that aren't faulty.
func (*Ringpop) HandleEvent ¶
HandleEvent is used to satisfy the swim.EventListener interface. No touchy.
func (*Ringpop) HandleOrForward ¶
func (rp *Ringpop) HandleOrForward(key string, request []byte, response *[]byte, service, endpoint string, format tchannel.Format, opts *forward.Options) (bool, error)
HandleOrForward returns true if the request should be handled locally, or false if it should be forwarded to a different node. If false is returned, forwarding is taken care of internally by the method, and, if no error has occured, the response is written in the provided response field.
func (*Ringpop) Lookup ¶
Lookup returns the address of the server in the ring that is responsible for the specified key. It returns an error if the Ringpop instance is not yet initialized/bootstrapped.
func (*Ringpop) LookupN ¶
LookupN returns the addresses of all the servers in the ring that are responsible for the specified key. It returns an error if the Ringpop instance is not yet initialized/bootstrapped.
func (*Ringpop) Ready ¶
Ready returns whether or not ringpop is bootstrapped and ready to receive requests.
func (*Ringpop) RegisterListener ¶
func (rp *Ringpop) RegisterListener(l events.EventListener)
RegisterListener adds a listener to the ringpop. The listener's HandleEvent method should be thread safe.
Source Files ¶
Directories ¶
Path | Synopsis |
---|---|
Godeps
|
|
_workspace/src/github.com/Sirupsen/logrus
Package logrus is a structured logger for Go, completely API compatible with the standard library logger.
|
Package logrus is a structured logger for Go, completely API compatible with the standard library logger. |
_workspace/src/github.com/cactus/go-statsd-client/statsd
Package statsd provides a StatsD client implementation that is safe for concurrent use by multiple goroutines and for efficiency can be created and reused.
|
Package statsd provides a StatsD client implementation that is safe for concurrent use by multiple goroutines and for efficiency can be created and reused. |
_workspace/src/github.com/davecgh/go-spew/spew
Package spew implements a deep pretty printer for Go data structures to aid in debugging.
|
Package spew implements a deep pretty printer for Go data structures to aid in debugging. |
_workspace/src/github.com/pmezard/go-difflib/difflib
Package difflib is a partial port of Python difflib module.
|
Package difflib is a partial port of Python difflib module. |
_workspace/src/github.com/rcrowley/go-metrics
Go port of Coda Hale's Metrics library <https://github.com/rcrowley/go-metrics> Coda Hale's original work: <https://github.com/codahale/metrics>
|
Go port of Coda Hale's Metrics library <https://github.com/rcrowley/go-metrics> Coda Hale's original work: <https://github.com/codahale/metrics> |
_workspace/src/github.com/rcrowley/go-metrics/stathat
Metrics output to StatHat.
|
Metrics output to StatHat. |
_workspace/src/github.com/stretchr/objx
objx - Go package for dealing with maps, slices, JSON and other data.
|
objx - Go package for dealing with maps, slices, JSON and other data. |
_workspace/src/github.com/stretchr/testify/assert
Package assert provides a set of comprehensive testing tools for use with the normal Go testing system.
|
Package assert provides a set of comprehensive testing tools for use with the normal Go testing system. |
_workspace/src/github.com/stretchr/testify/mock
Provides a system by which it is possible to mock your objects and verify calls are happening as expected.
|
Provides a system by which it is possible to mock your objects and verify calls are happening as expected. |
_workspace/src/github.com/stretchr/testify/require
Alternative testing tools which stop test execution if test failed.
|
Alternative testing tools which stop test execution if test failed. |
_workspace/src/github.com/stretchr/testify/suite
The suite package contains logic for creating testing suite structs and running the methods on those structs as tests.
|
The suite package contains logic for creating testing suite structs and running the methods on those structs as tests. |
_workspace/src/github.com/uber-common/bark
Package bark provides an abstraction for loggers and stats reporters used in Uber's Go libraries.
|
Package bark provides an abstraction for loggers and stats reporters used in Uber's Go libraries. |
_workspace/src/github.com/uber/tchannel-go
Package tchannel implements Go bindings for the TChannel protocol (https://github.com/uber/tchannel).
|
Package tchannel implements Go bindings for the TChannel protocol (https://github.com/uber/tchannel). |
_workspace/src/github.com/uber/tchannel-go/examples/keyvalue/gen-go/keyvalue
Package keyvalue is generated code used to make or handle TChannel calls using Thrift.
|
Package keyvalue is generated code used to make or handle TChannel calls using Thrift. |
_workspace/src/github.com/uber/tchannel-go/examples/thrift/gen-go/test
Package test is generated code used to make or handle TChannel calls using Thrift.
|
Package test is generated code used to make or handle TChannel calls using Thrift. |
_workspace/src/github.com/uber/tchannel-go/hyperbahn/gen-go/hyperbahn
Package hyperbahn is generated code used to make or handle TChannel calls using Thrift.
|
Package hyperbahn is generated code used to make or handle TChannel calls using Thrift. |
_workspace/src/github.com/uber/tchannel-go/thrift
Package thrift adds support to use Thrift services over TChannel.
|
Package thrift adds support to use Thrift services over TChannel. |
_workspace/src/github.com/uber/tchannel-go/thrift/benchclient
benchclient is used to make requests to a specific server.
|
benchclient is used to make requests to a specific server. |
_workspace/src/github.com/uber/tchannel-go/thrift/gen-go/test
Package test is generated code used to make or handle TChannel calls using Thrift.
|
Package test is generated code used to make or handle TChannel calls using Thrift. |
_workspace/src/github.com/uber/tchannel-go/thrift/thrift-gen
thrift-gen generates code for Thrift services that can be used with the uber/tchannel/thrift package.
|
thrift-gen generates code for Thrift services that can be used with the uber/tchannel/thrift package. |
_workspace/src/github.com/uber/tchannel-go/trace
Package trace provides methods to submit Zipkin style spans to TCollector.
|
Package trace provides methods to submit Zipkin style spans to TCollector. |
_workspace/src/github.com/uber/tchannel-go/trace/thrift/gen-go/tcollector
Package tcollector is generated code used to make or handle TChannel calls using Thrift.
|
Package tcollector is generated code used to make or handle TChannel calls using Thrift. |
_workspace/src/golang.org/x/net/context
Package context defines the Context type, which carries deadlines, cancelation signals, and other request-scoped values across API boundaries and between processes.
|
Package context defines the Context type, which carries deadlines, cancelation signals, and other request-scoped values across API boundaries and between processes. |
examples
|
|
pingpong/gen-go/pingpong
Package pingpong is generated code used to make or handle TChannel calls using Thrift.
|
Package pingpong is generated code used to make or handle TChannel calls using Thrift. |
Package forward provides a mechanism to forward TChannel requests.
|
Package forward provides a mechanism to forward TChannel requests. |
Package hashring provides a hashring implementation that uses a red-black Tree.
|
Package hashring provides a hashring implementation that uses a red-black Tree. |
Package replica extends Ringpop functionality by providing a mechanism to replicate a request to multiple nodes in the ring.
|
Package replica extends Ringpop functionality by providing a mechanism to replicate a request to multiple nodes in the ring. |
scripts
|
|
test
|
|
thrift/pingpong
Package pingpong is generated code used to make or handle TChannel calls using Thrift.
|
Package pingpong is generated code used to make or handle TChannel calls using Thrift. |