api

package
v0.0.0-...-3403bd2 Latest Latest
Warning

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

Go to latest
Published: Jun 30, 2018 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const (
	GetName    = "GET"
	SetName    = "SET"
	DelName    = "DEL"
	TxModeName = "TX"

	CreateDatabase = "CREATEDB"
	DeleteDatabase = "DELETEDB"

	RaftInstallSnapshotName = "I"
	RaftAppendName          = "A"
	RaftVoteName            = "V"
	RaftChunkName           = "C"
	RaftDoneName            = "D"
	RaftSnapshotName        = "RSNAPNAME"
	RaftSnapshotsName       = "RSNAPS"
	RaftSlice               = "RSLICE"
	RaftBootstrap           = "BOOTSTRAP"
	RaftJoinName            = "JOIN"
	RaftDemote              = "DEMOTE"
	RaftJoinSlaveName       = "RJOINSLAVE"
	RaftRemoveName          = "REMOVE"
	RaftStatsName           = "RAFTSTATS"
	RaftStateName           = "RAFTSTATE"
	RaftConfigName          = "RCONFIG"
	RaftLeaderName          = "LEADER"
	RaftShrinkName          = "RSHRINK"
)
View Source
const (
	Idle    int32 = iota
	Active        = 1
	Closing       = 2
	Closed        = 3
)

Variables

View Source
var (
	RaftInstall = []byte(RaftInstallSnapshotName)
	RaftAppend  = []byte(RaftAppendName)
	RaftVote    = []byte(RaftVoteName)
	RaftChunk   = []byte(RaftChunkName)
	RaftDone    = []byte(RaftDoneName)
	RaftJoin    = []byte(RaftJoinName)
	RaftStats   = []byte(RaftStatsName)
	RaftState   = []byte(RaftStateName)
	RaftLeader  = []byte(RaftLeaderName)
	RaftShrink  = []byte(RaftShrinkName)
)
View Source
var (
	OK     = Ok{}
	PONG   = Pong{}
	PING   = BulkString("PING")
	QUEUED = Queued{}
	NIL    = Nil{}
)
View Source
var ApplyCommands map[string]ApplyCommand
View Source
var Commands map[string]Command

Global registry of commands

View Source
var ErrInvalidParam = errors.New("invalid param")
View Source
var GlobalRaftID = RaftID{
	DatabaseID: -1,
	SliceID:    -1,
}
View Source
var (
	Workers = NewWorkerPool(context.Background(), 0, 0)
)

Functions

func ErrWake

func ErrWake(err error) error

func ParseBool

func ParseBool(arg []byte) (bool, error)

func Register

func Register(cmd Command)

func ReplyEquals

func ReplyEquals(reply CommandReply, reply2 CommandReply) bool

func ReplyType

func ReplyType(reply CommandReply) string

Types

type ApplyCommand

type ApplyCommand interface {
	Marshal(b []byte) []byte

	Unmarshal(b []byte) error

	Handle() CommandReply
}

type Array

type Array []CommandReply

func (Array) Handle

func (arr Array) Handle(ctx *Context) CommandReply

func (Array) Help

func (arr Array) Help() string

func (Array) IsError

func (arr Array) IsError() bool

func (Array) IsWorker

func (arr Array) IsWorker() bool

func (Array) Marshal

func (arr Array) Marshal(b []byte) []byte

func (Array) MarshalReply

func (arr Array) MarshalReply(b []byte) []byte

func (Array) Name

func (arr Array) Name() string

func (Array) Parse

func (arr Array) Parse(args [][]byte) Command

func (Array) UnmarshalReply

func (arr Array) UnmarshalReply(packet []byte, args [][]byte) error

type Bulk

type Bulk []byte

func (Bulk) Handle

func (by Bulk) Handle(ctx *Context) CommandReply

func (Bulk) Help

func (by Bulk) Help() string

func (Bulk) IsError

func (by Bulk) IsError() bool

func (Bulk) IsWorker

func (by Bulk) IsWorker() bool

func (Bulk) Marshal

func (by Bulk) Marshal(b []byte) []byte

func (Bulk) MarshalReply

func (by Bulk) MarshalReply(b []byte) []byte

func (Bulk) Name

func (by Bulk) Name() string

func (Bulk) Parse

func (by Bulk) Parse(args [][]byte) Command

func (Bulk) UnmarshalReply

func (by Bulk) UnmarshalReply(packet []byte, args [][]byte) error

type BulkString

type BulkString string

func (BulkString) Handle

func (s BulkString) Handle(ctx *Context) CommandReply

func (BulkString) Help

func (s BulkString) Help() string

func (BulkString) IsError

func (s BulkString) IsError() bool

