common

package
v0.0.0-...-e1dc7cb Latest Latest
Warning

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

Go to latest
Published: Feb 7, 2013 License: BSD-2-Clause-Views Imports: 15 Imported by: 0

README

common

A bunch of stuff used by several sub packages in god.

Documentation

Index

Constants

View Source
const (
	Redundancy   = 3
	PingInterval = time.Second
)

Variables

View Source
var Switch = newSwitchboard()

Switch is the default Switchboard.

Functions

func AssertWithin

func AssertWithin(t *testing.T, f func() (string, bool), d time.Duration)

AssertWithin asserts that the given func returns a true bool within d, or it fires an error through t.

func BetweenIE

func BetweenIE(needle, fromInc, toExc []byte) (result bool)

BetweenIE returns whether needle is between fromInc, inclusive and toExc, exclusive.

func BetweenII

func BetweenII(needle, fromInc, toInc []byte) (result bool)

BetweenII returns whether needle is between fromInc and toInc, inclusive.

func DecodeBigInt

func DecodeBigInt(b []byte) (result *big.Int)

func DecodeFloat64

func DecodeFloat64(b []byte) (result float64, err error)

func DecodeInt64

func DecodeInt64(b []byte) (result int64, err error)

func EncodeBigInt

func EncodeBigInt(i *big.Int) []byte

func EncodeFloat64

func EncodeFloat64(f float64) []byte

func EncodeInt64

func EncodeInt64(i int64) []byte

func HexEncode

func HexEncode(b []byte) (result string)

HexEncode will encode the given bytes to a string, and pad it with 0 until it is at least twice the length of b.

func Max

func Max(i ...int) (result int)

func Max64

func Max64(i ...int64) (result int64)

func Min

func Min(i ...int) (result int)

func Min64

func Min64(i ...int64) (result int64)

func MustDecodeFloat64

func MustDecodeFloat64(b []byte) (result float64)

func MustDecodeInt64

func MustDecodeInt64(b []byte) (result int64)

func MustParseFloat64

func MustParseFloat64(s string) (result float64)

Types

type Conf

type Conf struct {
	TreeKey   []byte
	Data      map[string]string
	Timestamp int64
}

type ConfItem

type ConfItem struct {
	TreeKey   []byte
	Key       string
	Value     string
	Timestamp int64
	TTL       int
}

type DHashDescription

type DHashDescription struct {
	Addr         string
	Pos          []byte
	LastReroute  time.Time
	LastSync     time.Time
	LastMigrate  time.Time
	Timer        time.Time
	OwnedEntries int
	HeldEntries  int
	Load         float64
	Nodes        Remotes
}

DHashDescription contains a description of a dhash node.

func (DHashDescription) Describe

func (self DHashDescription) Describe() string

Describe will return a humanly readable string description of the dhash node.

type Index

type Index struct {
	N       int
	Existed bool
}

type Item

type Item struct {
	Key       []byte
	SubKey    []byte
	Value     []byte
	Exists    bool
	Timestamp int64
	TTL       int
	Index     int
	Sync      bool
}

func MergeItems

func MergeItems(arys []*[]Item, up bool) (result []Item)

MergeItems will merge the given slices of Items into a slice with the newest version of each Item, with regard to their keys.

type Range

type Range struct {
	Key      []byte
	Min      []byte
	Max      []byte
	MinInc   bool
	MaxInc   bool
	MinIndex int
	MaxIndex int
	Len      int
}

type Remote

type Remote struct {
	Pos  []byte
	Addr string
}

func (Remote) Call

func (self Remote) Call(service string, args, reply interface{}) error

func (Remote) Clone

func (self Remote) Clone() (result Remote)

func (Remote) Equal

func (self Remote) Equal(other Remote) bool

func (Remote) Go

func (self Remote) Go(service string, args, reply interface{}) *rpc.Call

func (Remote) Less

func (self Remote) Less(other Remote) bool

