client

package
v0.0.0-...-b800c40 Latest Latest
Warning

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

Go to latest
Published: Aug 7, 2017 License: Apache-2.0 Imports: 26 Imported by: 0

Documentation

Index

Constants

View Source
const (
	RESP_SUCCESS string = "success"
	RESP_ERROR   string = "error"
)

Variables

View Source
var ConnPoolCallback func(host string, source string, start time.Time, err error)

ConnPoolTimeout is notified whenever connections are acquired from a pool.

View Source
var ErrIndexNotFound = fmt.Errorf("Index not found")

These error strings need to be in sync with common.ErrIndexNotFound and common.ErrIndexNotReady.

View Source
var ErrIndexNotReady = fmt.Errorf("Index not ready for serving queries")
View Source
var ErrorClientUninitialized = errors.New("queryport.clientUninitialized")

ErrorClientUninitialized

View Source
var ErrorClosedPool = errors.New("queryport.closedPool")

ErrorClosedPool

View Source
var ErrorExpectedTimestamp = errors.New("queryport.expectedTimestamp")

ErrorExpectedTimestamp

View Source
var ErrorIndexNotFound = errors.New("queryport.indexNotFound")

ErrorIndexNotFound

View Source
var ErrorInstanceNotFound = errors.New("queryport.instanceNotFound")

ErrorInstanceNotFound

View Source
var ErrorInvalidConsistency = errors.New("queryport.invalidConsistency")

ErrorInvalidConsistency

View Source
var ErrorNoHost = errors.New("queryport.client.noHost")

ErrorNoHost

View Source
var ErrorNoPool = errors.New("queryport.errorNoPool")

ErrorNoPool

View Source
var ErrorNotImplemented = errors.New("queryport.notImplemented")

ErrorNotImplemented

View Source
var ErrorPoolTimeout = errors.New("queryport.connPoolTimeout")

ErrorPoolTimeout

View Source
var ErrorProtocol = errors.New("queryport.client.protocol")

ErrorProtocol

Functions

This section is empty.

Types

type BridgeAccessor

type BridgeAccessor interface {
	// Synchronously update current server metadata to the client
	// A Refresh call followed by a Sync() ensures that client is
	// up to date wrt the server.
	Sync() error

	// Refresh shall refresh to latest set of index managed by GSI
	// cluster, cache it locally and return the list of index.
	Refresh() ([]*mclient.IndexMetadata, uint64, uint64, error)

	// Nodes shall return a map of adminport and queryport for indexer
	// nodes.
	Nodes() ([]*IndexerService, error)

	// CreateIndex and return defnID of created index.
	// name
	//      index name
	// bucket
	//      bucket name in which index is defined.
	// using
	//      token should always be GSI.
	// exprType
	//      token specifies how in interpret partnExpr, whereExpr, secExprs
	// partnExpr
	//      marshalled expression of type `exprType` that emits partition
	//      value from a kv-document.
	// whereExpr
	//      marshalled predicate-expression of type `exprType` that emits
	//      a boolean from a kv-document.
	// secExprs
	//      marshalled list of expression of type `exprType` that emits
	//      an array of secondary-key values from a kv-document.
	// isPrimary
	//      specify whether the index is created on docid.
	// with
	//      JSON marshalled description about index deployment (and more...).
	CreateIndex(
		name, bucket, using, exprType, partnExpr, whereExpr string,
		secExprs []string, desc []bool, isPrimary bool,
		with []byte) (defnID uint64, err error)

	// BuildIndexes to build a deferred set of indexes. This call implies
	// that indexes specified are already created.
	BuildIndexes(defnIDs []uint64) error

	// MoveIndex to move a set of indexes to different node.
	MoveIndex(defnID uint64, with map[string]interface{}) error

	// DropIndex to drop index specified by `defnID`.
	// - if index is in deferred build state, it shall be removed
	//   from deferred list.
	DropIndex(defnID uint64) error

	// GetScanports shall return list of queryports for all indexer in
	// the cluster.
	GetScanports() (queryports []string)

	// GetScanport shall fetch queryport address for indexer,
	// if `retry` is ZERO, pick the indexer under least
	// load, else do a round-robin, based on the retry count,
	// if more than one indexer is found hosing the index or an
	// equivalent index.
	GetScanport(
		defnID uint64,
		retry int,
		excludes map[uint64]bool) (queryport string, targetDefnID uint64, targetInstID uint64, rollbackTime int64, ok bool)

	// GetIndex will return the index-definition structure for defnID.
	GetIndexDefn(defnID uint64) *common.IndexDefn

	// IndexState returns the current state of index `defnID` and error.
	IndexState(defnID uint64) (common.IndexState, error)

	// IsPrimary returns whether index is on primary key.
	IsPrimary(defnID uint64) bool

	// Timeit will add `value` to incrementalAvg for index-load.
	Timeit(instID uint64, value float64)

	// Close this accessor.
	Close()
}

