table

package
v1.0.3 Latest Latest
Warning

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

Go to latest
Published: May 7, 2015 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Overview

The official client API of GoTable. GoTable is a high performance NoSQL database.

Index

Constants

View Source
const (
	EcNotExist    = 1   // Key NOT exist
	EcOk          = 0   // Success
	EcCasNotMatch = -1  // CAS not match, get new CAS and try again
	EcTempFail    = -2  // Temporary failed, retry may fix this
	EcUnknownCmd  = -10 // Unknown cmd
	EcAuthFailed  = -11 // Authorize failed
	EcNoPrivilege = -12 // No access privilege
	EcWriteSlave  = -13 // Can NOT write slave directly
	EcSlaveCas    = -14 // Invalid CAS on slave for GET/MGET
	EcReadFail    = -15 // Read failed
	EcWriteFail   = -16 // Write failed
	EcDecodeFail  = -17 // Decode request PKG failed
	EcInvDbId     = -18 // Invalid DB ID (cannot be 255)
	EcInvRowKey   = -19 // RowKey length should be [1 ~ 255]
	EcInvValue    = -20 // Value length should be [0 ~ 1MB]
	EcInvPkgLen   = -21 // Pkg length should be less than 2MB
	EcInvScanNum  = -22 // Scan request number out of range
	EcScanEnded   = -23 // Already scan/dump to end
)

GoTable Error Code List

View Source
const Version = "1.0.3" // GoTable version

Variables

View Source
var (
	ErrShutdown     = errors.New("connection is shutdown")
	ErrCallNotReady = errors.New("call not ready to reply")
	ErrClosedPool   = errors.New("connection pool is closed")
	ErrNoValidAddr  = errors.New("no valid address")
)
View Source
var (
	ErrCasNotMatch = initErr(EcCasNotMatch, "cas not match")
	ErrTempFail    = initErr(EcTempFail, "temporary failed")
	ErrUnknownCmd  = initErr(EcUnknownCmd, "unknown cmd")
	ErrAuthFailed  = initErr(EcAuthFailed, "authorize failed")
	ErrNoPrivilege = initErr(EcNoPrivilege, "no access privilege")
	ErrWriteSlave  = initErr(EcWriteSlave, "can not write slave directly")
	ErrSlaveCas    = initErr(EcSlaveCas, "invalid cas on slave")
	ErrReadFail    = initErr(EcReadFail, "read failed")
	ErrWriteFail   = initErr(EcWriteFail, "write failed")
	ErrDecodeFail  = initErr(EcDecodeFail, "decode request pkg failed")
	ErrInvDbId     = initErr(EcInvDbId, "can not use admin db")
	ErrInvRowKey   = initErr(EcInvRowKey, "row key length out of range")
	ErrInvValue    = initErr(EcInvValue, "value length out of range")
	ErrInvPkgLen   = initErr(EcInvPkgLen, "pkg length out of range")
	ErrInvScanNum  = initErr(EcInvScanNum, "scan request number out of range")
	ErrScanEnded   = initErr(EcScanEnded, "already scan/dump to end")
)

Functions

This section is empty.

Types

type Addr

type Addr struct {
	Network string
	Address string
}

type Call

type Call struct {
	Done chan *Call // Reply channel
	// contains filtered or unexported fields
}

func (*Call) Reply

func (call *Call) Reply() (interface{}, error)

Get call reply. The real reply types are: Auth/Ping/(Z)Set/(Z)Del: nil; (Z)Get: GetReply; (Z)Incr: IncrReply; (Z)MGet: []GetReply; (Z)MSet: []SetReply; (Z)MDel: []DelReply; (Z)MIncr: []IncrReply; (Z)Scan: ScanReply; Dump: DumpReply;

type Client

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

A Client is a connection to GoTable server. It's safe to use in multiple goroutines.

func Dial

func Dial(network, address string) (*Client, error)

Dial connects to the address on the named network of GoTable server.

Known networks are "tcp", "tcp4" (IPv4-only), "tcp6" (IPv6-only), and "unix". For TCP networks, addresses have the form host:port. For Unix networks, the address must be a file system path.

It returns a connection Client to GoTable server.

func NewClient

func NewClient(conn net.Conn) *Client

Create a new connection Client to GoTable server.

func (*Client) Close

func (c *Client) Close() error

Close the connection.

func (*Client) NewContext

func (c *Client) NewContext(dbId uint8) *Context

Create a new client Context with selected dbId. All operations on the Context use the selected dbId.

type Context

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

Connection Context to GoTable server. It's safe to use in multiple goroutines.

func (*Context) Auth

func (c *Context) Auth(password string) error

Authenticate to the server.

func (*Context) Client

func (c *Context) Client() *Client

