Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( //ErrInvalidRange when range syntax is invalid ErrInvalidRange = fmt.Errorf("invalid range") //ErrNotRoutable when pool can't find a match for this hash ErrNotRoutable = fmt.Errorf("not routable") //ErrNotFound when key can't be found in a pool ErrNotFound = fmt.Errorf("not found") //ErrPoolNotFound when table reference a pool that is not configured ErrPoolNotFound = fmt.Errorf("pool not found") //ErrInvalidDestination ErrUnknownScheme = fmt.Errorf("unknown scheme") )
var ( //SupportedScheme list of supported url scheme SupportedScheme = []string{ "ardb", "zdb", "redis", } )
Functions ¶
Types ¶
type Config ¶
type Config struct {
Pools map[string]PoolConfig `yaml:"pools"`
Lookup []string `yaml:"lookup"`
Cache []string `yaml:"cache"`
}
Config defines config file format
func NewConfigFromFile ¶
NewConfigFromFile loads config from yaml file
type Destination ¶
Destination defines a route destination
func NewDestination ¶
func NewDestination(dest string) (Destination, error)
NewDestination parse and validate destination
type Pool ¶
type Pool interface {
Range
Route(h []byte) Destination
Get(key []byte) ([]byte, error)
Set(key []byte, data []byte) error
}
Pool defines a pool interface
type PoolConfig ¶
PoolConfig is a map from hash-range to destination
type PoolFactory ¶
PoolFactory defines a pool factory method
var ( //DefaultPoolFactory default pool implementation DefaultPoolFactory PoolFactory = NewScanPool )
type Router ¶
type Router struct {
// contains filtered or unexported fields
}
Router defines a router engine. The router will try the pools in the same order defined by the table. And write to cache if wasn't retrieved from the cache pool
type ScanPool ¶
type ScanPool struct {
Rules []Rule
// contains filtered or unexported fields
}
ScanPool defines a set of routing rules This implementation of pool does a sequential scan of the rules. That's not very efficient usually plus it always returns the first match.
More sophisticated implementation of the pool should balance the routing if more than rule matches the hash.
func (*ScanPool) Route ¶
func (p *ScanPool) Route(h []byte) Destination
Route matches hash against the pool and return the first matched destination
func (*ScanPool) Routes ¶
func (p *ScanPool) Routes(h []byte) []Destination
Routes returns all possible destinations for hash h.