inmemory

package
v0.11.0 Latest Latest
Warning

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

Go to latest
Published: Sep 16, 2026 License: MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalidArgument           = errors.New("invalid argument")
	ErrInvalidHashTablePartition = errors.New("hash table partition is invalid")
	ErrInvalidWALData            = errors.New("invalid WAL log data")
)
View Source
var HashTableBuilder = func() hashTable {
	return NewHashTable()
}
View Source
var IndexedHashTableBuilder = func() hashTable {
	return NewIndexedHashTable()
}

Functions

This section is empty.

Types

type Engine

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

func NewEngine

func NewEngine(
	tableBuilder func() hashTable,
	partitionsNumber int,
	logger *zerolog.Logger,
	walStream <-chan wal.Chunk,
	dumpStream <-chan database.DumpChunk,
) (*Engine, error)

func NewEngineWithKeyIndex added in v0.6.0

func NewEngineWithKeyIndex(
	tableBuilder func() hashTable,
	partitionsNumber int,
	logger *zerolog.Logger,
	walStream <-chan wal.Chunk,
	dumpStream <-chan database.DumpChunk,
	scanIndexEnabled bool,
) (*Engine, error)

func NewEngineWithWALApplyWorkers added in v0.3.8

func NewEngineWithWALApplyWorkers(
	tableBuilder func() hashTable,
	partitionsNumber int,
	logger *zerolog.Logger,
	walStream <-chan wal.Chunk,
	dumpStream <-chan database.DumpChunk,
	walApplyWorkers int,
) (*Engine, error)

func NewEngineWithWALApplyWorkersAndKeyIndex added in v0.6.0

func NewEngineWithWALApplyWorkersAndKeyIndex(
	tableBuilder func() hashTable,
	partitionsNumber int,
	logger *zerolog.Logger,
	walStream <-chan wal.Chunk,
	dumpStream <-chan database.DumpChunk,
	walApplyWorkers int,
	scanIndexEnabled bool,
) (*Engine, error)

func (*Engine) Clean

func (e *Engine) Clean(ctx context.Context)

func (*Engine) Del

func (e *Engine) Del(txCtx database.TxContext, key database.BatchKey) bool

func (*Engine) FlushDB added in v0.5.0

func (e *Engine) FlushDB()

func (*Engine) Get

func (e *Engine) Get(key database.BatchKey) (database.ValueType, bool)

func (*Engine) Incr

func (e *Engine) Incr(
	txCtx database.TxContext,
	key database.BatchKey,
	beforeApply func() error,
) (database.ValueType, error)

func (*Engine) IncrBy added in v0.11.0

func (e *Engine) IncrBy(
	txCtx database.TxContext,
	key database.BatchKey,
	delta database.ValueType,
	beforeApply func() error,
) (database.ValueType, error)

func (*Engine) MDel

func (e *Engine) MDel(txCtx database.TxContext, keys []database.BatchKey) []bool

func (*Engine) QuotaAcquire added in v0.3.9

func (e *Engine) QuotaAcquire(
	txCtx database.TxContext,
	request database.QuotaAcquireRequest,
	beforeApply func() error,
) (database.QuotaAcquireResult, error)

func (*Engine) QuotaDelete added in v0.3.9

func (e *Engine) QuotaDelete(txCtx database.TxContext, name string, beforeApply func() error) (bool, error)

func (*Engine) QuotaInfo added in v0.3.9

func (e *Engine) QuotaInfo(now database.TxTime, name string) database.QuotaInfo

func (*Engine) QuotaRelease added in v0.3.9

func (e *Engine) QuotaRelease(
	txCtx database.TxContext,
	name, clientID string,
	beforeApply func() error,
) (database.QuotaReleaseResult, error)

func (*Engine) QuotaSet added in v0.3.11

func (e *Engine) QuotaSet(
	txCtx database.TxContext,
	request database.QuotaSetRequest,
	beforeApply func() error,
) (bool, error)

func (*Engine) RLimitFixedWindow

func (e *Engine) RLimitFixedWindow(
	txCtx database.TxContext,
	key database.BatchKey,
	limit database.ValueType,
	beforeApply func() error,
) (database.RateLimitResult, error)

RLimitFixedWindow ...

func (*Engine) RLimitSlidingWindow

func (e *Engine) RLimitSlidingWindow(
	txCtx database.TxContext,
	key database.BatchKey,
	limit database.ValueType,
	beforeApply func() error,
) (database.RateLimitResult, error)

RLimitSlidingWindow ...

func (*Engine) RLimitTokenBucket

func (e *Engine) RLimitTokenBucket(
	txCtx database.TxContext,
	key database.BatchKey,
	capacity database.ValueType,
	refillAmount database.ValueType,
	beforeApply func() error,
) (database.RateLimitResult, error)

RLimitTokenBucket ...

func (*Engine) RestoreDumpElem

