Documentation ¶
Overview ¶
Package couchbase provides a smart client for go.
Usage:
client, err := couchbase.Connect("http://myserver:8091/") handleError(err) pool, err := client.GetPool("default") handleError(err) bucket, err := pool.GetBucket("MyAwesomeBucket") handleError(err) ...
or a shortcut for the bucket directly
bucket, err := couchbase.GetBucket("http://myserver:8091/", "default", "default")
in any case, you can specify authentication credentials using standard URL userinfo syntax:
b, err := couchbase.GetBucket("http://bucketname:bucketpass@myserver:8091/", "default", "bucket")
Index ¶
- Constants
- Variables
- func AlreadyExistsError(err error) bool
- func CleanupHost(h, commonSuffix string) string
- func ClientConfigForX509(certFile, keyFile, rootFile string) (*tls.Config, error)
- func DisableOverflowConnections()
- func DropSystemBucket(c *Client, name string) error
- func EnableAsynchronousCloser(closer bool)
- func FindCommonSuffix(input []string) string
- func InitBulkGet()
- func IsKeyEExistsError(err error) bool
- func IsKeyNoEntError(err error) bool
- func IsReadTimeOutError(err error) bool
- func IsRefreshRequired(err error) bool
- func IsUnknownCollection(err error) bool
- func MapKVtoSSL(hostport string, ps *PoolServices) (string, bool, error)
- func MapKVtoSSLExt(hostport string, ps *PoolServices, force bool) (string, bool, error)
- func ParseURL(urlStr string) (result *url.URL, err error)
- func SetCertFile(cert string)
- func SetConnectionPoolParams(size, overflow int)
- func SetKeyFile(cert string)
- func SetRootFile(cert string)
- func SetSkipVerify(skip bool)
- func SetTcpKeepalive(enabled bool, interval int)
- func SetViewUpdateParams(baseU string, params map[string]interface{}) (viewOpts map[string]interface{}, err error)
- type AuditSpec
- type AuditUser
- type AuthHandler
- type AuthWithSaslHandler
- type Bucket
- func (b *Bucket) Add(k string, exp int, v interface{}, context ...*memcached.ClientContext) (added bool, err error)
- func (b *Bucket) AddRaw(k string, exp int, v []byte, context ...*memcached.ClientContext) (added bool, err error)
- func (b *Bucket) AddRawWithMT(k string, exp int, v []byte, context ...*memcached.ClientContext) (added bool, mt *MutationToken, err error)
- func (b *Bucket) AddWithMT(k string, exp int, v interface{}, context ...*memcached.ClientContext) (added bool, mt *MutationToken, err error)
- func (b *Bucket) Append(k string, data []byte, context ...*memcached.ClientContext) error
- func (b *Bucket) Cas(k string, exp int, cas uint64, v interface{}, ...) (uint64, error)
- func (b *Bucket) CasRaw(k string, exp int, cas uint64, v interface{}, ...) (uint64, error)
- func (b *Bucket) CasWithMeta(k string, flags int, exp int, cas uint64, v interface{}, ...) (uint64, *MutationToken, error)
- func (b *Bucket) CasWithMetaRaw(k string, flags int, exp int, cas uint64, v interface{}, ...) (uint64, *MutationToken, error)
- func (b *Bucket) Close()
- func (b *Bucket) CommonAddressSuffix() string
- func (b *Bucket) CreateCollection(scope string, collection string) error
- func (b *Bucket) CreateScope(scope string) error
- func (b *Bucket) Decr(k string, amt, def uint64, exp int, context ...*memcached.ClientContext) (val uint64, err error)
- func (b *Bucket) Delete(k string, context ...*memcached.ClientContext) error
- func (b *Bucket) DeleteDDoc(docname string) error
- func (b *Bucket) Do(k string, f func(mc *memcached.Client, vb uint16) error) (err error)
- func (b *Bucket) Do2(k string, f func(mc *memcached.Client, vb uint16) error, deadline bool) (err error)
- func (b *Bucket) DropCollection(scope string, collection string) error
- func (b *Bucket) DropScope(scope string) error
- func (b *Bucket) FlushCollection(scope string, collection string) error
- func (b *Bucket) GatherStats(which string) map[string]GatheredStats
- func (b *Bucket) Get(k string, rv interface{}, context ...*memcached.ClientContext) error
- func (b *Bucket) GetAndTouchRaw(k string, exp int, context ...*memcached.ClientContext) (data []byte, cas uint64, err error)
- func (b *Bucket) GetBulk(keys []string, reqDeadline time.Time, subPaths []string, ...) (map[string]*gomemcached.MCResponse, error)
- func (b *Bucket) GetBulkRaw(keys []string, context ...*memcached.ClientContext) (map[string][]byte, error)
- func (b *Bucket) GetCollectionCID(scope string, collection string, reqDeadline time.Time) (uint32, uint32, error)
- func (b *Bucket) GetCollectionsManifest() (*Manifest, error)
- func (b *Bucket) GetCount(refresh bool, context ...*memcached.ClientContext) (count int64, err error)
- func (b *Bucket) GetDDoc(docname string, into interface{}) error
- func (b *Bucket) GetDDocWithRetry(docname string, into interface{}) error
- func (b *Bucket) GetDDocs() (DDocsResult, error)
- func (b *Bucket) GetDDocsWithRetry() (DDocsResult, error)
- func (b *Bucket) GetFailoverLogs(vBuckets []uint16) (FailoverLog, error)
- func (b *Bucket) GetMeta(k string, flags *int, expiry *int, cas *uint64, seqNo *uint64, ...) (err error)
- func (b *Bucket) GetName() string
- func (b *Bucket) GetNodeList(vb uint16) []string
- func (b *Bucket) GetPool() *Pool
- func (b *Bucket) GetPoolServices(name string) (*PoolServices, error)
- func (b *Bucket) GetRandomDoc(context ...*memcached.ClientContext) (*gomemcached.MCResponse, error)
- func (b *Bucket) GetRaw(k string, context ...*memcached.ClientContext) ([]byte, error)
- func (b *Bucket) GetSize(refresh bool, context ...*memcached.ClientContext) (size int64, err error)
- func (b *Bucket) GetStats(which string) map[string]map[string]string
- func (b *Bucket) GetUUID() string
- func (b *Bucket) GetVBmap(addrs []string) (map[string][]uint16, error)
- func (b *Bucket) Gets(k string, rv interface{}, caso *uint64, context ...*memcached.ClientContext) error
- func (b *Bucket) GetsMC(key string, reqDeadline time.Time, context ...*memcached.ClientContext) (*gomemcached.MCResponse, error)
- func (b *Bucket) GetsRaw(k string, context ...*memcached.ClientContext) (data []byte, flags int, cas uint64, err error)
- func (b *Bucket) GetsSubDoc(key string, reqDeadline time.Time, subPaths []string, ...) (*gomemcached.MCResponse, error)
- func (b *Bucket) HealthyNodes() []Node
- func (b *Bucket) Incr(k string, amt, def uint64, exp int, context ...*memcached.ClientContext) (val uint64, err error)
- func (b *Bucket) NodeAddresses() []string
- func (b *Bucket) NodeListChanged() bool
- func (b *Bucket) Nodes() []Node
- func (b *Bucket) OPJobPoll()
- func (b *Bucket) Observe(k string) (result memcached.ObserveResult, err error)
- func (b *Bucket) ObserveAndPersistPoll(vb uint16, vbuuid uint64, seqNo uint64) (err error, failover bool)
- func (b *Bucket) PutDDoc(docname string, value interface{}) error
- func (b *Bucket) Refresh() error
- func (b *Bucket) RefreshFully() error
- func (b *Bucket) ReleaseGetBulkPools(rv map[string]*gomemcached.MCResponse)
- func (b *Bucket) RunBucketUpdater(notify NotifyFn)
- func (b *Bucket) RunBucketUpdater2(streamingFn StreamingFn, notify NotifyFn)
- func (b *Bucket) Set(k string, exp int, v interface{}, context ...*memcached.ClientContext) error
- func (b *Bucket) SetObserveAndPersist(nPersist PersistTo, nObserve ObserveTo) (err error)
- func (b *Bucket) SetRaw(k string, exp int, v []byte, context ...*memcached.ClientContext) error
- func (b *Bucket) SetWithMeta(k string, flags int, exp int, v interface{}, ...) (*MutationToken, error)
- func (b *Bucket) StartOPPollers(maxWorkers int)
- func (b *Bucket) StartTapFeed(args *memcached.TapArguments) (*TapFeed, error)
- func (b *Bucket) StartUprFeed(name string, sequence uint32) (*UprFeed, error)
- func (b *Bucket) StartUprFeedWithConfig(name string, sequence uint32, data_chan_size int, dcp_buffer_size uint32) (*UprFeed, error)
- func (b *Bucket) Update(k string, exp int, callback UpdateFunc) error
- func (b *Bucket) UpdateBucket() error
- func (b *Bucket) UpdateBucket2(streamingFn StreamingFn) error
- func (b *Bucket) VBHash(key string) uint32
- func (b *Bucket) VBServerMap() *VBucketServerMap
- func (b *Bucket) View(ddoc, name string, params map[string]interface{}) (ViewResult, error)
- func (b *Bucket) ViewCustom(ddoc, name string, params map[string]interface{}, vres interface{}) (err error)
- func (b *Bucket) ViewURL(ddoc, name string, params map[string]interface{}) (string, error)
- func (b *Bucket) WaitForPersistence(k string, cas uint64, deletion bool) error
- func (b *Bucket) Write(k string, flags, exp int, v interface{}, opt WriteOptions, ...) (err error)
- func (b *Bucket) WriteCas(k string, flags, exp int, cas uint64, v interface{}, opt WriteOptions, ...) (newCas uint64, err error)
- func (b *Bucket) WriteCasWithMT(k string, flags, exp int, cas uint64, v interface{}, opt WriteOptions, ...) (newCas uint64, mt *MutationToken, err error)
- func (b *Bucket) WriteUpdate(k string, exp int, callback WriteUpdateFunc) error
- func (b *Bucket) WriteWithMT(k string, flags, exp int, v interface{}, opt WriteOptions, ...) (mt *MutationToken, err error)
- type BucketAuth
- type BucketInfo
- type BucketNotFoundError
- type Client
- func (c *Client) ClearTLS()
- func (c *Client) GetAuditSpec() (*AuditSpec, error)
- func (c *Client) GetPool(name string) (p Pool, err error)
- func (c *Client) GetPoolServices(name string) (ps PoolServices, err error)
- func (c *Client) GetRolesAll() ([]RoleDescription, error)
- func (c *Client) GetUserInfoAll() ([]User, error)
- func (c *Client) GetUserRoles() ([]interface{}, error)
- func (c *Client) InitTLS(certFile string) error
- func (c *Client) ProcessStream(path string, callb func(interface{}) error, data interface{}) error
- func (c *Client) PutUserInfo(u *User) error
- type Collection
- type DDoc
- type DDocsResult
- type DocID
- type DurablitySettings
- type FailoverLog
- type FeedInfo
- type GatheredStats
- type GenericMcdAuthHandler
- type HTTPAuthHandler
- type InputCollection
- type InputManifest
- type InputScope
- type JobType
- type Manifest
- type MultiBucketAuthHandler
- type MutationToken
- type Node
- type NodeAlternateNames
- type NodeServices
- type NotifyFn
- type OPErrResponse
- type OPpool
- type ObservePersistJob
- type ObserveTo
- type PersistTo
- type Pool
- type PoolServices
- type Pools
- type RestPool
- type Role
- type RoleDescription
- type Scope
- type StreamingFn
- type TapFeed
- type UpdateFunc
- type UprFeed
- type User
- type VBucketServerMap
- type ViewDefinition
- type ViewError
- type ViewResult
- type ViewRow
- type WriteOptions
- type WriteUpdateFunc
Constants ¶
const ( // Raw specifies that the value is raw []byte or nil; don't // JSON-encode it. Raw = WriteOptions(1 << iota) // AddOnly indicates an item should only be written if it // doesn't exist, otherwise ErrKeyExists is returned. AddOnly // Persist causes the operation to block until the server // confirms the item is persisted. Persist // Indexable causes the operation to block until it's availble via the index. Indexable // Append indicates the given value should be appended to the // existing value for the given key. Append )
const ( PersistNone = PersistTo(0x00) PersistMaster = PersistTo(0x01) PersistOne = PersistTo(0x02) PersistTwo = PersistTo(0x03) PersistThree = PersistTo(0x04) PersistFour = PersistTo(0x05) )
const ( ObserveNone = ObserveTo(0x00) ObserveReplicateOne = ObserveTo(0x01) ObserveReplicateTwo = ObserveTo(0x02) ObserveReplicateThree = ObserveTo(0x03) ObserveReplicateFour = ObserveTo(0x04) )
const ( OBSERVE = JobType(0x00) PERSIST = JobType(0x01) )
const ABS_MAX_RETRIES = 10
const ABS_MIN_RETRIES = 3
const DEFAULT_WINDOW_SIZE = 20 * 1024 * 1024 // 20 Mb
const DISCONNECT_PERIOD = 120 * time.Second
const HTTP_MAX_RETRY = 5
arbitary number, may need to be tuned #FIXME
const MAX_RETRY_COUNT = 5
const START_NODE_ID = -1
const UpdateCancel = memcached.CASQuit
Return this as the error from an UpdateFunc to cancel the Update operation.
Variables ¶
var AsynchronousCloser = false
AsynchronousCloser turns on asynchronous closing for overflow connections
var ClientOpCallback func(opname, k string, start time.Time, err error)
ClientOpCallback is called for each invocation of Do.
var ClientTimeOut = 10 * time.Second
var ConnCloserInterval = time.Second * 30
overflow connection closer cycle time
var ConnPoolAvailWaitTime = time.Millisecond
ConnPoolAvailWaitTime is the amount of time to wait for an existing connection from the pool before considering the creation of a new one.
ConnPoolTimeout is notified whenever connections are acquired from a pool.
var ConnPoolTimeout = time.Hour * 24 * 30
Default timeout for retrieving a connection from the pool.
var DefaultDialTimeout = time.Duration(0)
var DefaultTimeout = time.Duration(0)
var EnableCollections = false
Enable Collections
var EnableDataType = false
Enable Data Type response
var EnableMutationToken = false
Enable MutationToken
var EnableXattr = false
Enable Xattr
var ErrKeyExists = errors.New("key exists")
Error returned from Write with AddOnly flag, when key already exists in the bucket.
var ErrOverwritten = errors.New("overwritten")
Returned from WaitForPersistence (or Write, if the Persistent or Indexable flag is used) if the value has been overwritten by another before being persisted.
var ErrTimeout = errors.New("timeout")
Returned from WaitForPersistence (or Write, if the Persistent or Indexable flag is used) if the value hasn't been persisted by the timeout interval
var HTTPClient = &http.Client{Transport: HTTPTransport, Timeout: ClientTimeOut}
var HTTPClientForStreaming = &http.Client{Transport: HTTPTransport, Timeout: 0}
Use this client for reading from streams that should be open for an extended duration.
var HTTPTransport = &http.Transport{MaxIdleConnsPerHost: MaxIdleConnsPerHost}
var MaxBackOffRetries = 25 // exponentail backOff result in over 30sec (25*13*0.1s)
var MaxBulkRetries = 5000
Maximum number of times to retry a chunk of a bulk get on error.
var MaxIdleConnsPerHost = 256
HTTPClient to use for REST and view operations.
var OPJobChan = make(chan *ObservePersistJob, 1024)
var OPJobDone = make(chan bool)
var ObservePersistPool = NewPool(1024)
var PoolOverflow = 16
PoolOverflow is the number of overflow connections allowed in a pool.
var PoolSize = 64
PoolSize is the size of each connection pool (per host).
var SlowServerCallWarningThreshold time.Duration
If this is set to a nonzero duration, Do() and ViewCustom() will log a warning if the call takes longer than that.
var TCPKeepalive = false
TCP KeepAlive enabled/disabled
var TCPKeepaliveInterval = 30 * 60
TCP keepalive interval in seconds. Default 30 minutes
var TimeoutError = errors.New("timeout waiting to build connection")
Error raised when a connection can't be retrieved from a pool.
var ViewCallback func(ddoc, name string, start time.Time, err error)
ViewCallback is called for each view invocation.
Functions ¶
func AlreadyExistsError ¶
func CleanupHost ¶
CleanupHost returns the hostname with the given suffix removed.
func ClientConfigForX509 ¶
func DropSystemBucket ¶
func EnableAsynchronousCloser ¶
func EnableAsynchronousCloser(closer bool)
Toggle asynchronous overflow closer
func FindCommonSuffix ¶
FindCommonSuffix returns the longest common suffix from the given strings.
func InitBulkGet ¶
func InitBulkGet()
func IsKeyEExistsError ¶
Return true if error is KEY_ENOENT. Required by cbq-engine
func IsKeyNoEntError ¶
Return true if error is KEY_ENOENT. Required by cbq-engine
func IsReadTimeOutError ¶
func IsRefreshRequired ¶
Return true if error suggests a bucket refresh is required. Required by cbq-engine
func IsUnknownCollection ¶
Return true if a collection is not known. Required by cbq-engine
func MapKVtoSSL ¶
func MapKVtoSSL(hostport string, ps *PoolServices) (string, bool, error)
Accepts a "host:port" string representing the KV TCP port and the pools nodeServices payload and returns a host:port string representing the KV TLS port on the same node as the KV TCP port. Returns the original host:port if in case of local communication (services on the same node as source)
func MapKVtoSSLExt ¶
func SetCertFile ¶
func SetCertFile(cert string)
func SetConnectionPoolParams ¶
func SetConnectionPoolParams(size, overflow int)
Allow applications to speciify the Poolsize and Overflow
func SetKeyFile ¶
func SetKeyFile(cert string)
func SetRootFile ¶
func SetRootFile(cert string)
func SetSkipVerify ¶
func SetSkipVerify(skip bool)
func SetTcpKeepalive ¶
Allow TCP keepalive parameters to be set by the application
Types ¶
type AuditSpec ¶
type AuditSpec struct { Disabled []uint32 `json:"disabled"` Uid string `json:"uid"` AuditdEnabled bool `json:"auditdEnabled` DisabledUsers []AuditUser `json:"disabledUsers"` LogPath string `json:"logPath"` RotateInterval int64 `json:"rotateInterval"` RotateSize int64 `json:"rotateSize"` }
Sample data: {"disabled":["12333", "22244"],"uid":"132492431","auditdEnabled":true,
"disabledUsers":[{"name":"bill","domain":"local"},{"name":"bob","domain":"local"}], "logPath":"/Users/johanlarson/Library/Application Support/Couchbase/var/lib/couchbase/logs", "rotateInterval":86400,"rotateSize":20971520}
type AuthHandler ¶
AuthHandler is a callback that gets the auth username and password for the given bucket.
type AuthWithSaslHandler ¶
type AuthWithSaslHandler interface { AuthHandler GetSaslCredentials() (string, string) }
AuthHandler is a callback that gets the auth username and password for the given bucket and sasl for memcached.
type Bucket ¶
type Bucket struct { sync.RWMutex AuthType string `json:"authType"` Capabilities []string `json:"bucketCapabilities"` CapabilitiesVersion string `json:"bucketCapabilitiesVer"` CollectionsManifestUid string `json:"collectionsManifestUid"` Type string `json:"bucketType"` Name string `json:"name"` NodeLocator string `json:"nodeLocator"` Quota map[string]float64 `json:"quota,omitempty"` Replicas int `json:"replicaNumber"` Password string `json:"saslPassword"` URI string `json:"uri"` StreamingURI string `json:"streamingUri"` LocalRandomKeyURI string `json:"localRandomKeyUri,omitempty"` UUID string `json:"uuid"` ConflictResolutionType string `json:"conflictResolutionType,omitempty"` DDocs struct { URI string `json:"uri"` } `json:"ddocs,omitempty"` BasicStats map[string]interface{} `json:"basicStats,omitempty"` Controllers map[string]interface{} `json:"controllers,omitempty"` // These are used for JSON IO, but isn't used for processing // since it needs to be swapped out safely. VBSMJson VBucketServerMap `json:"vBucketServerMap"` NodesJSON []Node `json:"nodes"` // contains filtered or unexported fields }
Bucket is the primary entry point for most data operations. Bucket is a locked data structure. All access to its fields should be done using read or write locking, as appropriate.
Some access methods require locking, but rely on the caller to do so. These are appropriate for calls from methods that have already locked the structure. Methods like this take a boolean parameter "bucketLocked".
func ConnectWithAuthAndGetBucket ¶
func ConnectWithAuthAndGetBucket(endpoint, poolname, bucketname string, ah AuthHandler) (*Bucket, error)
ConnectWithAuthAndGetBucket is a convenience function for getting a named bucket from a given URL and an auth callback
func (*Bucket) Add ¶
func (b *Bucket) Add(k string, exp int, v interface{}, context ...*memcached.ClientContext) (added bool, err error)
Add adds a value to this bucket; like Set except that nothing happens if the key exists. The value will be serialized into a JSON document.
func (*Bucket) AddRaw ¶
func (b *Bucket) AddRaw(k string, exp int, v []byte, context ...*memcached.ClientContext) (added bool, err error)
AddRaw adds a value to this bucket; like SetRaw except that nothing happens if the key exists. The value will be stored as raw bytes.
func (*Bucket) AddRawWithMT ¶
func (b *Bucket) AddRawWithMT(k string, exp int, v []byte, context ...*memcached.ClientContext) (added bool, mt *MutationToken, err error)
AddRaw adds a value to this bucket; like SetRaw except that nothing happens if the key exists. The value will be stored as raw bytes.
func (*Bucket) AddWithMT ¶
func (b *Bucket) AddWithMT(k string, exp int, v interface{}, context ...*memcached.ClientContext) (added bool, mt *MutationToken, err error)
Add adds a value to this bucket; like Set except that nothing happens if the key exists. The value will be serialized into a JSON document.
func (*Bucket) Cas ¶
func (b *Bucket) Cas(k string, exp int, cas uint64, v interface{}, context ...*memcached.ClientContext) (uint64, error)
Set a value in this bucket with Cas and return the new Cas value
func (*Bucket) CasRaw ¶
func (b *Bucket) CasRaw(k string, exp int, cas uint64, v interface{}, context ...*memcached.ClientContext) (uint64, error)
Set a value in this bucket with Cas without json encoding it
func (*Bucket) CasWithMeta ¶
func (b *Bucket) CasWithMeta(k string, flags int, exp int, cas uint64, v interface{}, context ...*memcached.ClientContext) (uint64, *MutationToken, error)
Extended CAS operation. These functions will return the mutation token, i.e vbuuid & guard
func (*Bucket) CasWithMetaRaw ¶
func (*Bucket) Close ¶
func (b *Bucket) Close()
Close marks this bucket as no longer needed, closing connections it may have open.
func (*Bucket) CommonAddressSuffix ¶
CommonAddressSuffix finds the longest common suffix of all host:port strings in the node list.
func (*Bucket) CreateCollection ¶
func (*Bucket) CreateScope ¶
func (*Bucket) Decr ¶
func (b *Bucket) Decr(k string, amt, def uint64, exp int, context ...*memcached.ClientContext) (val uint64, err error)
Decr decrements the value at a given key by amt and defaults to def if no value present
func (*Bucket) DeleteDDoc ¶
DeleteDDoc removes a design document.
func (*Bucket) Do ¶
Do executes a function on a memcached connection to the node owning key "k"
Note that this automatically handles transient errors by replaying your function on a "not-my-vbucket" error, so don't assume your command will only be executed only once.
func (*Bucket) DropCollection ¶
func (*Bucket) FlushCollection ¶
func (*Bucket) GatherStats ¶
func (b *Bucket) GatherStats(which string) map[string]GatheredStats
GatherStats returns a map of server ID -> GatheredStats from all servers.
func (*Bucket) Get ¶
Get a value from this bucket. The value is expected to be a JSON stream and will be deserialized into rv.
func (*Bucket) GetAndTouchRaw ¶
func (b *Bucket) GetAndTouchRaw(k string, exp int, context ...*memcached.ClientContext) (data []byte, cas uint64, err error)
GetAndTouchRaw gets a raw value from this bucket including its CAS counter and flags, and updates the expiry on the doc.
func (*Bucket) GetBulk ¶
func (b *Bucket) GetBulk(keys []string, reqDeadline time.Time, subPaths []string, context ...*memcached.ClientContext) (map[string]*gomemcached.MCResponse, error)
func (*Bucket) GetBulkRaw ¶
func (b *Bucket) GetBulkRaw(keys []string, context ...*memcached.ClientContext) (map[string][]byte, error)
Fetches multiple keys concurrently, with []byte values
This is a wrapper around GetBulk which converts all values returned by GetBulk from raw memcached responses into []byte slices. Returns one document for duplicate keys
func (*Bucket) GetCollectionCID ¶
func (b *Bucket) GetCollectionCID(scope string, collection string, reqDeadline time.Time) (uint32, uint32, error)
Returns collectionUid, manifestUid, error.
func (*Bucket) GetCollectionsManifest ¶
This function assumes the bucket is locked.
func (*Bucket) GetCount ¶
func (b *Bucket) GetCount(refresh bool, context ...*memcached.ClientContext) (count int64, err error)
Get bucket count through the bucket stats
func (*Bucket) GetDDocWithRetry ¶
func (*Bucket) GetDDocs ¶
func (b *Bucket) GetDDocs() (DDocsResult, error)
GetDDocs lists all design documents
func (*Bucket) GetDDocsWithRetry ¶
func (b *Bucket) GetDDocsWithRetry() (DDocsResult, error)
func (*Bucket) GetFailoverLogs ¶
func (b *Bucket) GetFailoverLogs(vBuckets []uint16) (FailoverLog, error)
GetFailoverLogs, get the failover logs for a set of vbucket ids
func (*Bucket) GetMeta ¶
func (b *Bucket) GetMeta(k string, flags *int, expiry *int, cas *uint64, seqNo *uint64, context ...*memcached.ClientContext) (err error)
GetMeta returns the meta values for a key
func (*Bucket) GetNodeList ¶
func (*Bucket) GetPoolServices ¶
func (b *Bucket) GetPoolServices(name string) (*PoolServices, error)
func (*Bucket) GetRandomDoc ¶
func (b *Bucket) GetRandomDoc(context ...*memcached.ClientContext) (*gomemcached.MCResponse, error)
func (*Bucket) GetStats ¶
GetStats gets a set of stats from all servers.
Returns a map of server ID -> map of stat key to map value.
func (*Bucket) Gets ¶
func (b *Bucket) Gets(k string, rv interface{}, caso *uint64, context ...*memcached.ClientContext) error
Gets gets a value from this bucket, including its CAS counter. The value is expected to be a JSON stream and will be deserialized into rv.
func (*Bucket) GetsMC ¶
func (b *Bucket) GetsMC(key string, reqDeadline time.Time, context ...*memcached.ClientContext) (*gomemcached.MCResponse, error)
Get a value straight from Memcached
func (*Bucket) GetsRaw ¶
func (b *Bucket) GetsRaw(k string, context ...*memcached.ClientContext) (data []byte, flags int, cas uint64, err error)
GetsRaw gets a raw value from this bucket including its CAS counter and flags.
func (*Bucket) GetsSubDoc ¶
func (b *Bucket) GetsSubDoc(key string, reqDeadline time.Time, subPaths []string, context ...*memcached.ClientContext) (*gomemcached.MCResponse, error)
Get a value through the subdoc API
func (*Bucket) HealthyNodes ¶
return the list of healthy nodes
func (*Bucket) Incr ¶
func (b *Bucket) Incr(k string, amt, def uint64, exp int, context ...*memcached.ClientContext) (val uint64, err error)
Incr increments the value at a given key by amt and defaults to def if no value present.
func (*Bucket) NodeAddresses ¶
NodeAddresses gets the (sorted) list of memcached node addresses (hostname:port).
func (*Bucket) NodeListChanged ¶
This API lets the caller know, if the list of nodes a bucket is connected to has gone through an edit (a rebalance operation) since the last update to the bucket, in which case a Refresh is advised.
func (*Bucket) ObserveAndPersistPoll ¶
func (*Bucket) RefreshFully ¶
func (*Bucket) ReleaseGetBulkPools ¶
func (b *Bucket) ReleaseGetBulkPools(rv map[string]*gomemcached.MCResponse)
func (*Bucket) RunBucketUpdater ¶
func (*Bucket) RunBucketUpdater2 ¶
func (b *Bucket) RunBucketUpdater2(streamingFn StreamingFn, notify NotifyFn)
func (*Bucket) SetObserveAndPersist ¶
func (*Bucket) SetWithMeta ¶
func (b *Bucket) SetWithMeta(k string, flags int, exp int, v interface{}, context ...*memcached.ClientContext) (*MutationToken, error)
Set a value in this bucket with with flags
func (*Bucket) StartOPPollers ¶
func (*Bucket) StartTapFeed ¶
StartTapFeed creates and starts a new Tap feed
func (*Bucket) StartUprFeed ¶
func (*Bucket) StartUprFeedWithConfig ¶
func (b *Bucket) StartUprFeedWithConfig(name string, sequence uint32, data_chan_size int, dcp_buffer_size uint32) (*UprFeed, error)
StartUprFeed creates and starts a new Upr feed No data will be sent on the channel unless vbuckets streams are requested
func (*Bucket) Update ¶
func (b *Bucket) Update(k string, exp int, callback UpdateFunc) error
Update performs a Safe update of a document, avoiding conflicts by using CAS.
The callback function will be invoked with the current raw document contents (or nil if the document doesn't exist); it should return the updated raw contents (or nil to delete.) If it decides not to change anything it can return UpdateCancel as the error.
If another writer modifies the document between the get and the set, the callback will be invoked again with the newer value.
func (*Bucket) UpdateBucket ¶
func (*Bucket) UpdateBucket2 ¶
func (b *Bucket) UpdateBucket2(streamingFn StreamingFn) error
func (*Bucket) VBServerMap ¶
func (b *Bucket) VBServerMap() *VBucketServerMap
VBServerMap returns the current VBucketServerMap.
func (*Bucket) View ¶
func (b *Bucket) View(ddoc, name string, params map[string]interface{}) (ViewResult, error)
View executes a view.
The ddoc parameter is just the bare name of your design doc without the "_design/" prefix.
Parameters are string keys with values that correspond to couchbase view parameters. Primitive should work fairly naturally (booleans, ints, strings, etc...) and other values will attempt to be JSON marshaled (useful for array indexing on on view keys, for example).
Example:
res, err := couchbase.View("myddoc", "myview", map[string]interface{}{ "group_level": 2, "startkey_docid": []interface{}{"thing"}, "endkey_docid": []interface{}{"thing", map[string]string{}}, "stale": false, })
func (*Bucket) ViewCustom ¶
func (b *Bucket) ViewCustom(ddoc, name string, params map[string]interface{}, vres interface{}) (err error)
ViewCustom performs a view request that can map row values to a custom type.
See the source to View for an example usage.
func (*Bucket) ViewURL ¶
ViewURL constructs a URL for a view with the given ddoc, view name, and parameters.
func (*Bucket) WaitForPersistence ¶
WaitForPersistence waits for an item to be considered durable.
Besides transport errors, ErrOverwritten may be returned if the item is overwritten before it reaches durability. ErrTimeout may occur if the item isn't found durable in a reasonable amount of time.
func (*Bucket) Write ¶
func (b *Bucket) Write(k string, flags, exp int, v interface{}, opt WriteOptions, context ...*memcached.ClientContext) (err error)
General-purpose value setter.
The Set, Add and Delete methods are just wrappers around this. The interpretation of `v` depends on whether the `Raw` option is given. If it is, v must be a byte array or nil. (A nil value causes a delete.) If `Raw` is not given, `v` will be marshaled as JSON before being written. It must be JSON-marshalable and it must not be nil.
func (*Bucket) WriteCasWithMT ¶
func (b *Bucket) WriteCasWithMT(k string, flags, exp int, cas uint64, v interface{}, opt WriteOptions, context ...*memcached.ClientContext) (newCas uint64, mt *MutationToken, err error)
func (*Bucket) WriteUpdate ¶
func (b *Bucket) WriteUpdate(k string, exp int, callback WriteUpdateFunc) error
WriteUpdate performs a Safe update of a document, avoiding conflicts by using CAS. WriteUpdate is like Update, except that the callback can return a set of WriteOptions, of which Persist and Indexable are recognized: these cause the call to wait until the document update has been persisted to disk and/or become available to index.
func (*Bucket) WriteWithMT ¶
func (b *Bucket) WriteWithMT(k string, flags, exp int, v interface{}, opt WriteOptions, context ...*memcached.ClientContext) (mt *MutationToken, err error)
type BucketAuth ¶
type BucketAuth struct {
// contains filtered or unexported fields
}
func (*BucketAuth) GetCredentials ¶
func (ba *BucketAuth) GetCredentials() (string, string, string)
type BucketInfo ¶
func GetBucketList ¶
func GetBucketList(baseU string) (bInfo []BucketInfo, err error)
Get SASL buckets
type BucketNotFoundError ¶
type BucketNotFoundError struct {
// contains filtered or unexported fields
}
func (*BucketNotFoundError) Error ¶
func (e *BucketNotFoundError) Error() string
type Client ¶
A Client is the starting point for all services across all buckets in a Couchbase cluster.
func Connect ¶
Connect to a couchbase cluster. An authentication handler will be created from the userinfo in the URL if provided.
func ConnectWithAuth ¶
func ConnectWithAuth(baseU string, ah AuthHandler) (c Client, err error)
ConnectWithAuth connects to a couchbase cluster with the given authentication handler.
func ConnectWithAuthCreds ¶
ConnectWithAuthCreds connects to a couchbase cluster with the give authorization creds returned by cb_auth
func (*Client) GetAuditSpec ¶
func (*Client) GetPoolServices ¶
func (c *Client) GetPoolServices(name string) (ps PoolServices, err error)
GetPoolServices returns all the bucket-independent services in a pool. (See "Exposing services outside of bucket context" in http://goo.gl/uuXRkV)
func (*Client) GetRolesAll ¶
func (c *Client) GetRolesAll() ([]RoleDescription, error)
func (*Client) GetUserInfoAll ¶
func (*Client) GetUserRoles ¶
Return user-role data, as parsed JSON. Sample:
[{"id":"ivanivanov","name":"Ivan Ivanov","roles":[{"role":"cluster_admin"},{"bucket_name":"default","role":"bucket_admin"}]}, {"id":"petrpetrov","name":"Petr Petrov","roles":[{"role":"replication_admin"}]}]
func (*Client) InitTLS ¶
Call this method with a TLS certificate file name to make communication with the KV engine encrypted.
This method should be called immediately after a Connect*() method.
func (*Client) ProcessStream ¶
func (*Client) PutUserInfo ¶
type Collection ¶
type DDoc ¶
type DDoc struct { Language string `json:"language,omitempty"` Views map[string]ViewDefinition `json:"views"` }
DDoc is the document body of a design document specifying a view.
type DDocsResult ¶
type DDocsResult struct { Rows []struct { DDoc struct { Meta map[string]interface{} JSON DDoc } `json:"doc"` } `json:"rows"` }
DDocsResult represents the result from listing the design documents.
type DocID ¶
type DocID string
DocID is the document ID type for the startkey_docid parameter in views.
type DurablitySettings ¶
type FailoverLog ¶
type FailoverLog map[uint16]memcached.FailoverLog
type FeedInfo ¶
type FeedInfo struct {
// contains filtered or unexported fields
}
UprFeed from a single connection
type GenericMcdAuthHandler ¶
type GenericMcdAuthHandler interface { AuthHandler AuthenticateMemcachedConn(host string, conn *memcached.Client) error }
GenericMcdAuthHandler is a kind of AuthHandler that performs special auth exchange (like non-standard auth, possibly followed by select-bucket).
type HTTPAuthHandler ¶
type HTTPAuthHandler interface { AuthHandler SetCredsForRequest(req *http.Request) error }
HTTPAuthHandler is kind of AuthHandler that performs more general for outgoing http requests than is possible via simple GetCredentials() call (i.e. digest auth or different auth per different destinations).
type InputCollection ¶
type InputManifest ¶
type InputManifest struct { Uid string Scopes []InputScope }
Structures for parsing collections manifest. The map key is the name of the scope. Example data: {"uid":"b","scopes":[
{"name":"_default","uid":"0","collections":[ {"name":"_default","uid":"0"}]}, {"name":"myScope1","uid":"8","collections":[ {"name":"myCollectionB","uid":"c"}, {"name":"myCollectionA","uid":"b"}]}, {"name":"myScope2","uid":"9","collections":[ {"name":"myCollectionC","uid":"d"}]}]}
type InputScope ¶
type InputScope struct { Name string Uid string Collections []InputCollection }
type MultiBucketAuthHandler ¶
type MultiBucketAuthHandler interface { AuthHandler ForBucket(bucket string) AuthHandler }
MultiBucketAuthHandler is kind of AuthHandler that may perform different auth for different buckets.
type MutationToken ¶
type MutationToken struct { VBid uint16 // vbucket id Guard uint64 // vbuuid Value uint64 // sequence number }
Mutation Token
type Node ¶
type Node struct { ClusterCompatibility int `json:"clusterCompatibility"` ClusterMembership string `json:"clusterMembership"` CouchAPIBase string `json:"couchApiBase"` Hostname string `json:"hostname"` AlternateNames map[string]NodeAlternateNames `json:"alternateAddresses"` InterestingStats map[string]float64 `json:"interestingStats,omitempty"` MCDMemoryAllocated float64 `json:"mcdMemoryAllocated"` MCDMemoryReserved float64 `json:"mcdMemoryReserved"` MemoryFree float64 `json:"memoryFree"` MemoryTotal float64 `json:"memoryTotal"` OS string `json:"os"` Ports map[string]int `json:"ports"` Services []string `json:"services"` Status string `json:"status"` Uptime int `json:"uptime,string"` Version string `json:"version"` ThisNode bool `json:"thisNode,omitempty"` }
A Node is a computer in a cluster running the couchbase software.
type NodeAlternateNames ¶
type NodeServices ¶
type NodeServices struct { Services map[string]int `json:"services,omitempty"` Hostname string `json:"hostname"` ThisNode bool `json:"thisNode"` AlternateNames map[string]NodeAlternateNames `json:"alternateAddresses"` }
NodeServices is all the bucket-independent services running on a node (given by Hostname)
type OPErrResponse ¶
type OPErrResponse struct {
// contains filtered or unexported fields
}
type OPpool ¶
type OPpool struct {
// contains filtered or unexported fields
}
pool of ObservePersist Jobs
func (*OPpool) Put ¶
func (p *OPpool) Put(o *ObservePersistJob)
Return returns a Client to the pool.
type ObservePersistJob ¶
type ObservePersistJob struct {
// contains filtered or unexported fields
}
type Pool ¶
type Pool struct { BucketMap map[string]*Bucket Nodes []Node BucketURL map[string]string `json:"buckets"` MemoryQuota float64 `json:"memoryQuota"` CbasMemoryQuota float64 `json:"cbasMemoryQuota"` EventingMemoryQuota float64 `json:"eventingMemoryQuota"` FtsMemoryQuota float64 `json:"ftsMemoryQuota"` IndexMemoryQuota float64 `json:"indexMemoryQuota"` // contains filtered or unexported fields }
A Pool of nodes and buckets.
func (*Pool) Close ¶
func (p *Pool) Close()
Release bucket connections when the pool is no longer in use
func (*Pool) GetBucketWithAuth ¶
GetBucket gets a bucket from within this pool.
type PoolServices ¶
type PoolServices struct { Rev int `json:"rev"` NodesExt []NodeServices `json:"nodesExt"` Capabilities json.RawMessage `json:"clusterCapabilities"` }
PoolServices is all the bucket-independent services in a pool
func ParsePoolServices ¶
func ParsePoolServices(jsonInput string) (*PoolServices, error)
type Pools ¶
type Pools struct { ComponentsVersion map[string]string `json:"componentsVersion,omitempty"` ImplementationVersion string `json:"implementationVersion"` IsAdmin bool `json:"isAdminCreds"` UUID string `json:"uuid"` Pools []RestPool `json:"pools"` }
Pools represents the collection of pools as returned from the REST API.
type RestPool ¶
type RestPool struct { Name string `json:"name"` StreamingURI string `json:"streamingUri"` URI string `json:"uri"` }
RestPool represents a single pool returned from the pools REST API.
type RoleDescription ¶
type RoleDescription struct { Role string Name string Desc string Ce bool BucketName string `json:"bucket_name"` }
Sample: {"role":"admin","name":"Admin","desc":"Can manage ALL cluster features including security.","ce":true} {"role":"query_select","bucket_name":"*","name":"Query Select","desc":"Can execute SELECT statement on bucket to retrieve data"}
type Scope ¶
type Scope struct { Name string Uid uint64 Collections map[string]*Collection // map by name }
type StreamingFn ¶
type StreamingFn func(bucket *Bucket)
type TapFeed ¶
type TapFeed struct { C <-chan memcached.TapEvent // contains filtered or unexported fields }
A TapFeed streams mutation events from a bucket.
Events from the bucket can be read from the channel 'C'. Remember to call Close() on it when you're done, unless its channel has closed itself already.
type UpdateFunc ¶
An UpdateFunc is a callback function to update a document
type UprFeed ¶
type UprFeed struct { C <-chan *memcached.UprEvent // contains filtered or unexported fields }
A UprFeed streams mutation events from a bucket.
Events from the bucket can be read from the channel 'C'. Remember to call Close() on it when you're done, unless its channel has closed itself already.
func (*UprFeed) UprCloseStream ¶
UprCloseStream ends a vbucket stream.
type VBucketServerMap ¶
type VBucketServerMap struct { HashAlgorithm string `json:"hashAlgorithm"` NumReplicas int `json:"numReplicas"` ServerList []string `json:"serverList"` VBucketMap [][]int `json:"vBucketMap"` }
VBucketServerMap is the a mapping of vbuckets to nodes.
type ViewDefinition ¶
ViewDefinition represents a single view within a design document.
type ViewError ¶
A ViewError is a node-specific error indicating a partial failure within a view result.
type ViewResult ¶
ViewResult holds the entire result set from a view request, including the rows and the errors.
type ViewRow ¶
type ViewRow struct { ID string Key interface{} Value interface{} Doc *interface{} }
ViewRow represents a single result from a view.
Doc is present only if include_docs was set on the request.
type WriteOptions ¶
type WriteOptions int
WriteOptions is the set of option flags availble for the Write method. They are ORed together to specify the desired request.
func (WriteOptions) String ¶
func (w WriteOptions) String() string
String representation of WriteOptions
type WriteUpdateFunc ¶
type WriteUpdateFunc func(current []byte) (updated []byte, opt WriteOptions, err error)
A WriteUpdateFunc is a callback function to update a document
Source Files ¶
Directories ¶
Path | Synopsis |
---|---|
Package cbdatasource streams data from a Couchbase cluster.
|
Package cbdatasource streams data from a Couchbase cluster. |
examples
|
|
upr_bench
Tool receives raw events from go-couchbase UPR client.
|
Tool receives raw events from go-couchbase UPR client. |
tools
|
|
Package trace provides a ring buffer utility to trace events.
|
Package trace provides a ring buffer utility to trace events. |
Package couchbaseutil offers some convenience functions for apps that use couchbase.
|
Package couchbaseutil offers some convenience functions for apps that use couchbase. |