common

package
v0.0.0-...-b29f263 Latest Latest
Warning

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

Go to latest
Published: Jun 16, 2016 License: Apache-2.0 Imports: 2 Imported by: 0

Documentation

Overview

Package common contains all protocol-agnostic types and interfaces, as well as some variables used by multiple other packages in the application. Metrics are useful in many places for tracking bytes written and read. Errors exist here to be the neutral representation of either protocol errors or other application errors that happen all over. Other interfaces and types used by multiple protocols are here so any protocol can be used on the front end as well as the back with the same intermediate representation.

Index

Constants

View Source
const (
	// RequestUnknown means the parser doesn't know what the request represents. Valid protocol
	// parsing but invalid values.
	RequestUnknown = iota

	// RequestGet represents both a single get and a multi-get, which take differen forms in
	// different protocols. This means it can also be the accumulation of many GETQ commands.
	RequestGet

	// RequestGat is a get-and-touch operation that retrieves the information while updating the TTL
	RequestGat

	// RequestGetE is a custom get which returns the TTL remaining with the data
	RequestGetE

	// RequestSet is to insert a new piece of data unconditionally. What that means is different
	// depending on L1 / L2 handling.
	RequestSet

	// RequestAdd will perform the same operations as set, but only if the key does not exist
	RequestAdd

	// RequestReplace will perform the same operations as set, but only if the key already exists
	RequestReplace

	// RequestDelete deletes a piece of data from all levels of cache
	RequestDelete

	// RequestTouch updates the TTL for the item specified to a new TTL
	RequestTouch

	// RequestNoop does nothing
	RequestNoop

	// RequestQuit closes the connection
	RequestQuit

	// RequestVersion replies with a string designating the current software version
	RequestVersion
)
View Source
const VersionString = "Rend 0.1"

Variables

View Source
var (
	MetricBytesReadRemote     = metrics.AddCounter("bytes_read_remote")
	MetricBytesReadLocal      = metrics.AddCounter("bytes_read_local")
	MetricBytesReadLocalL1    = metrics.AddCounter("bytes_read_local_l1")
	MetricBytesReadLocalL2    = metrics.AddCounter("bytes_read_local_l2")
	MetricBytesWrittenRemote  = metrics.AddCounter("bytes_written_remote")
	MetricBytesWrittenLocal   = metrics.AddCounter("bytes_written_local")
	MetricBytesWrittenLocalL1 = metrics.AddCounter("bytes_written_local_l1")
	MetricBytesWrittenLocalL2 = metrics.AddCounter("bytes_written_local_l2")

	// Errors used across the application
	ErrBadRequest = errors.New("CLIENT_ERROR bad request")
	ErrBadLength  = errors.New("CLIENT_ERROR length is not a valid integer")
	ErrBadFlags   = errors.New("CLIENT_ERROR flags is not a valid integer")
	ErrBadExptime = errors.New("CLIENT_ERROR exptime is not a valid integer")

	ErrNoError        = errors.New("Success")
	ErrKeyNotFound    = errors.New("ERROR Key not found")
	ErrKeyExists      = errors.New("ERROR Key already exists")
	ErrValueTooBig    = errors.New("ERROR Value too big")
	ErrInvalidArgs    = errors.New("ERROR Invalid arguments")
	ErrItemNotStored  = errors.New("ERROR Item not stored (CAS didn't match)")
	ErrBadIncDecValue = errors.New("ERROR Bad increment/decrement value")
	ErrAuth           = errors.New("ERROR Authentication error")
	ErrUnknownCmd     = errors.New("ERROR Unknown command")
	ErrNoMem          = errors.New("ERROR Out of memory")
	ErrNotSupported   = errors.New("ERROR Not supported")
	ErrInternal       = errors.New("ERROR Internal error")
	ErrBusy           = errors.New("ERROR Busy")
	ErrTempFailure    = errors.New("ERROR Temporary error")
)

Common metrics used across packages

Functions

func IsAppError

func IsAppError(err error) bool

IsAppError differentiates between protocol-defined errors that are relatively benign and other fatal errors like an IO error because of some socket problem or network issue. Make sure to keep this list in sync with the one above. It should contain all Err* that could come back from memcached itself

Types

type DeleteRequest

type DeleteRequest struct {
	Key    []byte
	Opaque uint32
}

