svcinstance

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Nov 14, 2019 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Overview

Package svcinstance provides a pool to keep track of the health status of service instances.

Usage

Instantiate the pool with a set of service instances. Use choose to select the best info according to the specified choosing algorithm. The caller should keep a reference to the returned Info and call Fail if an error is encountered during the request.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Info

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

Info holds the information for a service instance.

func (Info) Addr

func (i Info) Addr() *addr.AppAddr

Addr returns the service instance address.

func (Info) Fail

func (i Info) Fail()

Fail increases the fail count. It shall be called when a request to the service instance fails.

func (Info) Name

func (i Info) Name() string

Name returns the service instance name.

type Pool

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

Pool keeps track of the service instances information and their health status. It allows to choose service instances based on their health.

func NewPool

func NewPool(svcInfo topology.IDAddrMap, opts healthpool.PoolOptions) (*Pool, error)

NewPool initializes the pool with the provided service instances and pool options.

func (*Pool) Choose

func (p *Pool) Choose() (Info, error)

Choose chooses the instance based on the configured algorithm. If the pool is closed, an error is returned.

func (*Pool) Close

func (p *Pool) Close()

Close closes the pool. After closing the pool, Update and Choose will return errors. The pool is safe to being closed multiple times.

func (*Pool) Update

func (p *Pool) Update(svcInfo topology.IDAddrMap) error

Update updates the service instances in the pool. Instances in the pool that are not in svcInfo are removed. Instances in svcInfo that are not in the pool are added. Changed addresses of existing instances are updated. In that case, the fail count is reset to zero. However, if Options.AllowEmpty is not set, and the Update causes an empty pool, the instances are not replaced and an error is returned. If the pool is closed, an error is returned.

Jump to

Keyboard shortcuts

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