func (BulkString) IsWorker

func (s BulkString) IsWorker() bool

func (BulkString) Marshal

func (s BulkString) Marshal(b []byte) []byte

func (BulkString) MarshalReply

func (s BulkString) MarshalReply(b []byte) []byte

func (BulkString) Name

func (s BulkString) Name() string

func (BulkString) Parse

func (s BulkString) Parse(args [][]byte) Command

func (BulkString) UnmarshalReply

func (s BulkString) UnmarshalReply(packet []byte, args [][]byte) error

type Command

type Command interface {
	Name() string

	Help() string

	IsError() bool

	// Flag to determine whether the command and be handled inline or
	// if it requires a worker.
	IsWorker() bool

	//
	Marshal(b []byte) []byte

	// Parses from a Redcon connection
	Parse(args [][]byte) Command

	// Invoke happens on the EvLoop
	Handle(ctx *Context) CommandReply
}

func ParseCommand

func ParseCommand(packet []byte, args [][]byte) Command

type CommandConn

type CommandConn interface {
	EvConn
	EvCloser
	EvData
	EvDetacher

	GetKind() ConnKind

	SetKind(kind ConnKind)

	//
	GetDurability() Durability

	//
	GetRaft() RaftService

	//
	SetRaft(raft RaftService)
}

type CommandReply

type CommandReply interface {
	IsError() bool

	//
	MarshalReply(b []byte) []byte

	//
	UnmarshalReply(packet []byte, args [][]byte) error
}

type CommandStats

type CommandStats struct {
	Name string
}

type ConnKind

type ConnKind byte
const (
	ConnCommand   ConnKind = 0
	ConnPubSub    ConnKind = 1
	ConnRaft      ConnKind = 2
	ConnQueue     ConnKind = 3
	ConnInstall   ConnKind = 4
	ConnHTTP      ConnKind = 5
	ConnWebSocket ConnKind = 6
)

type Context

type Context struct {
	Reason error

	Action evio.Action
	Kind   ConnKind

	// Durability setting
	Durability Durability

	Multi Multi

	// Assigned raft context
	// This is used for the RaftTransport to support multiple Raft clusters
	// over the same port
	Raft RaftService // Raft service for Raft connections

	Parse func(packet []byte, args [][]byte) Command
}

Represents a series of pipelined Commands in the context of a single call for a single connection or for Raft log applying.

func (*Context) AppendCommand

func (c *Context) AppendCommand(b []byte, command Command) []byte

func (*Context) GetDurability

func (c *Context) GetDurability() Durability

func (*Context) GetKind

func (c *Context) GetKind() ConnKind

func (*Context) GetRaft

func (c *Context) GetRaft() RaftService

func (*Context) SetKind

func (c *Context) SetKind(kind ConnKind)

func (*Context) SetRaft

func (c *Context) SetRaft(raft RaftService)

type ContextInput

type ContextInput struct {
	Context

	// Buffers
	In  []byte // in/ingress or "read" buffer
	Out []byte // out/egress or "write" buffer

	// Backlog
	Multi     bool
	MultiList []Command
	Backlog   []Command // commands that must wait until current worker finishes
	// contains filtered or unexported fields
}

func (*ContextInput) Input

func (c *ContextInput) Input(in []byte) (o []byte)

Parses a raw stream into a series of commands

func (*ContextInput) InputReply

func (c *ContextInput) InputReply(in []byte) (o []CommandReply)

type ContextPurpose

type ContextPurpose byte
const (
	Parse ContextPurpose = 0
	Apply ContextPurpose = 1
	Log   ContextPurpose = 2
)

type ContextReader

type ContextReader struct {
}

type ContextStats

type ContextStats struct {
}

type Database

type Database interface {
	Name()

	Slices()

	CreateTopic()

	DeleteTopic()

	CreateQueue()

	DeleteQueue()

	CreateTable()

	DeleteTable()
}

type Databases

type Databases interface {
	GetByName(name string) Database

	GetByID(id int32) Database
}

type Durability

type Durability int32
const (
	Low    Durability = -1
	Medium Durability = 0
	High   Durability = 1
)

type Err

type Err string

func (Err) Error

func (e Err) Error() string

func (Err) Handle

func (e Err) Handle(ctx *Context) CommandReply

func (Err) Help

func (e Err) Help() string

func (Err) IsError

func (e Err) IsError() bool

func (Err) IsWorker

func (e Err) IsWorker() bool

func (Err) Marshal

func (e Err) Marshal(b []byte) []byte

func (Err) MarshalReply

func (e Err) MarshalReply(b []byte) []byte

func (Err) Name

func (e Err) Name() string

func (Err) Parse

