pail

package module
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: May 30, 2019 License: MPL-2.0 Imports: 3 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"
	
    "github.com/couchbase/gocb"
    "github.com/myENA/pail"
)

func main() {
	// create couchbase connection and bucket as you normally would
	connStr := "couchbase://127.0.0.1"
    cluster, err := gocb.Connect(connStr)
    if err != nil {
    	panic(err)
    }
    bucket, err := cluster.OpenBucket("mybuck", "mypass")
    if err != nil {
    	panic(err)
    }
    
    // once created, make a new pail 
    p, err := pail.New(bucket, 5)
    if err != nil {
    	panic(err)
    }
    
    // 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
    cas, err := p.TryGet("mykey", tPtr)
    if err != nil {
    	panic(err)
    }
    fmt.Println(cas)
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type LookupInBuilder

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

LookupInBuilder embeds the gocb.LookupInBuilder type, enabling retry functionality

func (*LookupInBuilder) Exists

func (lib *LookupInBuilder) Exists(path string) *LookupInBuilder

Exists wraps the default couchbase Exists with retries

func (*LookupInBuilder) ExistsEx

func (lib *LookupInBuilder) ExistsEx(path string, flags gocb.SubdocFlag) *LookupInBuilder

ExistsEx wraps the default couchbase ExistsEx with retries

func (*LookupInBuilder) Get

func (lib *LookupInBuilder) Get(path string) *LookupInBuilder

Get wraps the default couchbase Get with retries

func (*LookupInBuilder) GetCount

func (lib *LookupInBuilder) GetCount(path string) *LookupInBuilder

GetCount wraps the default couchbase GetCount with retries

func (*LookupInBuilder) GetCountEx

func (lib *LookupInBuilder) GetCountEx(path string, flags gocb.SubdocFlag) *LookupInBuilder

GetCountEx wraps the default couchbase GetCountEx with retries

func (*LookupInBuilder) GetEx

func (lib *LookupInBuilder) GetEx(path string, flags gocb.SubdocFlag) *LookupInBuilder

GetEx wraps the default couchbase GetEx with retries

func (*LookupInBuilder) TryExecute

func (lib *LookupInBuilder) TryExecute() (*gocb.DocumentFragment, error)

TryExecute will repeatedly execute the TryLookupIn call until success, non-connection error is seen, or retries is breached

type MutateInBuilder

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

MutateInBuilder embeds the gocb.MutateInBuilder type, enabling retry functionality

func (*MutateInBuilder) ArrayAddUnique

func (mib *MutateInBuilder) ArrayAddUnique(path string, value interface{}, createParents bool) *MutateInBuilder

ArrayAddUnique wraps the default couchbase ArrayAddUnique with retries

func (*MutateInBuilder) ArrayAddUniqueEx

func (mib *MutateInBuilder) ArrayAddUniqueEx(path string, value interface{}, flags gocb.SubdocFlag) *MutateInBuilder

ArrayAddUniqueEx wraps the default couchbase ArrayAddUniqueEx with retries

func (*MutateInBuilder) ArrayAppend

func (mib *MutateInBuilder) ArrayAppend(path string, value interface{}, createParents bool) *MutateInBuilder

ArrayAppend wraps the default couchbase ArrayAppend with retries

func (*MutateInBuilder) ArrayAppendEx

func (mib *MutateInBuilder) ArrayAppendEx(path string, value interface{}, flags gocb.SubdocFlag) *MutateInBuilder

ArrayAppendEx wraps the default couchbase ArrayAppendEx with retries

func (*MutateInBuilder) ArrayAppendMulti

func (mib *MutateInBuilder) ArrayAppendMulti(path string, values interface{}, createParents bool) *MutateInBuilder

ArrayAppendMulti wraps the default couchbase ArrayAppendMulti with retries

func (*MutateInBuilder) ArrayAppendMultiEx

func (mib *MutateInBuilder) ArrayAppendMultiEx(path string, values interface{}, flags gocb.SubdocFlag) *MutateInBuilder

ArrayAppendMultiEx wraps the default couchbase ArrayAppendMultiEx with retries

func (*MutateInBuilder) ArrayInsert

func (mib *MutateInBuilder) ArrayInsert(path string, value interface{}) *MutateInBuilder

ArrayInsert wraps the default couchbase ArrayInsert with retries

func (*MutateInBuilder) ArrayInsertEx

func (mib *MutateInBuilder) ArrayInsertEx(path string, value interface{}, flags gocb.SubdocFlag) *MutateInBuilder

ArrayInsertEx wraps the default couchbase ArrayInsertEx with retries

func (*MutateInBuilder) ArrayInsertMulti

func (mib *MutateInBuilder) ArrayInsertMulti(path string, values interface{}) *MutateInBuilder

ArrayInsertMulti wraps the default couchbase ArrayInsertMulti with retries

func (*MutateInBuilder) ArrayInsertMultiEx

func (mib *MutateInBuilder) ArrayInsertMultiEx(path string, values interface{}, flags gocb.SubdocFlag) *MutateInBuilder

ArrayInsertMultiEx wraps the default couchbase ArrayInsertMultiEx with retries

func (*MutateInBuilder) ArrayPrepend

func (mib *MutateInBuilder) ArrayPrepend(path string, value interface{}, createParents bool) *MutateInBuilder

ArrayPrepend wraps the default couchbase ArrayPrepend with retries

func (*MutateInBuilder) ArrayPrependEx

func (mib *MutateInBuilder) ArrayPrependEx(path string, value interface{}, flags gocb.SubdocFlag) *MutateInBuilder

ArrayPrependEx wraps the default couchbase ArrayPrependEx with retries

func (*MutateInBuilder) ArrayPrependMulti

func (mib *MutateInBuilder) ArrayPrependMulti(path string, values interface{}, createParents bool) *MutateInBuilder

ArrayPrependMulti wraps the default couchbase ArrayPrependMulti with retries

func (*MutateInBuilder) ArrayPrependMultiEx

func (mib *MutateInBuilder) ArrayPrependMultiEx(path string, values interface{}, flags gocb.SubdocFlag) *MutateInBuilder

ArrayPrependMultiEx wraps the default couchbase ArrayPrependMultiEx with retries

func (*MutateInBuilder) Counter

func (mib *MutateInBuilder) Counter(path string, delta int64, createParents bool) *MutateInBuilder

Counter wraps the default couchbase Counter with retries

func (*MutateInBuilder) CounterEx

func (mib *MutateInBuilder) CounterEx(path string, delta int64, flags gocb.SubdocFlag) *MutateInBuilder

CounterEx wraps the default couchbase CounterEx with retries

func (*MutateInBuilder) Insert

func (mib *MutateInBuilder) Insert(path string, value interface{}, createParents bool) *MutateInBuilder

Insert wraps the default couchbase Insert with retries

func (*MutateInBuilder) InsertEx

func (mib *MutateInBuilder) InsertEx(path string, value interface{}, flags gocb.SubdocFlag) *MutateInBuilder

InsertEx wraps the default couchbase InsertEx with retries

func (*MutateInBuilder) Remove

func (mib *MutateInBuilder) Remove(path string) *MutateInBuilder

Remove wraps the default couchbase Remove with retries

func (*MutateInBuilder) RemoveEx

func (mib *MutateInBuilder) RemoveEx(path string, flags gocb.SubdocFlag) *MutateInBuilder

RemoveEx wraps the default couchbase RemoveEx with retries

func (*MutateInBuilder) Replace

func (mib *MutateInBuilder) Replace(path string, value interface{}) *MutateInBuilder

Replace wraps the default Couchbase Replace with retries

func (*MutateInBuilder) ReplaceEx

func (mib *MutateInBuilder) ReplaceEx(path string, value interface{}, flags gocb.SubdocFlag) *MutateInBuilder

ReplaceEx wraps the default Couchbase ReplaceEx with retries

func (*MutateInBuilder) TryExecute

func (mib *MutateInBuilder) TryExecute() (*gocb.DocumentFragment, error)

TryExecute will attempt the TryMutateIn call repeatedly until success, non-connection error is seen, or retries is breached

func (*MutateInBuilder) Upsert

func (mib *MutateInBuilder) Upsert(path string, value interface{}, createParents bool) *MutateInBuilder

Upsert wraps the default couchbase Upsert with retries

func (*MutateInBuilder) UpsertEx

func (mib *MutateInBuilder) UpsertEx(path string, value interface{}, flags gocb.SubdocFlag) *MutateInBuilder

UpsertEx wraps the default couchbase UpsertEx with retries

type Pail

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

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

func New

func New(bucket *gocb.Bucket, retries int) (*Pail, error)

New will create a new Pail for you to use

err is here for forwards compatibility

func (*Pail) Try

func (p *Pail) Try(retries int, fn RetryFunc) error

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

func (*Pail) TryCounter

func (p *Pail) TryCounter(key string, delta, initial int64, expiry uint32) (uint64, gocb.Cas, error)

TryCounter wraps bucket.Counter with a retry func

func (*Pail) TryDo

func (p *Pail) TryDo(ops []gocb.BulkOp) error

TryDo wraps bucket.Do with a retry func

func (*Pail) TryExecuteN1qlQuery

func (p *Pail) TryExecuteN1qlQuery(n1ql *gocb.N1qlQuery, params interface{}) (gocb.QueryResults, error)

TryExecuteN1qlQuery wraps bucket.ExecuteN1qlQuery with a retry func

func (*Pail) TryGet

func (p *Pail) TryGet(key string, valuePtr interface{}) (gocb.Cas, error)

TryGet wraps bucket.Get with a retry func

func (*Pail) TryInsert

func (p *Pail) TryInsert(key string, value interface{}, expiry uint32) (gocb.Cas, error)

TryInsert wraps bucket.Insert with a retry func

func (*Pail) TryLookupIn

func (p *Pail) TryLookupIn(key string) *LookupInBuilder

TryLookupIn wraps bucket.TryLookupIn with our own LookupInBuilder

func (*Pail) TryLookupInEx

func (p *Pail) TryLookupInEx(key string, flags gocb.SubdocDocFlag) *LookupInBuilder

TryLookupInEx wraps bucket.TryLookupInEx with our own LookupInBuilder

func (*Pail) TryMutateIn

func (p *Pail) TryMutateIn(key string, cas gocb.Cas, expiry uint32) *MutateInBuilder

TryMutateIn wraps bucket.TryMutateIn with our own MutateInBuilder

func (*Pail) TryMutateInEx

func (p *Pail) TryMutateInEx(key string, flags gocb.SubdocDocFlag, cas gocb.Cas, expiry uint32) *MutateInBuilder

TryMutateInEx wraps bucket.TryMutateInEx with our own MutateInBuilder

func (*Pail) TryN1qlQueryNotBounded

func (p *Pail) TryN1qlQueryNotBounded(query string, params ...interface{}) (gocb.QueryResults, error)

TryN1qlQueryNotBounded creates and executes a new N1ql query with parameters, setting the NotBounded consistency type

func (*Pail) TryN1qlQueryRequestPlus

func (p *Pail) TryN1qlQueryRequestPlus(query string, params ...interface{}) (gocb.QueryResults, error)

TryN1qlQueryRequestPlus creates and executes a new N1ql query with parameters, setting the RequestPlus consistency type

func (*Pail) TryN1qlQueryStatementPlus added in v0.2.0

func (p *Pail) TryN1qlQueryStatementPlus(query string, params ...interface{}) (gocb.QueryResults, error)

TryN1qlQueryStatementPlus creates and executes a new N1ql query with parameters, setting the StatementPlus consistency type

func (*Pail) TryN1qlQueryWithParameters

func (p *Pail) TryN1qlQueryWithParameters(query string, consistency gocb.ConsistencyMode, params interface{}) (gocb.QueryResults, error)

TryN1qlQueryWithParameters will create and execute a new N1qlQuery type, setting the provided consistency and parameters for you

func (*Pail) TryRemove

func (p *Pail) TryRemove(key string, cas gocb.Cas) (gocb.Cas, error)

TryRemove wraps bucket.Remove with a retry func

func (*Pail) TryReplace

func (p *Pail) TryReplace(key string, value interface{}, cas gocb.Cas, expiry uint32) (gocb.Cas, error)

TryReplace wraps bucket.replace with a retry func

func (*Pail) TryTouch

func (p *Pail) TryTouch(key string, cas gocb.Cas, expiry uint32) (gocb.Cas, error)

TryTouch wraps bucket.Touch with a retry func

func (*Pail) TryUpsert

func (p *Pail) TryUpsert(key string, value interface{}, expiry uint32) (gocb.Cas, error)

TryUpsert wraps bucket.Upsert with a retry func

func (*Pail) TryViewQuery

func (p *Pail) TryViewQuery(vq *gocb.ViewQuery) (gocb.ViewResults, error)

TryViewQuery - ExecuteViewQuery Try() wrapper.

type RetryFunc

type RetryFunc func(*gocb.Bucket) error

RetryFunc - this is passed to Try

Jump to

Keyboard shortcuts

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