Get the underling connection Client of the Context.

func (*Context) DatabaseId

func (c *Context) DatabaseId() uint8

Get the selected database ID of the Context.

func (*Context) Del

func (c *Context) Del(tableId uint8, rowKey, colKey []byte,
	cas uint32) error

Delete the key in default column space. CAS is 0 for normal cases. Use the CAS returned by GET if you want to "lock" the record.

func (*Context) DumpDB

func (c *Context) DumpDB() (DumpReply, error)

Dump all tables in current DB(dbId in Context).

func (*Context) DumpMore

func (c *Context) DumpMore(last DumpReply) (DumpReply, error)

Dump more records.

func (*Context) DumpPivot

func (c *Context) DumpPivot(oneTable bool, tableId, colSpace uint8,
	rowKey, colKey []byte, score int64,
	startUnitId, endUnitId uint16) (DumpReply, error)

Dump records from the pivot record. If oneTable is true, only dump the selected table. If oneTable is false, dump all tables in current DB(dbId). The pivot record is excluded from the reply.

func (*Context) DumpTable

func (c *Context) DumpTable(tableId uint8) (DumpReply, error)

Dump the selected Table.

func (*Context) Get

func (c *Context) Get(tableId uint8, rowKey, colKey []byte, cas uint32) (
	value []byte, score int64, retCas uint32, err error)

Get value&score of the key in default column space. Parameter CAS is Compare-And-Swap, 2 means read data on master and return a new CAS, 1 means read data on master machine but without a new CAS, 0 means read data on any machine without a new CAS. On cluster mode, routing to master machine is automatically, but on a normal master/slave mode it should be done manually. If CAS 1&2 sent to a slave machine, error will be returned. For most cases, set CAS as 0. Return value nil means key not exist.

func (*Context) GoDel

func (c *Context) GoDel(tableId uint8, rowKey, colKey []byte,
	cas uint32, done chan *Call) (*Call, error)

Asynchronous DEL API.

func (*Context) GoGet

func (c *Context) GoGet(tableId uint8, rowKey, colKey []byte, cas uint32,
	done chan *Call) (*Call, error)

Asynchronous GET API.

func (*Context) GoIncr

func (c *Context) GoIncr(tableId uint8, rowKey, colKey []byte, score int64,
	cas uint32, done chan *Call) (*Call, error)

Asynchronous INCR API.

func (*Context) GoMDel

func (c *Context) GoMDel(args []DelArgs, done chan *Call) (*Call, error)

Asynchronous MDEL API.

func (*Context) GoMGet

func (c *Context) GoMGet(args []GetArgs, done chan *Call) (*Call, error)

Asynchronous MGET API.

func (*Context) GoMIncr

func (c *Context) GoMIncr(args []IncrArgs, done chan *Call) (*Call, error)

Asynchronous MINCR API.

func (*Context) GoMSet

func (c *Context) GoMSet(args []SetArgs, done chan *Call) (*Call, error)

Asynchronous MSET API.

func (*Context) GoPing

func (c *Context) GoPing(done chan *Call) (*Call, error)

Asynchronous PING API.

func (*Context) GoScan

func (c *Context) GoScan(tableId uint8, rowKey []byte,
	asc bool, num int, done chan *Call) (*Call, error)

Asynchronous SCAN API from MIN/MAX colKey.

func (*Context) GoScanPivot

func (c *Context) GoScanPivot(tableId uint8, rowKey, colKey []byte,
	asc bool, num int, done chan *Call) (*Call, error)

Asynchronous SCAN API from pivot record.

func (*Context) GoSet

func (c *Context) GoSet(tableId uint8, rowKey, colKey, value []byte, score int64,
	cas uint32, done chan *Call) (*Call, error)

Asynchronous SET API.

func (*Context) GoZDel

func (c *Context) GoZDel(tableId uint8, rowKey, colKey []byte,
	cas uint32, done chan *Call) (*Call, error)

Asynchronous ZDEL API.

func (*Context) GoZGet

func (c *Context) GoZGet(tableId uint8, rowKey, colKey []byte, cas uint32,
	done chan *Call) (*Call, error)

Asynchronous ZGET API.

func (*Context) GoZIncr

func (c *Context) GoZIncr(tableId uint8, rowKey, colKey []byte, score int64,
	cas uint32, done chan *Call) (*Call, error)

Asynchronous ZINCR API.

func (*Context) GoZScan

func (c *Context) GoZScan(tableId uint8, rowKey []byte,
	asc, orderByScore bool, num int, done chan *Call) (*Call, error)

Asynchronous ZSCAN API from MIN/MAX colKey and score.

func (*Context) GoZScanPivot

