pail

package module
v2.1.0 Latest Latest
Warning

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

Go to latest
Published: Dec 16, 2021 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 (c *Cluster) QueryOptions(in *gocb.QueryOptions, fn ClusterRetryFunc) (ClusterRetryContext, *gocb.QueryOptions)

func (*Cluster) SearchOptions

func (c *Cluster) SearchOptions(in *gocb.SearchOptions, fn ClusterRetryFunc) (ClusterRetryContext, *gocb.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) AppendOptions

func (c *Collection) AppendOptions(in *gocb.AppendOptions, fn CollectionRetryFunc) (CollectionRetryContext, *gocb.AppendOptions)

func (*Collection) BulkOpOptions

func (c *Collection) BulkOpOptions(in *gocb.BulkOpOptions, fn CollectionRetryFunc) (CollectionRetryContext, *gocb.BulkOpOptions)

func (*Collection) DecrementOptions

func (c *Collection) DecrementOptions(in *gocb.DecrementOptions, fn CollectionRetryFunc) (CollectionRetryContext, *gocb.DecrementOptions)

func (*Collection) GetOptions

func (c *Collection) GetOptions(in *gocb.GetOptions, fn CollectionRetryFunc) (CollectionRetryContext, *gocb.GetOptions)

func (*Collection) IncrementOptions

func (c *Collection) IncrementOptions(in *gocb.IncrementOptions, fn CollectionRetryFunc) (CollectionRetryContext, *gocb.IncrementOptions)

func (*Collection) InsertOptions

func (c *Collection) InsertOptions(in *gocb.InsertOptions, fn CollectionRetryFunc) (CollectionRetryContext, *gocb.InsertOptions)

func (*Collection) PrependOptions

func (c *Collection) PrependOptions(in *gocb.PrependOptions, fn CollectionRetryFunc) (CollectionRetryContext, *gocb.PrependOptions)

func (*Collection) RemoveOptions

func (c *Collection) RemoveOptions(in *gocb.RemoveOptions, fn CollectionRetryFunc) (CollectionRetryContext, *gocb.RemoveOptions)

func (*Collection) ReplaceOptions

func (c *Collection) ReplaceOptions(in *gocb.ReplaceOptions, fn CollectionRetryFunc) (CollectionRetryContext, *gocb.ReplaceOptions)

func (*Collection) TouchOptions

func (c *Collection) TouchOptions(in *gocb.TouchOptions, fn CollectionRetryFunc) (CollectionRetryContext, *gocb.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)

func (*Collection) UpsertOptions

func (c *Collection) UpsertOptions(in *gocb.UpsertOptions, fn CollectionRetryFunc) (CollectionRetryContext, *gocb.UpsertOptions)

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

func (rc DefaultClusterRetryContext) Try(c *gocb.Cluster) error

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) BuildDeferredQueryIndexOptions

func (qm *QueryIndexManager) BuildDeferredQueryIndexOptions(in *gocb.BuildDeferredQueryIndexOptions, fn QueryIndexManagerRetryFunc) (QueryIndexManagerRetryContext, *gocb.BuildDeferredQueryIndexOptions)

func (*QueryIndexManager) CreatePrimaryQueryIndexOptions

func (qm *QueryIndexManager) CreatePrimaryQueryIndexOptions(in *gocb.CreatePrimaryQueryIndexOptions, fn QueryIndexManagerRetryFunc) (QueryIndexManagerRetryContext, *gocb.CreatePrimaryQueryIndexOptions)

func (*QueryIndexManager) CreateQueryIndexOptions

func (qm *QueryIndexManager) CreateQueryIndexOptions(in *gocb.CreateQueryIndexOptions, fn QueryIndexManagerRetryFunc) (QueryIndexManagerRetryContext, *gocb.CreateQueryIndexOptions)

func (*QueryIndexManager) DropPrimaryQueryIndexOptions

func (qm *QueryIndexManager) DropPrimaryQueryIndexOptions(in *gocb.DropPrimaryQueryIndexOptions, fn QueryIndexManagerRetryFunc) (QueryIndexManagerRetryContext, *gocb.DropPrimaryQueryIndexOptions)

func (*QueryIndexManager) DropQueryIndexOptions

func (qm *QueryIndexManager) DropQueryIndexOptions(in *gocb.DropQueryIndexOptions, fn QueryIndexManagerRetryFunc) (QueryIndexManagerRetryContext, *gocb.DropQueryIndexOptions)

func (*QueryIndexManager) GetAllQueryIndexesOptions

func (qm *QueryIndexManager) GetAllQueryIndexesOptions(in *gocb.GetAllQueryIndexesOptions, fn QueryIndexManagerRetryFunc) (QueryIndexManagerRetryContext, *gocb.GetAllQueryIndexesOptions)

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)

func (*QueryIndexManager) WatchQueryIndexOptions

func (qm *QueryIndexManager) WatchQueryIndexOptions(in *gocb.WatchQueryIndexOptions, fn QueryIndexManagerRetryFunc) (QueryIndexManagerRetryContext, *gocb.WatchQueryIndexOptions)

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

func (rc SimpleCollectionRetryContext) Try(c *gocb.Collection) error

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

func (rc SimpleQueryIndexManagerRetryContext) Try(qm *gocb.QueryIndexManager) error

Jump to

Keyboard shortcuts

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