mysqlqm

package
v1.2.1 Latest Latest
Warning

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

Go to latest
Published: Aug 16, 2018 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Overview

Package mysqlqm defines a MySQL-based quota.Manager implementation.

Index

Constants

View Source
const (
	// DefaultMaxUnsequenced is a suggested value for MaxUnsequencedRows.
	// Note that this is a Global/Write quota suggestion, so it applies across trees.
	DefaultMaxUnsequenced = 500000 // About 2h of non-stop signing at 70QPS.

)

Variables

View Source
var (
	// ErrTooManyUnsequencedRows is returned when tokens are requested but Unsequenced has grown
	// beyond the configured limit.
	ErrTooManyUnsequencedRows = errors.New("too many unsequenced rows")
)

Functions

This section is empty.

Types

type QuotaManager

type QuotaManager struct {
	DB                 *sql.DB
	MaxUnsequencedRows int
	UseSelectCount     bool
}

QuotaManager is a MySQL-based quota.Manager implementation.

It has two working modes: one queries the information schema for the number of Unsequenced rows, the other does a select count(*) on the Unsequenced table. Information schema queries are default, even though they are approximate, as they're constant time (select count(*) on InnoDB based MySQL needs to traverse the index and may take quite a while to complete).

QuotaManager only implements Global/Write quotas, which is based on the number of Unsequenced rows (to be exact, tokens = MaxUnsequencedRows - actualUnsequencedRows). Other quotas are considered infinite.

func (*QuotaManager) GetTokens

func (m *QuotaManager) GetTokens(ctx context.Context, numTokens int, specs []quota.Spec) error

GetTokens implements quota.Manager.GetTokens. It doesn't actually reserve or retrieve tokens, instead it allows access based on the number of rows in the Unsequenced table.

func (*QuotaManager) PeekTokens

func (m *QuotaManager) PeekTokens(ctx context.Context, specs []quota.Spec) (map[quota.Spec]int, error)

PeekTokens implements quota.Manager.PeekTokens. Global/Write tokens reflect the number of rows in the Unsequenced tables, other specs are considered infinite.

func (*QuotaManager) PutTokens

func (m *QuotaManager) PutTokens(ctx context.Context, numTokens int, specs []quota.Spec) error

PutTokens implements quota.Manager.PutTokens. It's a noop for QuotaManager.

func (*QuotaManager) ResetQuota

func (m *QuotaManager) ResetQuota(ctx context.Context, specs []quota.Spec) error

ResetQuota implements quota.Manager.ResetQuota. It's a noop for QuotaManager.

Jump to

Keyboard shortcuts

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