func (c *Context) GoZScanPivot(tableId uint8, rowKey, colKey []byte, score int64,
	asc, orderByScore bool, num int, done chan *Call) (*Call, error)

Asynchronous ZSCAN API from pivot record.

func (*Context) GoZSet

func (c *Context) GoZSet(tableId uint8, rowKey, colKey, value []byte, score int64,
	cas uint32, done chan *Call) (*Call, error)

Asynchronous ZSET API.

func (*Context) GoZmDel

func (c *Context) GoZmDel(args []DelArgs, done chan *Call) (*Call, error)

Asynchronous ZMDEL API.

func (*Context) GoZmGet

func (c *Context) GoZmGet(args []GetArgs, done chan *Call) (*Call, error)

Asynchronous ZMGET API.

func (*Context) GoZmIncr

func (c *Context) GoZmIncr(args []IncrArgs, done chan *Call) (*Call, error)

Asynchronous ZMINCR API.

func (*Context) GoZmSet

func (c *Context) GoZmSet(args []SetArgs, done chan *Call) (*Call, error)

Asynchronous ZMSET API.

func (*Context) Incr

func (c *Context) Incr(tableId uint8, rowKey, colKey []byte, score int64,
	cas uint32) (newValue []byte, newScore int64, err error)

Increase key/score in default column space. CAS is 0 for normal cases. Use the CAS returned by GET if you want to "lock" the record.

func (*Context) MDel

func (c *Context) MDel(args MDelArgs) ([]DelReply, error)

Delete multiple keys in default column space.

func (*Context) MGet

func (c *Context) MGet(args MGetArgs) ([]GetReply, error)

Get values&scores of multiple keys in default column space.

func (*Context) MIncr

func (c *Context) MIncr(args MIncrArgs) ([]IncrReply, error)

Increase multiple keys/scores in default column space.

func (*Context) MSet

func (c *Context) MSet(args MSetArgs) ([]SetReply, error)

Set multiple keys/values in default column space.

func (*Context) Ping

func (c *Context) Ping() error

Ping the server.

func (*Context) Scan

func (c *Context) Scan(tableId uint8, rowKey []byte,
	asc bool, num int) (ScanReply, error)

Scan columns of rowKey in default column space from MIN/MAX colKey. If asc is true SCAN start from the MIN colKey, else SCAN from the MAX colKey. It replies at most num records.

func (*Context) ScanMore

func (c *Context) ScanMore(last ScanReply) (ScanReply, error)

Scan/ZScan more records.

func (*Context) ScanPivot

func (c *Context) ScanPivot(tableId uint8, rowKey, colKey []byte,
	asc bool, num int) (ScanReply, error)

Scan columns of rowKey in default column space from pivot record. The colKey is the pivot record where scan starts. If asc is true SCAN in ASC order, else SCAN in DESC order. It replies at most num records. The pivot record is excluded from the reply.

func (*Context) Set

func (c *Context) Set(tableId uint8, rowKey, colKey, value []byte, score int64,
	cas uint32) error

Set key/value in default column space. CAS is 0 for normal cases. Use the CAS returned by GET if you want to "lock" the record.

func (*Context) ZDel

func (c *Context) ZDel(tableId uint8, rowKey, colKey []byte,
	cas uint32) error

Delete the key in "Z" sorted score column space. CAS is 0 for normal cases. Use the CAS returned by GET if you want to "lock" the record.

func (*Context) ZGet

func (c *Context) ZGet(tableId uint8, rowKey, colKey []byte, cas uint32) (
	value []byte, score int64, retCas uint32, err error)

Get value&score of the key in "Z" sorted score column space. Request and return parameters have the same meaning as the Get API.

func (*Context) ZIncr

func (c *Context) ZIncr(tableId uint8, rowKey, colKey []byte, score int64,
	cas uint32) (newValue []byte, newScore int64, err error)

Increase key/score in "Z" sorted score column space. CAS is 0 for normal cases. Use the CAS returned by GET if you want to "lock" the record.

func (*Context) ZScan

func (c *Context) ZScan(tableId uint8, rowKey []byte,
	asc, orderByScore bool, num int) (ScanReply, error)

Scan columns of rowKey in "Z" sorted score space from MIN/MAX colKey and score. If asc is true ZSCAN start from the MIN colKey and score, else ZSCAN from the MAX colKey and score. If orderByScore is true ZSCAN order by score+colKey, else ZSCAN order by colKey. It replies at most num records.

func (*Context) ZScanPivot

func (c *Context) ZScanPivot(tableId uint8, rowKey, colKey []byte, score int64,
	asc, orderByScore bool, num int) (ScanReply, error)

