queue

package
v1.7.0-rc.2 Latest Latest
Warning

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

Go to latest
Published: Feb 19, 2021 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrTooManyRequests = errors.New("too many outstanding requests")
	ErrStopped         = errors.New("queue is stopped")
)

Functions

This section is empty.

Types

type Request

type Request interface{}

Request stored into the queue.

type RequestQueue

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

RequestQueue holds incoming requests in per-user queues. It also assigns each user specified number of queriers, and when querier asks for next request to handle (using GetNextRequestForQuerier), it returns requests in a fair fashion.

func NewRequestQueue

func NewRequestQueue(maxOutstandingPerTenant int, queueLength *prometheus.GaugeVec) *RequestQueue

func (*RequestQueue) EnqueueRequest

func (q *RequestQueue) EnqueueRequest(userID string, req Request, maxQueriers int, successFn func()) error

Puts the request into the queue. MaxQueries is user-specific value that specifies how many queriers can this user use (zero or negative = all queriers). It is passed to each EnqueueRequest, because it can change between calls.

If request is successfully enqueued, successFn is called with the lock held, before any querier can receive the request.

func (*RequestQueue) GetConnectedQuerierWorkersMetric

func (q *RequestQueue) GetConnectedQuerierWorkersMetric() float64

func (*RequestQueue) GetNextRequestForQuerier

func (q *RequestQueue) GetNextRequestForQuerier(ctx context.Context, last UserIndex, querierID string) (Request, UserIndex, error)

GetNextRequestForQuerier find next user queue and takes the next request off of it. Will block if there are no requests. By passing user index from previous call of this method, querier guarantees that it iterates over all users fairly. If querier finds that request from the user is already expired, it can get a request for the same user by using UserIndex.ReuseLastUser.

func (*RequestQueue) QuerierDisconnecting

func (q *RequestQueue) QuerierDisconnecting()

When querier is waiting for next request, this unblocks the method.

func (*RequestQueue) RegisterQuerierConnection

func (q *RequestQueue) RegisterQuerierConnection(querier string)

func (*RequestQueue) Stop

func (q *RequestQueue) Stop()

func (*RequestQueue) UnregisterQuerierConnection

func (q *RequestQueue) UnregisterQuerierConnection(querier string)

type UserIndex

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

UserIndex is opaque type that allows to resume iteration over users between successive calls of RequestQueue.GetNextRequestForQuerier method.

func FirstUser

func FirstUser() UserIndex

FirstUser returns UserIndex that starts iteration over user queues from the very first user.

func (UserIndex) ReuseLastUser

func (ui UserIndex) ReuseLastUser() UserIndex

Modify index to start iteration on the same user, for which last queue was returned.

Jump to

Keyboard shortcuts

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