BridgeAccessor for Create,Drop,List,Refresh operations.

type ClientSettings

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

func NewClientSettings

func NewClientSettings(needRefresh bool) *ClientSettings

func (*ClientSettings) BackfillLimit

func (s *ClientSettings) BackfillLimit() int32

func (*ClientSettings) Close

func (s *ClientSettings) Close()

func (*ClientSettings) DisablePruneReplica

func (s *ClientSettings) DisablePruneReplica() bool

func (*ClientSettings) NumReplica

func (s *ClientSettings) NumReplica() int32

func (*ClientSettings) ScanLagItem

func (s *ClientSettings) ScanLagItem() uint64

func (*ClientSettings) ScanLagPercent

func (s *ClientSettings) ScanLagPercent() float64

type CompositeElementFilter

type CompositeElementFilter struct {
	Low       interface{}
	High      interface{}
	Inclusion Inclusion
}

type GsiAccessor

type GsiAccessor interface {
	BridgeAccessor

	// LookupStatistics for a single secondary-key.
	LookupStatistics(
		defnID uint64, requestId string, v common.SecondaryKey) (common.IndexStatistics, error)

	// RangeStatistics for index range.
	RangeStatistics(
		defnID uint64, requestId string, low, high common.SecondaryKey,
		inclusion Inclusion) (common.IndexStatistics, error)

	// Lookup scan index between low and high.
	Lookup(
		defnID uint64, requestId string, values []common.SecondaryKey,
		distinct bool, limit int64,
		cons common.Consistency, vector *TsConsistency,
		callb ResponseHandler) error

	// Range scan index between low and high.
	Range(
		defnID uint64, requestId string, low, high common.SecondaryKey,
		inclusion Inclusion, distinct bool, limit int64,
		cons common.Consistency, vector *TsConsistency,
		callb ResponseHandler) error

	// ScanAll for full table scan.
	ScanAll(
		defnID uint64, requestId string, limit int64,
		cons common.Consistency, vector *TsConsistency,
		callb ResponseHandler) error

	// Multiple scans with composite index filters
	MultiScan(
		defnID uint64, requestId string, scans Scans,
		reverse, distinct bool, projection *IndexProjection, offset, limit int64,
		cons common.Consistency, vector *TsConsistency,
		callb ResponseHandler) error

	// CountLookup of all entries in index.
	CountLookup(
		defnID uint64, requestId string, values []common.SecondaryKey,
		cons common.Consistency, vector *TsConsistency) (int64, error)

	// CountRange of all entries in index.
	CountRange(
		defnID uint64, requestId string,
		low, high common.SecondaryKey, inclusion Inclusion,
		cons common.Consistency, vector *TsConsistency) (int64, error)

	// Count using MultiScan
	MultiScanCount(
		defnID uint64, requestId string,
		scans Scans, distinct bool,
		cons common.Consistency, vector *TsConsistency) (int64, error)
}

GsiAccessor for index operation on GSI cluster.

type GsiClient

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

GsiClient for accessing GSI cluster. The client shall use `adminport` for meta-data operation and `queryport` for index-scan related operations.

func NewGsiClient

func NewGsiClient(
	cluster string, config common.Config) (c *GsiClient, err error)

NewGsiClient returns client to access GSI cluster.

func NewGsiClientWithSettings

func NewGsiClientWithSettings(
	cluster string, config common.Config, needRefresh bool) (c *GsiClient, err error)

func (*GsiClient) Bridge

func (c *GsiClient) Bridge() BridgeAccessor

func (*GsiClient) BucketSeqnos

func (c *GsiClient) BucketSeqnos(
	bucketn string, hash64 uint64) (*TsConsistency, error)

