pail

package module
Version: v2.0.2 Latest Latest
Warning

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

Go to latest
Published: Sep 25, 2020 License: MPL-2.0 Imports: 6 Imported by: 0

README

pail

Lightweight extension to couchbase/gocb bucket that provides CRUD and N1QL retry logic

Purpose

In our testing with Couchbase, we noticed we sometimes see errors that stem from either an internal lock within the gocb client, sporadic networking issues, etc etc. These errors have nothing to do with the request being executed and there is nothing to "handle" within our app code, thus the only solution was to catch every error and just try it again.

This package is the end result of that work. Its only dependency is the upstream gocb package, and provides glide, dep, and mod dependency manager files.

Basic Usage

package main

import(
	"fmt"
    "time"
	
    "github.com/couchbase/gocb/v2"
    "github.com/myENA/pail/v2"
)

func main() {
	// create couchbase connection and bucket as you normally would
	connStr := "couchbase://127.0.0.1"
    cluster, err := pail.Connect(connStr, gocb.ClusterOptions{}, 5, 20 * time.Millisecond)
    if err != nil {
    	panic(err)
    }
    p := cluster.Bucket("bucketname")
    
    // From here, the API is pretty simple.  Any call you wish to attempt retries on, execute the "TryX" version of the
    // standard api method
    
    type pType struct {
    	Key string
    	Value string
    }
    
    tPtr := new(pType)
    
    // TryGet wraps bucket.Get
    res, err := p.DefaultCollection().TryGetContent("mykey", tPtr, nil)
    if err != nil {
    	panic(err)
    }
    fmt.Println(res)
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Cluster

type Cluster struct {
	*gocb.Cluster
	// contains filtered or unexported fields
}

func Connect

func Connect(connStr string, opts gocb.ClusterOptions, retries int, delay time.Duration) (*Cluster, error)

func NewCluster

func NewCluster(cluster *gocb.Cluster, retries int, delay time.Duration) *Cluster

func (*Cluster) Bucket

func (c *Cluster) Bucket(bucketName string) *Pail

func (*Cluster) QueryOptions

func (*Cluster) SearchOptions

func (*Cluster) Try

func (c *Cluster) Try(ctx ClusterRetryContext) error

func (*Cluster) TryQuery added in v2.0.1

func (c *Cluster) TryQuery(statement string, opts *gocb.QueryOptions) (*gocb.QueryResult, error)

func (*Cluster) TryQueryIndexes added in v2.0.1

func (c *Cluster) TryQueryIndexes() *QueryIndexManager

func (*Cluster) TrySearchQuery added in v2.0.1

func (c *Cluster) TrySearchQuery(indexName string, query cbsearch.Query, opts *gocb.SearchOptions) (*gocb.SearchResult, error)

type ClusterRetryContext

type ClusterRetryContext interface {
	gocb.RetryStrategy
	Try(*gocb.Cluster) error
}

type ClusterRetryFunc

type ClusterRetryFunc func(*gocb.Cluster) error

type Collection

type Collection struct {
	*gocb.Collection
	// contains filtered or unexported fields
}

func (*Collection) GetOptions

func (*Collection) TouchOptions

func (*Collection) Try

Try will attempt to execute retryFunc up to retries+1 times or until a non-connection-related error is seen.

func (*Collection) TryAppend

func (c *Collection) TryAppend(id string, value []byte, opts *gocb.AppendOptions) (*gocb.MutationResult, error)

func (*Collection) TryDecrement

func (c *Collection) TryDecrement(id string, opts *gocb.DecrementOptions) (*gocb.CounterResult, error)

func (*Collection) TryDo

func (c *Collection) TryDo(ops []gocb.BulkOp, opts *gocb.BulkOpOptions) error

func (*Collection) TryGet

func (c *Collection) TryGet(id string, opts *gocb.GetOptions) (*gocb.GetResult, error)

func (*Collection) TryGetContent

func (c *Collection) TryGetContent(id string, ptr interface{}, opts *gocb.GetOptions) (*gocb.GetResult, error)

func (*Collection) TryIncrement

func (c *Collection) TryIncrement(id string, opts *gocb.IncrementOptions) (*gocb.CounterResult, error)

func (*Collection) TryInsert

func (c *Collection) TryInsert(id string, value interface{}, opts *gocb.InsertOptions) (*gocb.MutationResult, error)

func (*Collection) TryPrepend

func (c *Collection) TryPrepend(id string, value []byte, opts *gocb.PrependOptions) (*gocb.MutationResult, error)

func (*Collection) TryRemove

func (c *Collection) TryRemove(id string, opts *gocb.RemoveOptions) (*gocb.MutationResult, error)

func (*Collection) TryReplace

func (c *Collection) TryReplace(id string, value interface{}, opts *gocb.ReplaceOptions) (*gocb.MutationResult, error)

func (*Collection) TryTouch

func (c *Collection) TryTouch(id string, expiry time.Duration, opts *gocb.TouchOptions) (*gocb.MutationResult, error)

func (*Collection) TryUpsert

func (c *Collection) TryUpsert(id string, value interface{}, opts *gocb.UpsertOptions) (*gocb.MutationResult, error)

type CollectionRetryContext

type CollectionRetryContext interface {
	gocb.RetryStrategy
	Try(*gocb.Collection) error
}

type CollectionRetryFunc

type CollectionRetryFunc func(*gocb.Collection) error

type ConnectionErrorRetryAction

type ConnectionErrorRetryAction time.Duration

func (ConnectionErrorRetryAction) Duration

type DefaultClusterRetryContext

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

func NewSimpleClusterRetryContext

func NewSimpleClusterRetryContext(retries uint32, delay time.Duration, baseStrategy gocb.RetryStrategy, fn ClusterRetryFunc) DefaultClusterRetryContext

func (DefaultClusterRetryContext) RetryAfter

func (bc DefaultClusterRetryContext) RetryAfter(req gocb.RetryRequest, reason gocb.RetryReason) gocb.RetryAction

func (DefaultClusterRetryContext) Try

type Pail

type Pail struct {
	*gocb.Bucket
	// contains filtered or unexported fields
}

Pail is our gocb.Bucket wrapper, providing retry goodness.

func NewPail

func NewPail(bucket *gocb.Bucket, retries int, delay time.Duration) *Pail

func (*Pail) Collection

func (p *Pail) Collection(collectionName string) *Collection

func (*Pail) DefaultCollection

func (p *Pail) DefaultCollection() *Collection

func (*Pail) DefaultScope

func (p *Pail) DefaultScope() *Scope

func (*Pail) Scope

func (p *Pail) Scope(scopeName string) *Scope

func (*Pail) ScopeCollection

func (p *Pail) ScopeCollection(scopeName, collectionName string) *Collection

type QueryIndexManager

type QueryIndexManager struct {
	*gocb.QueryIndexManager
	// contains filtered or unexported fields
}

func NewQueryIndexManager

func NewQueryIndexManager(queryIndexManager *gocb.QueryIndexManager, retries int, delay time.Duration) *QueryIndexManager

func (*QueryIndexManager) Try

func (*QueryIndexManager) TryBuildDeferredIndexes added in v2.0.1

func (qm *QueryIndexManager) TryBuildDeferredIndexes(bucketName string, opts *gocb.BuildDeferredQueryIndexOptions) ([]string, error)

func (*QueryIndexManager) TryCreateIndex added in v2.0.1

func (qm *QueryIndexManager) TryCreateIndex(bucketName, indexName string, fields []string, opts *gocb.CreateQueryIndexOptions) error

func (*QueryIndexManager) TryCreatePrimaryIndex added in v2.0.1

func (qm *QueryIndexManager) TryCreatePrimaryIndex(bucketName string, opts *gocb.CreatePrimaryQueryIndexOptions) error

func (*QueryIndexManager) TryDropIndex added in v2.0.1

func (qm *QueryIndexManager) TryDropIndex(bucketName, indexName string, opts *gocb.DropQueryIndexOptions) error

func (*QueryIndexManager) TryDropPrimaryIndex added in v2.0.1

func (qm *QueryIndexManager) TryDropPrimaryIndex(bucketName string, opts *gocb.DropPrimaryQueryIndexOptions) error

func (*QueryIndexManager) TryGetAllIndexes added in v2.0.1

func (qm *QueryIndexManager) TryGetAllIndexes(bucketName string, opts *gocb.GetAllQueryIndexesOptions) ([]gocb.QueryIndex, error)

type QueryIndexManagerRetryContext

type QueryIndexManagerRetryContext interface {
	gocb.RetryStrategy
	Try(*gocb.QueryIndexManager) error
}

type QueryIndexManagerRetryFunc

type QueryIndexManagerRetryFunc func(*gocb.QueryIndexManager) error

type Scope

type Scope struct {
	*gocb.Scope
	// contains filtered or unexported fields
}

func (*Scope) Collection

func (s *Scope) Collection(collectionName string) *Collection

func (*Scope) DefaultCollection

func (s *Scope) DefaultCollection() *Collection

type SimpleCollectionRetryContext

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

func NewSimpleCollectionRetryContext

func NewSimpleCollectionRetryContext(retries uint32, delay time.Duration, baseStrategy gocb.RetryStrategy, fn CollectionRetryFunc) SimpleCollectionRetryContext

func (SimpleCollectionRetryContext) RetryAfter

func (bc SimpleCollectionRetryContext) RetryAfter(req gocb.RetryRequest, reason gocb.RetryReason) gocb.RetryAction

func (SimpleCollectionRetryContext) Try

type SimpleQueryIndexManagerRetryContext

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

func NewSimpleQueryIndexManagerRetryContext

func NewSimpleQueryIndexManagerRetryContext(retries uint32, delay time.Duration, baseStrategy gocb.RetryStrategy, fn QueryIndexManagerRetryFunc) SimpleQueryIndexManagerRetryContext

func (SimpleQueryIndexManagerRetryContext) RetryAfter

func (bc SimpleQueryIndexManagerRetryContext) RetryAfter(req gocb.RetryRequest, reason gocb.RetryReason) gocb.RetryAction

func (SimpleQueryIndexManagerRetryContext) Try

Source Files

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
t or T : Toggle theme light dark auto
y or Y : Canonical URL