hlld

package module
v0.0.0-...-0d48314 Latest Latest
Warning

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

Go to latest
Published: Jan 31, 2016 License: MIT Imports: 8 Imported by: 0

README

go-hlld

Provides the hlld package that implements a client library for the HyperLogLog daemon (HLLD). HyperLogLogs provide an extremely efficient method of cardinality estimation. The client library supports pipelining for extremely high throughput.

Documentation

The full documentation is available on Godoc.

Example

Below is a simple example of usage

// Create a client
client, err := hlld.Dial("hlld-server:1234")
if err != nil {
    panic("could not dial")
}

// Create a new set, custom precision
createCommand, err := hlld.NewCreateCommand("foo")
if err != nil {
    panic("failed to make command")
}

// Start the command
future, err := client.Execute(createCommand)
if err != nil {
    panic("failed to make command")
}

// Wait for the command to finish
if err := future.Error(); err != nil {
    panic("command failed")
}

// Check the result
ok, err := createCommand.Result()
if !ok || err != nil {
    panic("failed to make set")
}

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrClientClosed is used if the client is closed
	ErrClientClosed = fmt.Errorf("client closed")
)

Functions

This section is empty.

Types

type Client

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

Client is used to interact with an hlld server

func Dial

func Dial(addr string) (*Client, error)

Dial is a short hand to dial a new connection

func NewClient

func NewClient(conn net.Conn, config *Config) (*Client, error)

NewClient is used to create a new client by wrapping an existing connection

func (*Client) Close

func (c *Client) Close() error

Close is used to shut down the client

func (*Client) Execute

func (c *Client) Execute(cmd Command) (*Future, error)

Execute starts command execution and returns a future

type Command

type Command interface {
	Encode(*bufio.Writer) error
	Decode(*bufio.Reader) error
}

Command is used to represent any command that can be sent to HLLD. It must be able to encode and decode from the wire.

type Config

type Config struct {
	// MaxPipeline is the maximum number of commands to pipeline
	MaxPipeline int

	// Timeout is the read or write timeout
	Timeout time.Duration
}

Config is used to parameterize the client

func DefaultConfig

func DefaultConfig() *Config

DefaultConfig is used as the default client configuration

func (*Config) Validate

func (c *Config) Validate() error

Validate is used to sanity check the configuration

type CreateCommand

type CreateCommand struct {
	// SetName is the name of the set to create
	SetName string

	// Precision is the number of bits used for the bucket, the higher
	// precision will reduce the errors at the cost of using more memory.A
	// By default this is unspecified and computed based on the ErrThreshold.
	Precision int

	// ErrThreshold is used to control the tolerable error. Higher thresholds
	// require less precision and less memory. It is optional and can be unspecified
	// to use the server default.
	ErrThreshold float64

	// InMemory can be set to true to prevent the set from ever being
	// paged out to disk. This is not recommended as it prevents cold
	// sets from leaving memory.
	InMemory bool
	// contains filtered or unexported fields
}

CreateCommand is used to make a new set

func NewCreateCommand

func NewCreateCommand(name string) (*CreateCommand, error)

NewCreateCommand is used to prepare a new create command

func (*CreateCommand) Decode

func (c *CreateCommand) Decode(r *bufio.Reader) error

func (*CreateCommand) Encode

func (c *CreateCommand) Encode(w *bufio.Writer) error

func (*CreateCommand) Result

func (c *CreateCommand) Result() (bool, error)

type FlushCommand

type FlushCommand struct {
	// SetName is the optional name of the set to create
	SetName string
	// contains filtered or unexported fields
}

FlushCommand is used to force a flush to disk

func NewFlushCommand

func NewFlushCommand(name string) (*FlushCommand, error)

NewFlushCommand is used to flush keys to disk, optionally restricted to a specific set

func (*FlushCommand) Decode

func (c *FlushCommand) Decode(r *bufio.Reader) error

func (*FlushCommand) Encode

func (c *FlushCommand) Encode(w *bufio.Writer) error

func (*FlushCommand) Result

