Back to godoc.org

Package rpcretry

v1.6.3
Latest Go to latest

The latest major version is .

Published: Aug 30, 2020 | License: MIT | Module: go.mercari.io/datastore

Overview

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.

Example (HowToUse)

Code:

package main

import (
	"context"
	"go.mercari.io/datastore/clouddatastore"
	"go.mercari.io/datastore/dsmiddleware/rpcretry"
	"go.mercari.io/datastore/internal/testutils"
	"time"
)

func main() {
	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

func New

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

New automatically RPC retry middleware creates & returns.

type RetryOption

type RetryOption interface {
	Apply(*retryHandler)
}

A RetryOption is an retry option for a retry middleware.

func WithLogf

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

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

WithLogger creates a ClientOption that uses the specified logger.

func WithMaxBackoffDuration

func WithMaxBackoffDuration(d time.Duration) RetryOption

WithMaxBackoffDuration specified maximum duratiuon of retry backoff.

func WithMaxDoublings

func WithMaxDoublings(maxDoublings int) RetryOption

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

func WithMinBackoffDuration

func WithMinBackoffDuration(d time.Duration) RetryOption

WithMinBackoffDuration specified minimal duration of retry backoff.

func WithRetryLimit

func WithRetryLimit(limit int) RetryOption

WithRetryLimit provides retry limit when RPC failed.

Package Files

Documentation was rendered with GOOS=linux and GOARCH=amd64.

Jump to identifier

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to identifier