func (Remote) String

func (self Remote) String() string

type Remotes

type Remotes []Remote

func (Remotes) Clone

func (self Remotes) Clone() (result Remotes)

func (Remotes) Describe

func (self Remotes) Describe() string

func (Remotes) Equal

func (self Remotes) Equal(other []Remote) bool

type Ring

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

Ring contains an ordered set of routes to discord.Nodes. It can fetch predecessor, match and successor for any key or remote (remotes are ordeded first on position, then on address, so that we have a defined orded even between nodes with the same position).

func NewRing

func NewRing() *Ring

func NewRingNodes

func NewRingNodes(nodes Remotes) *Ring

func (*Ring) Add

func (self *Ring) Add(r Remote)

Add adds r to this Ring. If a Node with the same address is already present, it will be updated if needed.

func (*Ring) AddChangeListener

func (self *Ring) AddChangeListener(f RingChangeListener)

func (*Ring) Clean

func (self *Ring) Clean(predecessor, successor Remote)

Clean removes any Nodes in this Ring between predecessor and successor (exclusive).

func (*Ring) Clone

func (self *Ring) Clone() *Ring

Clone returns a copy of this Ring and its contents.

func (*Ring) Describe

func (self *Ring) Describe() string

Describe returns a humanly readable description of this Ring.

func (*Ring) Equal

func (self *Ring) Equal(other *Ring) bool

func (*Ring) GetSlot

func (self *Ring) GetSlot() []byte

GetSlot returns the biggest free spot in this Ring, assuming a maximum size 2 ^ (murmur.Size * 8).

func (*Ring) Hash

func (self *Ring) Hash() []byte

Hash returns a hash of the contents of this Ring.

func (*Ring) Nodes

func (self *Ring) Nodes() Remotes

Nodes returns a copy of the Nodes of this Ring.

func (*Ring) Predecessor

func (self *Ring) Predecessor(r Remote) Remote

func (*Ring) Random

func (self *Ring) Random() Remote

Random returns a random Node in this Ring.

func (*Ring) Redundancy

func (self *Ring) Redundancy() int

Redundancy returns the minimum of the number of nodes present and the Redundancy const.

func (*Ring) Remotes

func (self *Ring) Remotes(pos []byte) (before, at, after *Remote)

Remotes returns the predecessor of pos, any Remote at pos and the successor of pos.

func (*Ring) Remove

func (self *Ring) Remove(remote Remote)

Remove deletes any Nodes in this Ring with the same address as remote.

func (*Ring) SetNodes

func (self *Ring) SetNodes(nodes Remotes)

SetNodes copies the nodes to replace the Nodes in this Ring.

func (*Ring) Size

func (self *Ring) Size() int

func (*Ring) Successor

func (self *Ring) Successor(r Remote) Remote

func (*Ring) Validate

func (self *Ring) Validate()

Validate, used for testing, validates the orded in this Ring.

type RingChangeListener

type RingChangeListener func(ring *Ring) (keep bool)

RingChangeListener is a function listening to changes in a Ring (ie changes in Node composition or position).

type Switchboard

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

Switchboard is a simple map of net/rpc.Clients, to avoid having to set up new connections for each remote call.

func (*Switchboard) Call

func (self *Switchboard) Call(addr, service string, args, reply interface{}) (err error)

func (*Switchboard) Go

func (self *Switchboard) Go(addr, service string, args, reply interface{}) (call *rpc.Call)

type TimeLock

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

func NewTimeLock

func NewTimeLock() *TimeLock

func (*TimeLock) Load

func (self *TimeLock) Load() float64

func (*TimeLock) Lock

func (self *TimeLock) Lock()

func (*TimeLock) RLock

func (self *TimeLock) RLock()

func (*TimeLock) RUnlock

func (self *TimeLock) RUnlock()

func (*TimeLock) Unlock

func (self *TimeLock) Unlock()

Jump to

Keyboard shortcuts

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