BucketSeqnos will return the current vbucket-timestamp using GET_SEQNOS command.

func (*GsiClient) BucketTs

func (c *GsiClient) BucketTs(bucketn string) (*TsConsistency, error)

BucketTs will return the current vbucket-timestamp using STATS command.

func (*GsiClient) BuildIndexes

func (c *GsiClient) BuildIndexes(defnIDs []uint64) error

BuildIndexes implements BridgeAccessor{} interface.

func (*GsiClient) Close

func (c *GsiClient) Close()

Close the client and all open connections with server.

func (*GsiClient) CountLookup

func (c *GsiClient) CountLookup(
	defnID uint64, requestId string, values []common.SecondaryKey,
	cons common.Consistency, vector *TsConsistency) (count int64, err error)

CountLookup to count number entries for given set of keys.

func (*GsiClient) CountRange

func (c *GsiClient) CountRange(
	defnID uint64, requestId string,
	low, high common.SecondaryKey,
	inclusion Inclusion,
	cons common.Consistency, vector *TsConsistency) (count int64, err error)

CountRange to count number entries in the given range.

func (*GsiClient) CreateIndex

func (c *GsiClient) CreateIndex(
	name, bucket, using, exprType, partnExpr, whereExpr string,
	secExprs []string, isPrimary bool,
	with []byte) (defnID uint64, err error)

CreateIndex implements BridgeAccessor{} interface.

func (*GsiClient) CreateIndex2

func (c *GsiClient) CreateIndex2(
	name, bucket, using, exprType, partnExpr, whereExpr string,
	secExprs []string, desc []bool, isPrimary bool,
	with []byte) (defnID uint64, err error)

CreateIndex implements BridgeAccessor{} interface.

func (*GsiClient) DescribeError

func (c *GsiClient) DescribeError(err error) string

DescribeError return error description as human readable string.

func (*GsiClient) DropIndex

func (c *GsiClient) DropIndex(defnID uint64) error

DropIndex implements BridgeAccessor{} interface.

func (*GsiClient) IndexState

func (c *GsiClient) IndexState(defnID uint64) (common.IndexState, error)

IndexState implements BridgeAccessor{} interface.

func (*GsiClient) Lookup

func (c *GsiClient) Lookup(
	defnID uint64, requestId string, values []common.SecondaryKey,
	distinct bool, limit int64,
	cons common.Consistency, vector *TsConsistency,
	callb ResponseHandler) (err error)

Lookup scan index between low and high.

func (*GsiClient) LookupStatistics

func (c *GsiClient) LookupStatistics(
	defnID uint64, requestId string, value common.SecondaryKey) (common.IndexStatistics, error)

LookupStatistics for a single secondary-key.

func (*GsiClient) MoveIndex

func (c *GsiClient) MoveIndex(defnID uint64, with map[string]interface{}) error

MoveIndex implements BridgeAccessor{} interface.

func (*GsiClient) MultiScan

func (c *GsiClient) MultiScan(
	defnID uint64, requestId string, scans Scans, reverse,
	distinct bool, projection *IndexProjection, offset, limit int64,
	cons common.Consistency, vector *TsConsistency,
	callb ResponseHandler) (err error)

func (*GsiClient) MultiScanCount

func (c *GsiClient) MultiScanCount(
	defnID uint64, requestId string,
	scans Scans, distinct bool,
	cons common.Consistency, vector *TsConsistency) (count int64, err error)

func (*GsiClient) Nodes

func (c *GsiClient) Nodes() ([]*IndexerService, error)

Nodes implements BridgeAccessor{} interface.

func (*GsiClient) Range

func (c *GsiClient) Range(
	defnID uint64, requestId string, low, high common.SecondaryKey,
	inclusion Inclusion, distinct bool, limit int64,
	cons common.Consistency, vector *TsConsistency,
	callb ResponseHandler) (err error)

Range scan index between low and high.

func (*GsiClient) RangeStatistics

func (c *GsiClient) RangeStatistics(
	defnID uint64, requestId string, low, high common.SecondaryKey,
	inclusion Inclusion) (common.IndexStatistics, error)

RangeStatistics for index range.

func (*GsiClient) Refresh

func (c *GsiClient) Refresh() ([]*mclient.IndexMetadata, uint64, uint64, error)

Refresh implements BridgeAccessor{} interface.