func (c *FlushCommand) Result() (bool, error)

type Future

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

Future is used to wrap a command and return a future

func NewFuture

func NewFuture(cmd Command) *Future

NewFuture returns a new future

func (*Future) Command

func (f *Future) Command() Command

Command returns the underlying command

func (*Future) Error

func (f *Future) Error() error

Error blocks until the future is complete

type InfoCommand

type InfoCommand struct {
	// SetName is the name of the set
	SetName string
	// contains filtered or unexported fields
}

InfoCommand is used to make a new set

func NewInfoCommand

func NewInfoCommand(name string) (*InfoCommand, error)

NewInfoCommand is used to query a specific set

func (*InfoCommand) Decode

func (c *InfoCommand) Decode(r *bufio.Reader) error

func (*InfoCommand) Encode

func (c *InfoCommand) Encode(w *bufio.Writer) error

func (*InfoCommand) Result

func (c *InfoCommand) Result() (*SetInfo, bool, error)

type ListCommand

type ListCommand struct {
	// Prefix is the prefix to filter
	Prefix string
	// contains filtered or unexported fields
}

ListCommand is used to make a new set

func NewListCommand

func NewListCommand(prefix string) (*ListCommand, error)

NewListCommand is used to list the sets, filtering on an optional prefix

func (*ListCommand) Decode

func (c *ListCommand) Decode(r *bufio.Reader) error

func (*ListCommand) Encode

func (c *ListCommand) Encode(w *bufio.Writer) error

func (*ListCommand) Result

func (c *ListCommand) Result() ([]*ListEntry, error)

type ListEntry

type ListEntry struct {
	Name         string
	ErrThreshold float64
	Precision    int
	Size         uint64
	Storage      uint64
}

ListEntry is used to provide the details of a set when listing

type SetCommand

type SetCommand struct {
	// Command is invoked on the set
	Command string

	// SetName is the name of the set to create
	SetName string
	// contains filtered or unexported fields
}

SetCommand is used to act on a set

func NewClearCommand

func NewClearCommand(name string) (*SetCommand, error)

NewClearCommand is used to remove a set from management, but leave on disk

func NewCloseCommand

func NewCloseCommand(name string) (*SetCommand, error)

NewCloseCommand is used to close a set out of memory

func NewDropCommand

func NewDropCommand(name string) (*SetCommand, error)

NewDropCommand is used to drop a set

func (*SetCommand) Decode

func (c *SetCommand) Decode(r *bufio.Reader) error

func (*SetCommand) Encode

func (c *SetCommand) Encode(w *bufio.Writer) error

func (*SetCommand) Result

func (c *SetCommand) Result() (bool, error)

type SetInfo

type SetInfo struct {
	// InMemory is true if the set is currently in memory
	InMemory bool

	// PageIns is the number of times the set has been paged in
	PageIns uint64

	// PageOuts is the number of times the set has been paged out
	PageOuts uint64

	// ErrThreshold is the error tolerance of the set
	ErrThreshold float64

	// Precision is the number of precision bits used
	Precision uint64

	// Sets is the number of write operations
	Sets uint64

	// Size is the estimated cardinaality of the set
	Size uint64

	// Storage is the disk space requirements of the set
	Storage uint64
}

SetInfo contains the results of a query

type SetKeysCommand

type SetKeysCommand struct {
	// SetName is the name of the set to create
	SetName string

	// Keys is the keys to set
	Keys []string
	// contains filtered or unexported fields
}

SetKeysCommand is used to set keys in a set

func NewSetKeysCommand

func NewSetKeysCommand(name string, keys []string) (*SetKeysCommand, error)

NewSetKeysCommand is used to set keys in a set

func (*SetKeysCommand) Decode

func (c *SetKeysCommand) Decode(r *bufio.Reader) error

func (*SetKeysCommand) Encode

func (c *SetKeysCommand) Encode(w *bufio.Writer) error

func (*SetKeysCommand) Result

func (c *SetKeysCommand) Result() (bool, error)

Jump to

Keyboard shortcuts

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