Scan columns of rowKey in "Z" sorted score space from pivot record. The colKey and score is the pivot record where scan starts. If asc is true ZSCAN in ASC order, else ZSCAN in DESC order. If orderByScore is true ZSCAN order by score+colKey, else ZSCAN order by colKey. It replies at most num records. The pivot record is excluded from the reply.

func (*Context) ZSet

func (c *Context) ZSet(tableId uint8, rowKey, colKey, value []byte, score int64,
	cas uint32) error

Set key/value in "Z" sorted score column space. CAS is 0 for normal cases. Use the CAS returned by GET if you want to "lock" the record.

func (*Context) ZmDel

func (c *Context) ZmDel(args MDelArgs) ([]DelReply, error)

Delete multiple keys in "Z" sorted score column space.

func (*Context) ZmGet

func (c *Context) ZmGet(args MGetArgs) ([]GetReply, error)

Get values&scores of multiple keys in "Z" sorted score column space.

func (*Context) ZmIncr

func (c *Context) ZmIncr(args MIncrArgs) ([]IncrReply, error)

Increase multiple keys/scores in "Z" sorted score column space.

func (*Context) ZmSet

func (c *Context) ZmSet(args MSetArgs) ([]SetReply, error)

Set multiple keys/values in "Z" sorted score column space.

type CtrlContext

type CtrlContext Context

Inner control context

func (*CtrlContext) DelUnit added in v1.0.3

func (c *CtrlContext) DelUnit(unitId uint16) error

Internal control command. DelUnit deletes one unit data.

func (*CtrlContext) Migrate

func (c *CtrlContext) Migrate(host string, unitId uint16) error

Internal control command. Migrate moves one unit data to another server on the fly.

func (*CtrlContext) SlaveOf

func (c *CtrlContext) SlaveOf(host string) error

Internal control command. SlaveOf can change the replication settings of a slave on the fly.

func (*CtrlContext) SlaveStatus

func (c *CtrlContext) SlaveStatus(migration bool, unitId uint16) (int, error)

Internal control command. SlaveStatus reads migration/slave status.

type DelArgs

type DelArgs GetArgs

type DelReply

type DelReply SetReply

type DumpKV

type DumpKV struct {
	TableId  uint8
	ColSpace uint8
	RowKey   []byte
	ColKey   []byte
	Value    []byte
	Score    int64
}

type DumpReply

type DumpReply struct {
	Kvs []DumpKV
	End bool // false: Not end yet; true: Has scan to end, stop now
	// contains filtered or unexported fields
}

type GetArgs

type GetArgs struct {
	TableId uint8
	RowKey  []byte
	ColKey  []byte
	Cas     uint32
}

type GetReply

type GetReply struct {
	ErrCode int8
	TableId uint8
	RowKey  []byte
	ColKey  []byte
	Value   []byte
	Score   int64
	Cas     uint32
}

type IncrArgs

type IncrArgs struct {
	TableId uint8
	RowKey  []byte
	ColKey  []byte
	Score   int64
	Cas     uint32
}

type IncrReply

type IncrReply struct {
	ErrCode int8
	TableId uint8
	RowKey  []byte
	ColKey  []byte
	Value   []byte
	Score   int64
}

type MDelArgs

type MDelArgs []DelArgs

func (*MDelArgs) Add

func (a *MDelArgs) Add(tableId uint8, rowKey, colKey []byte, cas uint32)

type MGetArgs

type MGetArgs []GetArgs

func (*MGetArgs) Add

func (a *MGetArgs) Add(tableId uint8, rowKey, colKey []byte, cas uint32)

type MIncrArgs

type MIncrArgs []IncrArgs

func (*MIncrArgs) Add

func (a *MIncrArgs) Add(tableId uint8, rowKey, colKey []byte, score int64, cas uint32)

type MSetArgs

type MSetArgs []SetArgs

func (*MSetArgs) Add

func (a *MSetArgs) Add(tableId uint8, rowKey, colKey, value []byte, score int64, cas uint32)

type Pool

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

func NewPool

func NewPool(as []Addr, connNum int) *Pool

func (*Pool) Close

func (p *Pool) Close()

func (*Pool) Get

func (p *Pool) Get() (*Client, error)

type ScanKV

type ScanKV struct {
	ColKey []byte
	Value  []byte
	Score  int64
}

type ScanReply

type ScanReply struct {
	TableId uint8
	RowKey  []byte
	Kvs     []ScanKV
	End     bool // false: Not end yet; true: Scan to end, stop now
	// contains filtered or unexported fields
}

type SetArgs

type SetArgs struct {
	TableId uint8
	RowKey  []byte
	ColKey  []byte
	Value   []byte
	Score   int64
	Cas     uint32
}

type SetReply

type SetReply struct {
	ErrCode int8
	TableId uint8
	RowKey  []byte
	ColKey  []byte
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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