func (e Err) Parse(args [][]byte) Command

func (Err) UnmarshalReply

func (e Err) UnmarshalReply(packet []byte, args [][]byte) error

type EvCloser

type EvCloser interface {
	Close() error
	OnClosed()
}

type EvConn

type EvConn interface {
	Conn() evio.Conn
}

type EvData

type EvData interface {
	OnData(in []byte) (out []byte, action evio.Action)
}

type EvDetacher

type EvDetacher interface {
	Detach() error

	OnDetach(rwc io.ReadWriteCloser)
}

type Float

type Float float64

func (Float) Handle

func (c Float) Handle(ctx *Context) CommandReply

func (Float) Help

func (c Float) Help() string

func (Float) IsError

func (c Float) IsError() bool

func (Float) IsWorker

func (c Float) IsWorker() bool

func (Float) Marshal

func (c Float) Marshal(b []byte) []byte

func (Float) MarshalReply

func (c Float) MarshalReply(b []byte) []byte

func (Float) Name

func (c Float) Name() string

func (Float) Parse

func (c Float) Parse(args [][]byte) Command

func (Float) UnmarshalReply

func (c Float) UnmarshalReply(packet []byte, args [][]byte) error

type ICluster

type ICluster interface {
	Raft() RaftService
}
var Cluster ICluster

type IDrives

type IDrives interface {
}
var Drives IDrives

type Int

type Int int64

func ParseInt

func ParseInt(p []byte) (Int, error)

ParseInt parses an integer reply.

func (Int) Handle

func (c Int) Handle(ctx *Context) CommandReply

func (Int) Help

func (c Int) Help() string

func (Int) IsError

func (c Int) IsError() bool

func (Int) IsWorker

func (c Int) IsWorker() bool

func (Int) Marshal

func (c Int) Marshal(b []byte) []byte

func (Int) MarshalReply

func (c Int) MarshalReply(b []byte) []byte

func (Int) Name

func (c Int) Name() string

func (Int) Parse

func (c Int) Parse(args [][]byte) Command

func (Int) UnmarshalReply

func (c Int) UnmarshalReply(packet []byte, args [][]byte) error

type Multi

type Multi int
const (
	SINGLE Multi = iota
	MULTI
	DISCARD
	EXEC
)

type Nil

type Nil struct{}

func (Nil) Handle

func (n Nil) Handle(ctx *Context) CommandReply

func (Nil) Help

func (n Nil) Help() string

func (Nil) IsError

func (n Nil) IsError() bool

func (Nil) IsWorker

func (n Nil) IsWorker() bool

func (Nil) Marshal

func (n Nil) Marshal(b []byte) []byte

func (Nil) MarshalReply

func (n Nil) MarshalReply(b []byte) []byte

func (Nil) Name

func (n Nil) Name() string

func (Nil) Parse

func (n Nil) Parse(args [][]byte) Command

func (Nil) UnmarshalReply

func (n Nil) UnmarshalReply(packet []byte, args [][]byte) error

type Node

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

type Ok

type Ok struct{}

func (Ok) Handle

func (e Ok) Handle(ctx *Context) CommandReply

func (Ok) Help

func (c Ok) Help() string

func (Ok) IsError

func (c Ok) IsError() bool

func (Ok) IsMatch

func (o Ok) IsMatch(command CommandReply) bool

func (Ok) IsWorker

func (c Ok) IsWorker() bool

func (Ok) Marshal

func (e Ok) Marshal(b []byte) []byte

func (Ok) MarshalReply

func (e Ok) MarshalReply(b []byte) []byte

func (Ok) Name

func (c Ok) Name() string

func (Ok) Parse

func (e Ok) Parse(args [][]byte) Command

func (Ok) UnmarshalReply

func (e Ok) UnmarshalReply(packet []byte, args [][]byte) error

type Pong

type Pong struct{}

func (Pong) Handle

func (p Pong) Handle(ctx *Context) CommandReply

func (Pong) Help

func (p Pong) Help() string

func (Pong) IsError

func (p Pong) IsError() bool

func (Pong) IsWorker

func (p Pong) IsWorker() bool

func (Pong) Marshal

func (p Pong) Marshal(b []byte) []byte

func (Pong) MarshalReply

func (p Pong) MarshalReply(b []byte) []byte

func (Pong) Name

func (p Pong) Name() string

func (Pong) Parse

func (p Pong) Parse(args [][]byte) Command

func (Pong) UnmarshalReply

func (p Pong) UnmarshalReply(packet []byte, args [][]byte) error

type ProtocolError

type ProtocolError string

func (ProtocolError) Error

func (pe ProtocolError) Error() string

type Queued

type Queued struct{}

func (Queued) Handle

