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.
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 ¶
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 ¶
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.