func (e *Engine) RestoreDumpElem(_ context.Context, elem database.DumpElem) error

func (*Engine) Scan added in v0.6.0

func (e *Engine) Scan(prefix, cursor string, count uint32) (database.ScanResult, error)

func (*Engine) SetAppliedTx added in v0.10.1

func (e *Engine) SetAppliedTx(tx database.Tx)

func (*Engine) SetLimitEventPublisher added in v0.3.10

func (e *Engine) SetLimitEventPublisher(publisher func(database.LimitEvent))

func (*Engine) SetQuotaEventPublisher added in v0.3.10

func (e *Engine) SetQuotaEventPublisher(publisher func(database.QuotaEvent))

func (*Engine) Snapshot added in v0.10.1

func (e *Engine) Snapshot(ctx context.Context, dumpTx database.Tx) (database.DumpSnapshot, error)

func (*Engine) SnapshotApplied added in v0.10.1

func (e *Engine) SnapshotApplied(ctx context.Context) (database.DumpSnapshot, database.Tx, error)

func (*Engine) Stats added in v0.7.0

func (e *Engine) Stats() database.EngineStats

type FqElem

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

func NewFqElem

func NewFqElem(batchSize uint32) *FqElem

func (*FqElem) DumpValue

func (e *FqElem) DumpValue(dumpTx database.Tx) (database.ValueType, database.TxTime, database.Tx)

func (*FqElem) ExpiredWithDelta added in v0.3.7

func (e *FqElem) ExpiredWithDelta(now database.TxTime) bool

func (*FqElem) Incr

func (e *FqElem) Incr(txCtx database.TxContext, beforeApply func() error) (database.ValueType, error)

func (*FqElem) IncrBy added in v0.11.0

func (e *FqElem) IncrBy(
	txCtx database.TxContext,
	delta database.ValueType,
	beforeApply func() error,
) (database.ValueType, error)

func (*FqElem) RLimitFixedWindow

func (e *FqElem) RLimitFixedWindow(
	txCtx database.TxContext,
	limit database.ValueType,
	beforeApply func() error,
) (database.RateLimitResult, error)

func (*FqElem) Value

func (e *FqElem) Value() database.ValueType

type HashTable

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

func NewHashTable

func NewHashTable() *HashTable

func NewIndexedHashTable added in v0.6.0

func NewIndexedHashTable() *HashTable

func (*HashTable) AddSlidingWindowEvent

func (s *HashTable) AddSlidingWindowEvent(txCtx database.TxContext, key database.BatchKey)

func (*HashTable) AddTokenBucketEvent

func (s *HashTable) AddTokenBucketEvent(
	txCtx database.TxContext,
	key database.BatchKey,
	capacity database.ValueType,
	refillAmount database.ValueType,
)

func (*HashTable) Clean

func (s *HashTable) Clean(ctx context.Context)

func (*HashTable) CompactIndex added in v0.6.0

func (s *HashTable) CompactIndex(ctx context.Context, maxDeletes int, budget time.Duration) bool

func (*HashTable) Del

func (s *HashTable) Del(key database.BatchKey) bool

func (*HashTable) FlushDB added in v0.5.0

func (s *HashTable) FlushDB()

func (*HashTable) Get

func (*HashTable) Incr

func (s *HashTable) Incr(
	txCtx database.TxContext,
	key database.BatchKey,
	beforeApply func() error,
) (database.ValueType, error)

func (*HashTable) IncrBy added in v0.11.0

func (s *HashTable) IncrBy(
	txCtx database.TxContext,
	key database.BatchKey,
	delta database.ValueType,
	beforeApply func() error,
) (database.ValueType, error)

func (*HashTable) QuotaAcquire added in v0.3.9

func (s *HashTable) QuotaAcquire(
	txCtx database.TxContext,
	request database.QuotaAcquireRequest,
	beforeApply func() error,
) (database.QuotaAcquireResult, error)

func (*HashTable) QuotaDelete added in v0.3.9

func (s *HashTable) QuotaDelete(txCtx database.TxContext, name string, beforeApply func() error) (bool, error)

func (*HashTable) QuotaInfo added in v0.3.9

func (s *HashTable) QuotaInfo(now database.TxTime, name string) database.QuotaInfo

func (*HashTable) QuotaRelease added in v0.3.9

func (s *HashTable) QuotaRelease(
	txCtx database.TxContext,
	name, clientID string,
	beforeApply func() error,
) (database.QuotaReleaseResult, error)

func (*HashTable) QuotaSet added in v0.3.11

func (s *HashTable) QuotaSet(
	txCtx database.TxContext,
	request database.QuotaSetRequest,
	beforeApply func() error,
) (bool, error)

func (*HashTable) RLimitFixedWindow

func (s *HashTable) RLimitFixedWindow(
	txCtx database.TxContext,
	key database.BatchKey,
	limit database.ValueType,
	beforeApply func() error,
) (database.RateLimitResult, error)