func (e Queued) Handle(ctx *Context) CommandReply

func (Queued) Help

func (c Queued) Help() string

func (Queued) IsError

func (c Queued) IsError() bool

func (Queued) IsWorker

func (c Queued) IsWorker() bool

func (Queued) Marshal

func (e Queued) Marshal(b []byte) []byte

func (Queued) MarshalReply

func (e Queued) MarshalReply(b []byte) []byte

func (Queued) Name

func (c Queued) Name() string

func (Queued) Parse

func (e Queued) Parse(args [][]byte) Command

func (Queued) UnmarshalReply

func (e Queued) UnmarshalReply(packet []byte, args [][]byte) error

type RaftFSM

type RaftFSM raft.FSM

type RaftID

type RaftID struct {
	DatabaseID int32
	SliceID    int32
}

type RaftService

type RaftService interface {
	IsLeader() bool

	Leader() raft.ServerAddress

	Stats() map[string]string

	State() raft.RaftState

	Append(payload []byte) CommandReply

	Vote(payload []byte) CommandReply

	Install(ctx *Context, arg []byte) Command

	Bootstrap() error

	Join(nodeID string, voter bool) error

	Demote(nodeID string) error

	Leave(nodeID string) error

	Configuration() (raft.ConfigurationFuture, error)
}

func GetRaftService

func GetRaftService(id RaftID) RaftService

type ReplyReader

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

func NewReplyReader

func NewReplyReader(b []byte) *ReplyReader

func (*ReplyReader) Next

func (rr *ReplyReader) Next() (CommandReply, error)

func (*ReplyReader) Reset

func (rr *ReplyReader) Reset(b []byte)

type SimpleString

type SimpleString string

func (SimpleString) Handle

func (s SimpleString) Handle(ctx *Context) CommandReply

func (SimpleString) Help

func (s SimpleString) Help() string

func (SimpleString) IsError

func (s SimpleString) IsError() bool

func (SimpleString) IsWorker

func (s SimpleString) IsWorker() bool

func (SimpleString) Marshal

func (s SimpleString) Marshal(b []byte) []byte

func (SimpleString) MarshalReply

func (s SimpleString) MarshalReply(b []byte) []byte

func (SimpleString) Name

func (s SimpleString) Name() string

func (SimpleString) Parse

func (s SimpleString) Parse(args [][]byte) Command

func (SimpleString) UnmarshalReply

func (s SimpleString) UnmarshalReply(packet []byte, args [][]byte) error

type Slice

type Slice interface {
	// Each slice has it's own Raft cluster
	Raft() RaftService

	Schema() Database

	Handle(ctx *Context, command Command)

	TopicAppend()

	QueueAppend()

	Set()

	Get()

	Iterate()

	Incr()

	Decr()
}

A slice is an instance of a Database that does not share state with any other slice within the schema or otherwise. It can be thought of as an independent database. State is consistently maintained through a Raft log. (CA of CAP) system.

Object definitions are inherited from it's Database. A Slice represents some range(s) of the total slots (16384) of the Database. Each record in a slice is assigned a Slot number usually based on the hash of it's key. A Slice's log is serialized but it's reads may happen in parallel.

To scale a Database add another Slice and let the Database re-balance.

type Store

type Store interface {
	Raft() RaftService

	//
	CreateDatabase()

	DeleteDatabase()

	Database() []Database

	GetSchema(id int32) Database
}

Cluster wide registry of schemas and Raft services.

type Topic

type Topic interface{}

type Transaction

type Transaction struct {
	Requests []ApplyCommand
	// contains filtered or unexported fields
}

Transaction is a single log entry in the Raft log.

type WithConnection

type WithConnection interface {
	Conn() evio.Conn

	ConnAction() evio.Action
}

type Worker

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

Maintains a cached goroutine that can process one job at a time and is returned back to a sync.Pool

type WorkerJob

type WorkerJob interface {
	Run()
}

type WorkerPool

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

func NewWorkerPool

func NewWorkerPool(ctx context.Context, min, max int) *WorkerPool

func (*WorkerPool) Dispatch

func (w *WorkerPool) Dispatch(job WorkerJob) bool

func (*WorkerPool) Get

func (w *WorkerPool) Get() *Worker

func (*WorkerPool) Name

func (w *WorkerPool) Name() string

func (*WorkerPool) PrintStats

func (w *WorkerPool) PrintStats()

func (*WorkerPool) Put

func (w *WorkerPool) Put(worker *Worker)

func (*WorkerPool) Register

func (w *WorkerPool) Register(registry metrics.Registry)

func (*WorkerPool) Stop

func (w *WorkerPool) Stop()

Jump to

Keyboard shortcuts

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