datastore: go.mercari.io/datastore/dsmiddleware/rpcretry Index | Examples | Files

package rpcretry

import "go.mercari.io/datastore/dsmiddleware/rpcretry"

Package rpcretry automatically retries when some RPCs end in error. RPC sometimes fails rarely and this may be able to recover simply by retrying.

Non idempotency operations (Commit, Rollback, and Next) are not automatically retried.

By default, it retries up to 3 times. First wait 100 milliseconds, then wait exponentially back off. This value can be changed by option.

Code:

ctx := context.Background()
client, err := clouddatastore.FromContext(ctx)
if err != nil {
    panic(err)
}
defer client.Close()
defer testutils.CleanUpAllEntities(ctx, client)

mw := rpcretry.New(
    rpcretry.WithRetryLimit(5),
    rpcretry.WithMinBackoffDuration(10*time.Millisecond),
    rpcretry.WithMaxBackoffDuration(150*time.Microsecond),
    // rpcretry.WithMaxDoublings(2),
)
client.AppendMiddleware(mw)

Index

Examples

Package Files

doc.go option.go rpcretry.go

func New Uses

func New(opts ...RetryOption) datastore.Middleware

New automatically RPC retry middleware creates & returns.

type RetryOption Uses

type RetryOption interface {
    Apply(*retryHandler)
}

A RetryOption is an retry option for a retry middleware.

func WithLogf Uses

func WithLogf(logf func(ctx context.Context, format string, args ...interface{})) RetryOption

WithLogf creates a ClientOption that uses the specified logger.

Deprecated: use WithLogger instead.

func WithLogger Uses

func WithLogger(logf func(ctx context.Context, format string, args ...interface{})) RetryOption

WithLogger creates a ClientOption that uses the specified logger.

func WithMaxBackoffDuration Uses

func WithMaxBackoffDuration(d time.Duration) RetryOption

WithMaxBackoffDuration specified maximum duratiuon of retry backoff.

func WithMaxDoublings Uses

func WithMaxDoublings(maxDoublings int) RetryOption

WithMaxDoublings specifies how many times the waiting time should be doubled.

func WithMinBackoffDuration Uses

func WithMinBackoffDuration(d time.Duration) RetryOption

WithMinBackoffDuration specified minimal duration of retry backoff.

func WithRetryLimit Uses

func WithRetryLimit(limit int) RetryOption

WithRetryLimit provides retry limit when RPC failed.

Package rpcretry imports 4 packages (graph) and is imported by 1 packages. Updated 2018-07-30. Refresh now. Tools for package owners.