func (*HashTable) RLimitSlidingWindow

func (s *HashTable) RLimitSlidingWindow(
	txCtx database.TxContext,
	key database.BatchKey,
	limit database.ValueType,
	beforeApply func() error,
) (database.RateLimitResult, error)

func (*HashTable) RLimitTokenBucket

func (s *HashTable) RLimitTokenBucket(
	txCtx database.TxContext,
	key database.BatchKey,
	capacity database.ValueType,
	refillAmount database.ValueType,
	beforeApply func() error,
) (database.RateLimitResult, error)

func (*HashTable) RestoreDumpElem

func (s *HashTable) RestoreDumpElem(elem database.DumpElem)

func (*HashTable) Scan added in v0.6.0

func (s *HashTable) Scan(prefix string, after hashTableKey, count uint32) []database.BatchKey

func (*HashTable) Snapshot added in v0.10.1

func (s *HashTable) Snapshot(ctx context.Context, dumpTx database.Tx) []database.DumpElem

func (*HashTable) Stats added in v0.7.0

func (s *HashTable) Stats() database.PartitionStats

type QuotaElem added in v0.3.9

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

func NewQuotaElem added in v0.3.9

func NewQuotaElem(limit database.ValueType, ownership database.QuotaOwnership) *QuotaElem

func (*QuotaElem) Acquire added in v0.3.9

func (e *QuotaElem) Acquire(
	txCtx database.TxContext,
	request database.QuotaAcquireRequest,
	beforeApply func() error,
) (database.QuotaAcquireResult, error)

func (*QuotaElem) AllocationCount added in v0.7.0

func (e *QuotaElem) AllocationCount() int

func (*QuotaElem) CanDelete added in v0.3.9

func (e *QuotaElem) CanDelete(now database.TxTime) bool

func (*QuotaElem) Clean added in v0.3.9

func (e *QuotaElem) Clean(now database.TxTime) bool

func (*QuotaElem) Clients added in v0.4.0

func (e *QuotaElem) Clients() uint32

func (*QuotaElem) Info added in v0.3.9

func (*QuotaElem) Limit added in v0.3.9

func (e *QuotaElem) Limit() database.ValueType

func (*QuotaElem) Ownership added in v0.3.11

func (e *QuotaElem) Ownership() database.QuotaOwnership

func (*QuotaElem) Policy added in v0.4.0

func (e *QuotaElem) Policy() database.QuotaPolicy

func (*QuotaElem) Release added in v0.3.9

func (e *QuotaElem) Release(
	txCtx database.TxContext,
	clientID string,
	beforeApply func() error,
) (database.QuotaReleaseResult, error)

func (*QuotaElem) RestoreAllocation added in v0.3.9

func (e *QuotaElem) RestoreAllocation(elem database.DumpElem)

func (*QuotaElem) RestoreConfig added in v0.3.11

func (e *QuotaElem) RestoreConfig(elem database.DumpElem)

func (*QuotaElem) SetConfig added in v0.4.0

func (e *QuotaElem) SetConfig(
	txCtx database.TxContext,
	request database.QuotaSetRequest,
	beforeApply func() error,
) (bool, error)

type SlidingWindowElem

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

func NewSlidingWindowElem

func NewSlidingWindowElem(window uint32) *SlidingWindowElem

func (*SlidingWindowElem) AddEvent

func (e *SlidingWindowElem) AddEvent(txCtx database.TxContext)

func (*SlidingWindowElem) AppendDump added in v0.10.1

func (e *SlidingWindowElem) AppendDump(
	dst []database.DumpElem,
	key hashTableKey,
	dumpTx database.Tx,
) []database.DumpElem

func (*SlidingWindowElem) Clean

func (e *SlidingWindowElem) Clean(now database.TxTime) bool

func (*SlidingWindowElem) RLimit

func (e *SlidingWindowElem) RLimit(
	txCtx database.TxContext,
	limit database.ValueType,
	beforeApply func() error,
) (database.RateLimitResult, error)

func (*SlidingWindowElem) RestoreBucket

func (e *SlidingWindowElem) RestoreBucket(elem database.DumpElem)

type TokenBucketElem

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

func NewTokenBucketElem

func NewTokenBucketElem(refillWindow uint32) *TokenBucketElem

func (*TokenBucketElem) AddEvent

func (e *TokenBucketElem) AddEvent(
	txCtx database.TxContext,
	capacity database.ValueType,
	refillAmount database.ValueType,
)

func (*TokenBucketElem) DumpValue

func (*TokenBucketElem) RLimit

func (e *TokenBucketElem) RLimit(
	txCtx database.TxContext,
	capacity database.ValueType,
	refillAmount database.ValueType,
	beforeApply func() error,
) (database.RateLimitResult, error)

func (*TokenBucketElem) Restore

func (e *TokenBucketElem) Restore(elem database.DumpElem)

Jump to

Keyboard shortcuts

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