Documentation
¶
Index ¶
- type AcquireResourceParams
- type CreateNumpoolParams
- type DBTX
- type EnqueueWaitingClientParams
- type NotifyAndDequeueFirstWaiterParams
- type NotifyWaitersParams
- type Numpool
- type Queries
- func (q *Queries) AcquireAdvisoryLock(ctx context.Context, lockID int64) error
- func (q *Queries) AcquireResource(ctx context.Context, arg AcquireResourceParams) (int64, error)
- func (q *Queries) CheckNumpoolExists(ctx context.Context, id string) (bool, error)
- func (q *Queries) CheckNumpoolTableExist(ctx context.Context) (bool, error)
- func (q *Queries) CreateNumpool(ctx context.Context, arg CreateNumpoolParams) error
- func (q *Queries) CreateTable(ctx context.Context) error
- func (q *Queries) DeleteNumpool(ctx context.Context, id string) (int64, error)
- func (q *Queries) DropNumpoolTable(ctx context.Context) error
- func (q *Queries) EnqueueWaitingClient(ctx context.Context, arg EnqueueWaitingClientParams) error
- func (q *Queries) GetNumpool(ctx context.Context, id string) (Numpool, error)
- func (q *Queries) GetNumpoolForUpdate(ctx context.Context, id string) (Numpool, error)
- func (q *Queries) ListPools(ctx context.Context, prefix pgtype.Text) ([]string, error)
- func (q *Queries) LockNumpoolTableInShareMode(ctx context.Context) error
- func (q *Queries) NotifyAndDequeueFirstWaiter(ctx context.Context, arg NotifyAndDequeueFirstWaiterParams) error
- func (q *Queries) NotifyWaiters(ctx context.Context, arg NotifyWaitersParams) error
- func (q *Queries) ReleaseResource(ctx context.Context, arg ReleaseResourceParams) (int64, error)
- func (q *Queries) RemoveFromWaitQueue(ctx context.Context, arg RemoveFromWaitQueueParams) error
- func (q *Queries) UpdateNumpoolMetadata(ctx context.Context, arg UpdateNumpoolMetadataParams) error
- func (q *Queries) WithTx(tx pgx.Tx) *Queries
- type ReleaseResourceParams
- type RemoveFromWaitQueueParams
- type UpdateNumpoolMetadataParams
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type AcquireResourceParams ¶
type AcquireResourceParams struct {
ID string
ResourceIndex interface{}
}
type CreateNumpoolParams ¶
type NotifyAndDequeueFirstWaiterParams ¶ added in v0.4.5
type NotifyWaitersParams ¶ added in v0.2.0
type Numpool ¶
type Numpool struct {
// ID is a unique identifier for the numpool.
// It is used to identify the numpool in the database.
ID string
// MaxResourcesCount is the maximum number of resources that can be allocated.
// It is used to limit the number of resources that can be created.
// The value must be between 1 and 64, inclusive.
MaxResourcesCount int32
// ResourceUsageStatus is a bitmask representing the usage of resources.
// Each bit corresponds to a resource, where 1 means the resource is in use and 0 means it is free.
// The length of the bitmask is equal to MaxResourcesCount.
// For example, if MaxResourcesCount is 8, then ResourceUsageStatus can be a value from 0 to 64, where each bit represents the usage of a resource.
ResourceUsageStatus pgtype.Bits
// WaitQueue is a list of client ids waiting for the numpool.
WaitQueue []string
// Metadata is a JSONB field that can store additional information about the numpool.
// It can be used to store any additional data that is relevant to the numpool, such as
// configuration settings, descriptions, or other metadata that does not fit into the other fields.
Metadata []byte
}
Numpool represents an abstract pool of resources.
func (*Numpool) FindUnusedResourceIndex ¶
FindUnusedResourceIndex finds the first unused resource index by examining the resource usage bitmap. Returns the index of the first free resource, or -1 if no resources are available.
type Queries ¶
type Queries struct {
// contains filtered or unexported fields
}
func (*Queries) AcquireAdvisoryLock ¶ added in v0.2.0
func (*Queries) AcquireResource ¶
AcquireResource attempts to acquire a resource from the numpool. It returns the id of the numpool if successful, or NULL if no resources are available.
func (*Queries) CheckNumpoolExists ¶ added in v0.2.0
CheckNumpoolExists checks if a numpool with the given id exists.
func (*Queries) CheckNumpoolTableExist ¶ added in v0.2.0
CheckNumpoolTableExist checks if "public"."numpool" exists.
func (*Queries) CreateNumpool ¶
func (q *Queries) CreateNumpool(ctx context.Context, arg CreateNumpoolParams) error
CreateNumpool creates a new numpool with the specified id and max_resources_count.
func (*Queries) CreateTable ¶ added in v0.2.0
CreateTable creates the numpool table in the database.
func (*Queries) DeleteNumpool ¶
DeleteNumpool deletes the numpool with the specified id.
func (*Queries) DropNumpoolTable ¶ added in v0.4.1
DropNumpoolTable drops the numpool table if it exists.
func (*Queries) EnqueueWaitingClient ¶
func (q *Queries) EnqueueWaitingClient(ctx context.Context, arg EnqueueWaitingClientParams) error
EnqueueWaitingClient adds a waiter ID to the wait queue.
func (*Queries) GetNumpool ¶
GetNumpoolForUpdate retrieves the numpool row with the given id without locking it.
func (*Queries) GetNumpoolForUpdate ¶
GetNumpoolForUpdate retrieves the numpool row with the given id and locks it for update.
func (*Queries) ListPools ¶ added in v0.4.4
ListPools returns a list of pool names that start with the given prefix. If prefix is empty, returns all pools ordered by pool name.
func (*Queries) LockNumpoolTableInShareMode ¶ added in v0.2.0
func (*Queries) NotifyAndDequeueFirstWaiter ¶ added in v0.4.5
func (q *Queries) NotifyAndDequeueFirstWaiter(ctx context.Context, arg NotifyAndDequeueFirstWaiterParams) error
NotifyAndDequeueFirstWaiter atomically dequeues the first waiter and notifies them. This prevents the race condition where multiple releases notify the same waiter.
func (*Queries) NotifyWaiters ¶ added in v0.2.0
func (q *Queries) NotifyWaiters(ctx context.Context, arg NotifyWaitersParams) error
func (*Queries) ReleaseResource ¶
ReleaseResource releases a resource back to the numpool.
func (*Queries) RemoveFromWaitQueue ¶
func (q *Queries) RemoveFromWaitQueue(ctx context.Context, arg RemoveFromWaitQueueParams) error
RemoveFromWaitQueue removes a specific waiter UUID from the wait queue.
func (*Queries) UpdateNumpoolMetadata ¶ added in v0.2.0
func (q *Queries) UpdateNumpoolMetadata(ctx context.Context, arg UpdateNumpoolMetadataParams) error
UpdateNumpoolMetadata updates the metadata of the numpool with the specified id.
type ReleaseResourceParams ¶
type ReleaseResourceParams struct {
ID string
ResourceIndex interface{}
}
type RemoveFromWaitQueueParams ¶
type RemoveFromWaitQueueParams struct {
ID string
WaiterID interface{}
}