func (*GsiClient) ScanAll

func (c *GsiClient) ScanAll(
	defnID uint64, requestId string, limit int64,
	cons common.Consistency, vector *TsConsistency,
	callb ResponseHandler) (err error)

ScanAll for full table scan.

func (*GsiClient) Settings

func (c *GsiClient) Settings() *ClientSettings

DescribeError return error description as human readable string.

func (*GsiClient) Sync

func (c *GsiClient) Sync() error

Sync implements BridgeAccessor{} interface.

type GsiScanClient

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

GsiScanClient for scan operations.

func NewGsiScanClient

func NewGsiScanClient(queryport string, config common.Config) (*GsiScanClient, error)

func (*GsiScanClient) Close

func (c *GsiScanClient) Close() error

func (*GsiScanClient) CountLookup

func (c *GsiScanClient) CountLookup(
	defnID uint64, requestId string, values []common.SecondaryKey,
	cons common.Consistency, vector *TsConsistency, rollbackTime int64) (int64, error)

CountLookup to count number entries for given set of keys.

func (*GsiScanClient) CountLookupPrimary

func (c *GsiScanClient) CountLookupPrimary(
	defnID uint64, requestId string, values [][]byte,
	cons common.Consistency, vector *TsConsistency, rollbackTime int64) (int64, error)

CountLookup to count number entries for given set of keys for primary index

func (*GsiScanClient) CountRange

func (c *GsiScanClient) CountRange(
	defnID uint64, requestId string, low, high common.SecondaryKey, inclusion Inclusion,
	cons common.Consistency, vector *TsConsistency, rollbackTime int64) (int64, error)

CountRange to count number entries in the given range.

func (*GsiScanClient) CountRangePrimary

func (c *GsiScanClient) CountRangePrimary(
	defnID uint64, requestId string, low, high []byte, inclusion Inclusion,
	cons common.Consistency, vector *TsConsistency, rollbackTime int64) (int64, error)

CountRange to count number entries in the given range for primary index

func (*GsiScanClient) Helo

func (c *GsiScanClient) Helo() (uint32, error)

func (*GsiScanClient) Lookup

func (c *GsiScanClient) Lookup(
	defnID uint64, requestId string, values []common.SecondaryKey,
	distinct bool, limit int64,
	cons common.Consistency, vector *TsConsistency,
	callb ResponseHandler,
	rollbackTime int64) (error, bool)

Lookup scan index between low and high.

func (*GsiScanClient) LookupStatistics

func (c *GsiScanClient) LookupStatistics(
	defnID uint64, value common.SecondaryKey) (common.IndexStatistics, error)

LookupStatistics for a single secondary-key.

func (*GsiScanClient) MultiScan

func (c *GsiScanClient) MultiScan(
	defnID uint64, requestId string, scans Scans,
	reverse, distinct bool, projection *IndexProjection, offset, limit int64,
	cons common.Consistency, vector *TsConsistency,
	callb ResponseHandler, rollbackTime int64) (error, bool)

func (*GsiScanClient) MultiScanCount

func (c *GsiScanClient) MultiScanCount(
	defnID uint64, requestId string, scans Scans, distinct bool,
	cons common.Consistency, vector *TsConsistency, rollbackTime int64) (int64, error)

func (*GsiScanClient) MultiScanCountPrimary

func (c *GsiScanClient) MultiScanCountPrimary(
	defnID uint64, requestId string, scans Scans, distinct bool,
	cons common.Consistency, vector *TsConsistency, rollbackTime int64) (int64, error)

func (*GsiScanClient) MultiScanPrimary

func (c *GsiScanClient) MultiScanPrimary(
	defnID uint64, requestId string, scans Scans,
	reverse, distinct bool, projection *IndexProjection, offset, limit int64,
	cons common.Consistency, vector *TsConsistency,
	callb ResponseHandler, rollbackTime int64) (error, bool)

func (*GsiScanClient) NeedSessionConsVector

func (c *GsiScanClient) NeedSessionConsVector() bool

func (*GsiScanClient) Range

func (c *GsiScanClient) Range(
	defnID uint64, requestId string, low, high common.SecondaryKey, inclusion Inclusion,
	distinct bool, limit int64, cons common.Consistency, vector *TsConsistency,
	callb ResponseHandler, rollbackTime int64) (error, bool)

Range scan index between low and high.

