backend

package
v0.0.0-...-e5281c0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 27, 2013 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Overview

Cassandra backend based on counters. As long as counters in cassandra can not be TTLed, this backend performs periodic garbage collections.

The implementation is pretty straightforward:

* Every counter in every time period is represented as a separate row * There are two tables: hits_even and hits_odd * Every day is numbered as even or odd (day number since epoch) * Even day counters are stored in hits_even, odd in hits_odd * The table that is not currently updated gets truncated once a day

Memory backend, used mostly for testing, but may be extended to become more useful in the future. In this case it'll need garbage collection.

Index

Constants

View Source
const (
	DefaultConnectTimeout    = time.Duration(200) * time.Millisecond
	DefaultReplicationFactor = 3
	DefaultCleanupHour       = 0
	DefaultCleanupMinute     = 30
)

Standard dial and read timeouts, can be overriden when supplying proxy settings

Variables

This section is empty.

Functions

This section is empty.

Types

type Backend

type Backend interface {
	// Used to retreive time for current stats.
	// Creates mostly for test reasons so we can override time in tests
	timeutils.TimeProvider

	// Get count of the given key in the time period
	GetCount(key string, period time.Duration) (int64, error)

	// Updates hitcount of the given key, with the given increment
	UpdateCount(key string, period time.Duration, increment int64) error
}

Stats backend, used to memorize counters for given keys to to request stats about upstreams and tokens

type CassandraBackend

type CassandraBackend struct {
	// contains filtered or unexported fields
}

func NewCassandraBackend

func NewCassandraBackend(config *CassandraConfig, timeProvider timeutils.TimeProvider) (*CassandraBackend, error)

func (*CassandraBackend) GetCount

func (b *CassandraBackend) GetCount(key string, period time.Duration) (int64, error)

func (*CassandraBackend) UpdateCount

func (b *CassandraBackend) UpdateCount(key string, period time.Duration, increment int64) error

func (*CassandraBackend) UtcNow

func (b *CassandraBackend) UtcNow() time.Time

type CassandraConfig

type CassandraConfig struct {
	Keyspace          string
	Consistency       gocql.Consistency
	Servers           []string
	ConnectTimeout    time.Duration
	ReplicationFactor int
	LaunchCleanup     bool
	CleanupTime       *CleanupTime
}

type CleanupTime

type CleanupTime struct {
	Hour   int
	Minute int
}

type FailingBackend

type FailingBackend struct {
}

All operation on this backend always fail

func (*FailingBackend) GetCount

func (b *FailingBackend) GetCount(key string, period time.Duration) (int64, error)

func (*FailingBackend) UpdateCount

func (b *FailingBackend) UpdateCount(key string, period time.Duration, increment int64) error

func (*FailingBackend) UtcNow

func (b *FailingBackend) UtcNow() time.Time

type MemoryBackend

type MemoryBackend struct {
	Hits         map[string]int64
	TimeProvider timeutils.TimeProvider
}

func NewMemoryBackend

func NewMemoryBackend(timeProvider timeutils.TimeProvider) (*MemoryBackend, error)

func (*MemoryBackend) GetCount

func (b *MemoryBackend) GetCount(key string, period time.Duration) (int64, error)

func (*MemoryBackend) UpdateCount

func (b *MemoryBackend) UpdateCount(key string, period time.Duration, increment int64) error

func (*MemoryBackend) UtcNow

func (b *MemoryBackend) UtcNow() time.Time

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL