util

package
v0.0.0-...-8836d2b Latest Latest
Warning

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

Go to latest
Published: Sep 27, 2018 License: Apache-2.0 Imports: 39 Imported by: 0

Documentation

Index

Constants

View Source
const (
	EVENTING_ADMIN_SERVICE = "eventingAdminPort"
	EVENTING_SSL_SERVICE   = "eventingSSL"
)
View Source
const (
	Stop time.Duration = -1

	DefaultInitialInterval     = 1 * time.Second
	DefaultRandomizationFactor = 0.5
	DefaultMultiplier          = 1.5
	DefaultMaxInterval         = 10 * time.Second
	DefaultMaxElapsedTime      = time.Minute
)
View Source
const (
	EventingAdminService = "eventingAdminPort"
	DataService          = "kv"
	MgmtService          = "mgmt"

	HTTPRequestTimeout = time.Duration(5000) * time.Millisecond

	EPSILON = 1e-5
)
View Source
const BUCKET_UUID_NIL = ""
View Source
const CLUSTER_INFO_INIT_RETRIES = 5
View Source
const CLUSTER_INFO_VALIDATION_RETRIES = 10
View Source
const (
	MAX_AUTH_RETRIES = 10
)

Variables

View Source
var (
	ErrInvalidNodeId       = errors.New("Invalid NodeId")
	ErrInvalidService      = errors.New("Invalid service")
	ErrNodeNotBucketMember = errors.New("Node is not a member of bucket")
	ErrValidationFailed    = errors.New("ClusterInfo Validation Failed")
)
View Source
var DefaultClient = &Client{}
View Source
var ErrorClosed = errors.New("bounded_queue is closed")
View Source
var ErrorSize = errors.New("element size is more than max memory quota")
View Source
var GocbCredsRequestCounter = 0
View Source
var ServiceAddrMap map[string]string
View Source
var SystemClock = systemClock{}

Functions

func Assert

func Assert(stmt func() bool)

func BucketSeqnos

func BucketSeqnos(cluster, pooln, bucketn string) (l_seqnos []uint64, err error)

BucketSeqnos return list of {{vbno,seqno}..} for all vbuckets. this call might fail due to,

  • concurrent access that can preserve a deleted/failed bucket object.
  • pollForDeletedBuckets() did not get a chance to cleanup a deleted bucket.

in both the cases if the call is retried it should get fixed, provided a valid bucket exists.

func CPUCount

func CPUCount(log bool) int

func CheckIfRebalanceOngoing

func CheckIfRebalanceOngoing(urlSuffix string, nodeAddrs []string) (bool, error)

func ClusterAuthUrl

func ClusterAuthUrl(cluster string) (string, error)

func CollectSeqnos

func CollectSeqnos(kvfeeds map[string]*kvConn) (l_seqnos []uint64, err error)

func CompareSlices

func CompareSlices(s1, s2 []uint16) bool

func ComputeMD5

func ComputeMD5(data []byte) ([]byte, error)

func Condense

func Condense(vbs []uint16) string

func ConnectBucket

func ConnectBucket(cluster, pooln, bucketn string) (*couchbase.Bucket, error)

ConnectBucket will instantiate a couchbase-bucket instance with cluster. caller's responsibility to close the bucket.

func Console

func Console(clusterAddr string, format string, v ...interface{}) error

Write to the admin console

func Contains

func Contains(needle interface{}, haystack interface{}) bool

func ContainsIgnoreCase

func ContainsIgnoreCase(needle string, haystack []string) bool

func ConvertBigEndianToUint64

func ConvertBigEndianToUint64(cas []byte) (uint64, error)

func CountActiveKVNodes

func CountActiveKVNodes(bucket, hostaddress string) int

func CurrentEventingNodeAddress

func CurrentEventingNodeAddress(auth, hostaddress string) (string, error)

func DeepCopy

func DeepCopy(kv map[string]interface{}) (newKv map[string]interface{})

func DeleteAppContent

func DeleteAppContent(appPath, checksumPath, appName string) error

DeleteAppContent delete handler code

func DeleteStaleAppContent

func DeleteStaleAppContent(appPath, appName string) error

Delete stale app fragments

func Do

func Do(req *http.Request) (*http.Response, error)

func EventingNodesAddresses

func EventingNodesAddresses(auth, hostaddress string) ([]string, error)

func EventingVer

func EventingVer() string

func FloatEquals

func FloatEquals(a, b float64) bool

func GenerateHandlerUUID

func GenerateHandlerUUID() (uint32, error)

func Get

func Get(url string) (resp *http.Response, err error)

func GetAggBootstrappingApps

func GetAggBootstrappingApps(urlSuffix string, nodeAddrs []string) (bool, error)

func GetAppNameFromPath

func GetAppNameFromPath(path string) string

func GetDeployedApps

func GetDeployedApps(urlSuffix string, nodeAddrs []string) (map[string]map[string]string, error)

func GetEventProcessingStats

func GetEventProcessingStats(urlSuffix string, nodeAddrs []string) (map[string]int64, error)

func GetHash

func GetHash(appCode string) string

func GetIPMode

func GetIPMode() string

func GetLogLevel

func GetLogLevel(logLevel string) logging.LogLevel

func GetMaxVbuckets

func GetMaxVbuckets() int

func GetNodeUUIDs

func GetNodeUUIDs(urlSuffix string, nodeAddrs []string) (map[string]string, error)

func GetProgress

func GetProgress(urlSuffix string, nodeAddrs []string) (*cm.RebalanceProgress, map[string]interface{}, map[string]error)
func Head(url string) (resp *http.Response, err error)

func IsIPv6

func IsIPv6() bool

func KVNodesAddresses

func KVNodesAddresses(auth, hostaddress, bucket string) ([]string, error)

func KVVbMap

func KVVbMap(auth, bucket, hostaddress string) (map[uint16]string, error)

func KillProcess

func KillProcess(pid int) error

func ListChildren

func ListChildren(path string) []string

func LocalEventingServiceHost

func LocalEventingServiceHost(auth, hostaddress string) (string, error)

func LocalKey

func LocalKey() (usr, key string)

func Localhost

func Localhost() string

func MemcachedErrCode

func MemcachedErrCode(err error) gomemcached.Status

func MetaKvDelete

func MetaKvDelete(path string, rev interface{}) error

func MetakvGet

func MetakvGet(path string) ([]byte, error)

func MetakvRecursiveDelete

func MetakvRecursiveDelete(dirpath string) error

func MetakvSet

func MetakvSet(path string, value []byte, rev interface{}) error

func NewRequest

func NewRequest(method, url string, body io.Reader) (*http.Request, error)

func NsServerNodesAddresses

func NsServerNodesAddresses(auth, hostaddress string) ([]string, error)

func Post

func Post(url string, contentType string, body io.Reader) (resp *http.Response, err error)

func PostForm

func PostForm(url string, data url.Values) (resp *http.Response, err error)

func ReadAppContent

func ReadAppContent(appsPath, checksumPath, appName string) ([]byte, error)

ReadAppContent reads Handler Code

func RecursiveDelete

func RecursiveDelete(dirpath string) error

func Retry

func Retry(b Backoff, retryCount *int64, callback CallbackFunc, args ...interface{}) error

func SeedProcess

func SeedProcess()

func SetIPv6

func SetIPv6(is6 bool)

func SetMaxVbuckets

func SetMaxVbuckets(sz int)

func SetServicePorts

func SetServicePorts(portMap map[string]string)

func SprintDCPCounts

func SprintDCPCounts(counts map[mcd.CommandCode]uint64) (string, uint64, time.Time)

func SprintV8Counts

func SprintV8Counts(counts map[string]uint64) string

func StopDebugger

func StopDebugger(nodeAddr, appName string)

func StrSliceDiff

func StrSliceDiff(kv1, kv2 []string) []string

func StripScheme

func StripScheme(endpoint string) string

func SuperImpose

func SuperImpose(source, on map[string]interface{}) map[string]interface{}

func ToStr

func ToStr(value bool) (strValue string)

func ToStringArray

func ToStringArray(from interface{}) (to []string)

func Uint16SliceDiff

func Uint16SliceDiff(kv1, kv2 []uint16) []uint16

func VbsSliceDiff

func VbsSliceDiff(X, Y []uint16) []uint16

func VbucketByKey

func VbucketByKey(key []byte, numVbuckets int) uint16

VbucketByKey returns doc_id to vbucket mapping

func VbucketDistribution

func VbucketDistribution(vbs []uint16, numWorkers int) map[int][]uint16

VbucketDistribution is used by vbucket ownership give up and takeover routines during rebalance

func VbucketNodeAssignment

func VbucketNodeAssignment(vbs []uint16, numWorkers int) map[int][]uint16

VbucketNodeAssignment will be used as generic partitioning scheme for vbucket assignment to Eventing.Consumer and Eventing.Producer instances

func WriteAppContent

func WriteAppContent(appsPath, checksumPath, appName string, payload []byte) error

WriteAppContent fragments the payload and store it to metakv

Types

type Backoff

type Backoff interface {
	NextBackoff() time.Duration
	Reset()
}

type BoundedQueue

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

func NewBoundedQueue

func NewBoundedQueue(maxcount, maxsize uint64) *BoundedQueue

func (*BoundedQueue) Close

func (q *BoundedQueue) Close()

func (*BoundedQueue) Count

func (q *BoundedQueue) Count() uint64

func (*BoundedQueue) IsClosed

func (q *BoundedQueue) IsClosed() bool

func (*BoundedQueue) Pop

func (q *BoundedQueue) Pop() (Element, error)

func (*BoundedQueue) Push

func (q *BoundedQueue) Push(elem Element) error

type CallbackFunc

type CallbackFunc func(arg ...interface{}) error

type CbAuthHandler

type CbAuthHandler struct {
	Hostport string
	Bucket   string
}

cbauth admin authentication helper Uses default cbauth env variables internally to provide auth creds

func (*CbAuthHandler) AuthenticateMemcachedConn

func (ah *CbAuthHandler) AuthenticateMemcachedConn(host string, conn *memcached.Client) error

func (*CbAuthHandler) GetCredentials

func (ah *CbAuthHandler) GetCredentials() (string, string)

type Client

type Client struct {
	http.Client
}

func NewClient

func NewClient(timeout time.Duration) *Client

func (*Client) Do

func (c *Client) Do(req *http.Request) (*http.Response, error)

func (*Client) Get

func (c *Client) Get(url string) (resp *http.Response, err error)

func (*Client) Head

func (c *Client) Head(url string) (resp *http.Response, err error)

func (*Client) Post

func (c *Client) Post(url string, contentType string, body io.Reader) (resp *http.Response, err error)

func (*Client) PostForm

func (c *Client) PostForm(url string, data url.Values) (resp *http.Response, err error)

type Clock

type Clock interface {
	Now() time.Time
}

type ClusterInfoCache

type ClusterInfoCache struct {
	sync.Mutex
	// contains filtered or unexported fields
}

Helper object for fetching cluster information Can be used by services running on a cluster node to connect with local management service for obtaining cluster information. Info cache can be updated by using Refresh() method.

func FetchNewClusterInfoCache

func FetchNewClusterInfoCache(clusterUrl string) (*ClusterInfoCache, error)

func (*ClusterInfoCache) Fetch

func (c *ClusterInfoCache) Fetch() error

func (*ClusterInfoCache) GetActiveEventingNodes

func (c *ClusterInfoCache) GetActiveEventingNodes() (nodes []couchbase.Node)

func (*ClusterInfoCache) GetBucketUUID

func (c *ClusterInfoCache) GetBucketUUID(bucket string) (uuid string)

Return UUID of a given bucket.

func (*ClusterInfoCache) GetClusterVersion

func (c *ClusterInfoCache) GetClusterVersion() (int, int)

func (*ClusterInfoCache) GetCurrentNode

func (c *ClusterInfoCache) GetCurrentNode() NodeId

func (*ClusterInfoCache) GetFailedEventingNodes

func (c *ClusterInfoCache) GetFailedEventingNodes() (nodes []couchbase.Node)

func (*ClusterInfoCache) GetLocalHostAddress

func (c *ClusterInfoCache) GetLocalHostAddress() (string, error)

func (*ClusterInfoCache) GetLocalHostname

func (c *ClusterInfoCache) GetLocalHostname() (string, error)

func (*ClusterInfoCache) GetLocalServerGroup

func (c *ClusterInfoCache) GetLocalServerGroup() (string, error)

func (*ClusterInfoCache) GetLocalServiceAddress

func (c *ClusterInfoCache) GetLocalServiceAddress(srvc string) (string, error)

func (*ClusterInfoCache) GetLocalServiceHost

func (c *ClusterInfoCache) GetLocalServiceHost(srvc string) (string, error)

func (*ClusterInfoCache) GetLocalServicePort

func (c *ClusterInfoCache) GetLocalServicePort(srvc string) (string, error)

func (*ClusterInfoCache) GetNewEventingNodes

func (c *ClusterInfoCache) GetNewEventingNodes() (nodes []couchbase.Node)

func (*ClusterInfoCache) GetNodeStatus

func (c *ClusterInfoCache) GetNodeStatus(nid NodeId) (string, error)

func (*ClusterInfoCache) GetNodesByBucket

func (c *ClusterInfoCache) GetNodesByBucket(bucket string) (nids []NodeId, err error)

func (*ClusterInfoCache) GetNodesByServiceType

func (c *ClusterInfoCache) GetNodesByServiceType(srvc string) (nids []NodeId)

func (*ClusterInfoCache) GetServerGroup

func (c *ClusterInfoCache) GetServerGroup(nid NodeId) string

func (*ClusterInfoCache) GetServiceAddress

func (c *ClusterInfoCache) GetServiceAddress(nid NodeId, srvc string) (addr string, err error)

func (*ClusterInfoCache) GetVBuckets

func (c *ClusterInfoCache) GetVBuckets(nid NodeId, bucket string) (vbs []uint32, err error)

func (*ClusterInfoCache) IsEphemeral

func (c *ClusterInfoCache) IsEphemeral(bucket string) (bool, error)

func (*ClusterInfoCache) IsMemcached

func (c *ClusterInfoCache) IsMemcached(bucket string) (bool, error)

func (*ClusterInfoCache) IsNodeHealthy

func (c *ClusterInfoCache) IsNodeHealthy(nid NodeId) (bool, error)

func (*ClusterInfoCache) SetLogPrefix

func (c *ClusterInfoCache) SetLogPrefix(p string)

func (*ClusterInfoCache) SetMaxRetries

func (c *ClusterInfoCache) SetMaxRetries(r int)

func (*ClusterInfoCache) SetServicePorts

func (c *ClusterInfoCache) SetServicePorts(portMap map[string]string)

type Config

type Config map[string]interface{}

func NewConfig

func NewConfig(data interface{}) (Config, error)

func (Config) Set

func (config Config) Set(key string, value interface{}) Config

func (Config) Update

func (config Config) Update(data interface{}) error

type ConfigHolder

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

func (*ConfigHolder) Load

func (h *ConfigHolder) Load() Config

func (*ConfigHolder) Store

func (h *ConfigHolder) Store(conf Config)

type DynamicAuthenticator

type DynamicAuthenticator struct {
	Caller string
}

func (*DynamicAuthenticator) Credentials

func (dynAuth *DynamicAuthenticator) Credentials(req gocb.AuthCredsRequest) ([]gocb.UserPassPair, error)

type Element

type Element interface {
	Size() uint64
}

type ExponentialBackoff

type ExponentialBackoff struct {
	InitialInterval     time.Duration
	RandomizationFactor float64
	Multiplier          float64
	MaxInterval         time.Duration

	// After MaxElapsedTime the ExponentialBackoff stops.
	// It never stops if MaxElapsedTime == 0.
	MaxElapsedTime time.Duration
	Clock          Clock
	// contains filtered or unexported fields
}

func NewExponentialBackoff

func NewExponentialBackoff() *ExponentialBackoff

func (*ExponentialBackoff) GetElapsedTime

func (b *ExponentialBackoff) GetElapsedTime() time.Duration

func (*ExponentialBackoff) NextBackoff

func (b *ExponentialBackoff) NextBackoff() time.Duration

func (*ExponentialBackoff) Reset

func (b *ExponentialBackoff) Reset()

type FixedBackoff

type FixedBackoff struct {
	Interval time.Duration
}

func NewFixedBackoff

func NewFixedBackoff(d time.Duration) *FixedBackoff

func (*FixedBackoff) NextBackoff

func (b *FixedBackoff) NextBackoff() time.Duration

func (*FixedBackoff) Reset

func (b *FixedBackoff) Reset()

type GocbLogger

type GocbLogger struct{}

func (*GocbLogger) Log

func (r *GocbLogger) Log(level gocb.LogLevel, offset int, format string, v ...interface{}) error

type NamedParamsInfo

type NamedParamsInfo struct {
	PInfo       ParseInfo `json:"p_info"`
	NamedParams []string  `json:"named_params"`
}

func GetNamedParams

func GetNamedParams(query string) (info *NamedParamsInfo)

type NodeId

type NodeId int

type ParseInfo

type ParseInfo struct {
	IsValid       bool   `json:"is_valid"`
	IsSelectQuery bool   `json:"is_select_query"`
	IsDmlQuery    bool   `json:"is_dml_query"`
	KeyspaceName  string `json:"keyspace_name"`
	Info          string `json:"info"`
}

func Parse

func Parse(query string) (info *ParseInfo, alg algebra.Statement)

func (*ParseInfo) FlattenParseInfo

func (parseInfo *ParseInfo) FlattenParseInfo(urlValues *url.Values)

type PayloadHash

type PayloadHash struct {
	Fragmentcnt  int      `json:"fragment_count"`
	Fragmenthash [][]byte `json:"fragment_hash"`
}

func (*PayloadHash) Update

func (payloadhash *PayloadHash) Update(payload []byte, fragmentSize int) error

type RetryHelper

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

Helper object to execute a function with retries and exponential backoff

func NewRetryHelper

func NewRetryHelper(
	maxRetries int,
	interval time.Duration,
	factor int,
	call retryFunc) *RetryHelper

func (*RetryHelper) Run

func (r *RetryHelper) Run() error

type UUID

type UUID []byte

func NewUUID

func NewUUID() (UUID, error)

func (UUID) Str

func (u UUID) Str() string

func (UUID) Uint64

func (u UUID) Uint64() uint64

type Uint16Slice

type Uint16Slice []uint16

func (Uint16Slice) Len

func (s Uint16Slice) Len() int

func (Uint16Slice) Less

func (s Uint16Slice) Less(i, j int) bool

func (Uint16Slice) Swap

func (s Uint16Slice) Swap(i, j int)

Jump to

Keyboard shortcuts

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