Documentation
¶
Index ¶
- Variables
- type API
- type Bucket
- func (b *Bucket) IsZero() bool
- func (b *Bucket) MarshalBinary() ([]byte, error)
- func (b *Bucket) MarshalLogObject(enc zapcore.ObjectEncoder) error
- func (b *Bucket) Merge(others ...*Bucket)
- func (b *Bucket) String() string
- func (b *Bucket) Take(now time.Time, r Rate, n uint64) (remaining uint64, ok bool)
- func (b *Bucket) Tokens() uint64
- func (b *Bucket) UnmarshalBinary(data []byte) error
- type Command
- type LocalRepo
- type Rate
- type ReplicatedRepo
- type Repo
Constants ¶
This section is empty.
Variables ¶
var ErrNameTooLarge = fmt.Errorf("bucket name larger than %d", maxBucketNameLength)
ErrNameTooLarge is returns by Bucket.MarshalBinary if the name of the Bucket exceeds the length of 231.
Functions ¶
This section is empty.
Types ¶
type Bucket ¶
type Bucket struct {
// contains filtered or unexported fields
}
Bucket implements a simple Token Bucket with underlying CRDT PN-Counter semantics which allow it to be merged without coordination with other Buckets.
func (*Bucket) IsZero ¶
IsZero returns true if the Bucket's fields are zero valued (apart from the Name and Created timestamp).
func (*Bucket) MarshalBinary ¶
MarshalBinary implements the encoding.BinaryMarshaler interface.
func (*Bucket) MarshalLogObject ¶
func (b *Bucket) MarshalLogObject(enc zapcore.ObjectEncoder) error
MarshalLogObject implements the zap.ObjectMarshaler interface
func (*Bucket) Merge ¶
Merge merges multiple Buckets using PN-counter CRDT semantics with its counters, picking the largest value for each field.
func (*Bucket) Take ¶
Take attempts to take n tokens out of the Bucket with the given filling Rate at time now. It returns the number of remaing tokens and if the take was successful.
func (*Bucket) UnmarshalBinary ¶
UnmarshalBinary implements the encoding.BinaryUnmarshaler interface.
type Command ¶
type Command struct {
Log *zap.Logger
APIAddr string
NodeAddr string
PeerAddrs []string
Clock func() time.Time // For testing
ShutdownTimeout time.Duration
}
A Command to be used in testing and the cmd/patrol.
type LocalRepo ¶
type LocalRepo struct {
// contains filtered or unexported fields
}
A LocalRepo stores Buckets locally in-memory. It's safe for concurrent use.
func NewLocalRepo ¶
NewLocalRepo returns a new LocalRepo with the given Buckets in it.
type Rate ¶
Rate defines the maximum frequency of some events. Rate is represented as number of events per unit of time. A zero Rate allows no events.
type ReplicatedRepo ¶
type ReplicatedRepo struct {
// contains filtered or unexported fields
}
A ReplicatedRepo stores, retrieves and replicates Buckets across the cluster.
func NewReplicatedRepo ¶
func NewReplicatedRepo(log *zap.Logger, r Repo, addr string, peers []string) (*ReplicatedRepo, error)
NewReplicatedRepo returns a new Repo that receives and sends UDP packets from the given addr to all peers.
func (*ReplicatedRepo) GetBucket ¶
GetBucket gets a Bucket by its name from the local Repo. It creates if it doesn't exist, asking the cluster to send their most up to date version of the Bucket asynchronously.
func (*ReplicatedRepo) Receive ¶
func (r *ReplicatedRepo) Receive(ctx context.Context) error
Receive starts receiving and applying Bucket state updates from other peers.
func (*ReplicatedRepo) UpsertBucket ¶
UpsertBucket upserts the given Bucket and broadcasts to all nodes in the cluster.