DeleteRequest corresponds to common.RequestDelete. It contains all the information required to fulfill a delete request.

func (DeleteRequest) Opq

func (r DeleteRequest) Opq() uint32

type GATRequest

type GATRequest struct {
	Key     []byte
	Exptime uint32
	Opaque  uint32
}

GATRequest corresponds to common.RequestGat. It contains all the information required to fulfill a get-and-touch request.

func (GATRequest) Opq

func (r GATRequest) Opq() uint32

type GetEResponse

type GetEResponse struct {
	Key     []byte
	Data    []byte
	Opaque  uint32
	Flags   uint32
	Exptime uint32
	Miss    bool
	Quiet   bool
}

GetEResponse is used in the GetE protocol extension

type GetRequest

type GetRequest struct {
	Keys       [][]byte
	Opaques    []uint32
	Quiet      []bool
	NoopOpaque uint32
	NoopEnd    bool
}

GetRequest corresponds to common.RequestGet. It contains all the information required to fulfill a get requestGets are batch by default, so single gets and batch gets are both represented by the same type.

func (GetRequest) Opq

func (r GetRequest) Opq() uint32

type GetResponse

type GetResponse struct {
	Key    []byte
	Data   []byte
	Opaque uint32
	Flags  uint32
	Miss   bool
	Quiet  bool
}

GetResponse is used in both RequestGet and RequestGat handling. Both respond in the same manner but with different opcodes. It is binary-protocol specific, but is still a part of the interface of responder to make the handling code more protocol-agnostic.

type NoopRequest

type NoopRequest struct {
	Opaque uint32
}

NoopRequest corresponds to common.RequestNoop. It contains all the information required to fulfill a version request.

func (NoopRequest) Opq

func (r NoopRequest) Opq() uint32

type QuitRequest

type QuitRequest struct {
	Opaque uint32
	Quiet  bool
}

QuitRequest corresponds to common.RequestQuit. It contains all the information required to fulfill a quit request.

func (QuitRequest) Opq

func (r QuitRequest) Opq() uint32

type Request

type Request interface {
	Opq() uint32
}

type RequestParser

type RequestParser interface {
	Parse() (Request, RequestType, error)
}

RequestParser represents an interface to parse incoming requests. Each protocol provides its own implementation. The return value is an interface{}, but not all hope is lost. The return result is guaranteed by implementations to be castable to the type that matches the RequestType returned.

type RequestType

type RequestType int

RequestType is the protocol-agnostic identifier for the command

type Responder

type Responder interface {
	Set(opaque uint32, quiet bool) error
	Add(opaque uint32, quiet bool) error
	Replace(opaque uint32, quiet bool) error
	Get(response GetResponse) error
	GetEnd(opaque uint32, noopEnd bool) error
	GetE(response GetEResponse) error
	GAT(response GetResponse) error
	Delete(opaque uint32) error
	Touch(opaque uint32) error
	Noop(opaque uint32) error
	Quit(opaque uint32, quiet bool) error
	Version(opaque uint32) error
	Error(opaque uint32, reqType RequestType, err error) error
}

Responder is the interface for a protocol to respond to different commands. It responds in whatever way is appropriate, including doing nothing or panic()-ing for unsupported interactions. Unsupported interactions are OK to panic() on because they should never be returned from the corresponding RequestParser.

type SetRequest

type SetRequest struct {
	Key     []byte
	Data    []byte
	Flags   uint32
	Exptime uint32
	Opaque  uint32
	Quiet   bool
}

SetRequest corresponds to common.RequestSet. It contains all the information required to fulfill a set request.

func (SetRequest) Opq

func (r SetRequest) Opq() uint32

type TouchRequest

type TouchRequest struct {
	Key     []byte
	Exptime uint32
	Opaque  uint32
}

TouchRequest corresponds to common.RequestTouch. It contains all the information required to fulfill a touch request.

func (TouchRequest) Opq

func (r TouchRequest) Opq() uint32

type VersionRequest

type VersionRequest struct {
	Opaque uint32
}

VersionRequest corresponds to common.RequestVersion. It contains all the information required to fulfill a version request.

func (VersionRequest) Opq

func (r VersionRequest) Opq() uint32

Jump to

Keyboard shortcuts

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