func (*GsiScanClient) RangePrimary

func (c *GsiScanClient) RangePrimary(
	defnID uint64, requestId string, low, high []byte, inclusion Inclusion,
	distinct bool, limit int64, cons common.Consistency, vector *TsConsistency,
	callb ResponseHandler, rollbackTime int64) (error, bool)

Range scan index between low and high.

func (*GsiScanClient) RangeStatistics

func (c *GsiScanClient) RangeStatistics(
	defnID uint64, low, high common.SecondaryKey,
	inclusion Inclusion) (common.IndexStatistics, error)

RangeStatistics for index range.

func (*GsiScanClient) RefreshServerVersion

func (c *GsiScanClient) RefreshServerVersion()

func (*GsiScanClient) ScanAll

func (c *GsiScanClient) ScanAll(
	defnID uint64, requestId string, limit int64,
	cons common.Consistency, vector *TsConsistency,
	callb ResponseHandler, rollbackTime int64) (error, bool)

ScanAll for full table scan.

type Inclusion

type Inclusion uint32

Inclusion specifier for range queries.

const (
	// Neither does not include low-key and high-key
	Neither Inclusion = iota
	// Low includes low-key but does not include high-key
	Low
	// High includes high-key but does not include low-key
	High
	// Both includes both low-key and high-key
	Both
)

type IndexIdList

type IndexIdList struct {
	DefnIds []uint64 `json:"defnIds,omitempty"`
}

type IndexProjection

type IndexProjection struct {
	EntryKeys  []int64
	PrimaryKey bool
}

type IndexRequest

type IndexRequest struct {
	Version  uint64                 `json:"version,omitempty"`
	Type     RequestType            `json:"type,omitempty"`
	Index    common.IndexDefn       `json:"index,omitempty"`
	IndexIds IndexIdList            `json:indexIds,omitempty"`
	Plan     map[string]interface{} `json:plan,omitempty"`
}

type IndexResponse

type IndexResponse struct {
	Version uint64 `json:"version,omitempty"`
	Code    string `json:"code,omitempty"`
	Error   string `json:"error,omitempty"`
}

type IndexerService

type IndexerService struct {
	Adminport string
	Queryport string
	Status    string // one of "initial", "online", "recovery"
}

IndexerService returns the status of the indexer node as observed by the GsiClient.

type Remoteaddr

type Remoteaddr string

Remoteaddr string in the shape of "<host:port>"

type RequestType

type RequestType string
const (
	CREATE RequestType = "create"
	DROP   RequestType = "drop"
	BUILD  RequestType = "build"
)

type ResponseHandler

type ResponseHandler func(resp ResponseReader) bool

ResponseHandler shall interpret response packets from server and handle them. If handler is not interested in receiving any more response it shall return false, else it shall continue until *protobufEncode.StreamEndResponse message is received.

type ResponseReader

type ResponseReader interface {
	// GetEntries returns a list of secondary-key and corresponding
	// primary-key if returned value is nil, then there are no more
	// entries for this query.
	GetEntries() ([]common.SecondaryKey, [][]byte, error)

	// Error returns the error value, if nil there is no error.
	Error() error
}

ResponseReader to obtain the actual data returned from server, handlers, should first call Error() and then call GetEntries().

type Scan

type Scan struct {
	Seek   common.SecondaryKey
	Filter []*CompositeElementFilter
}

type Scans

type Scans []*Scan

type TsConsistency

type TsConsistency struct {
	Vbnos   []uint16
	Seqnos  []uint64
	Vbuuids []uint64
	Crc64   uint64
}

TsConsistency specifies a subset of vbuckets to be used as timestamp vector to specify consistency criteria.

Timestamp-vector will be ignored for AnyConsistency, computed locally by scan-coordinator or accepted as scan-arguments for SessionConsistency.

func NewTsConsistency

func NewTsConsistency(
	vbnos []uint16, seqnos []uint64, vbuuids []uint64) *TsConsistency

NewTsConsistency returns a new consistency vector object.

func (*TsConsistency) Override

func (ts *TsConsistency) Override(
	vbno uint16, seqno, vbuuid uint64) *TsConsistency

Override vbucket's {seqno, vbuuid} in the timestamp-vector, if vbucket is not present in the vector, append them to vector.

Jump to

Keyboard shortcuts

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