Documentation
¶
Index ¶
- Variables
- func WatchStorageNoop(dataStore Database)
- func WatchWithCallback(dataStore Database, callback func(Event))
- type Adapter
- func (a *Adapter) Active() bool
- func (a *Adapter) Clear()
- func (a *Adapter) Close()
- func (a *Adapter) Del(key string) error
- func (a *Adapter) DelSilent(key string) error
- func (a *Adapter) Get(key string) (meta.Object, error)
- func (a *Adapter) GetAndLock(key string) (meta.Object, error)
- func (a *Adapter) GetList(path string) ([]meta.Object, error)
- func (a *Adapter) GetListDescending(path string) ([]meta.Object, error)
- func (a *Adapter) GetN(path string, limit int) ([]meta.Object, error)
- func (a *Adapter) GetNAscending(path string, limit int) ([]meta.Object, error)
- func (a *Adapter) GetNRange(path string, limit int, from, to int64) ([]meta.Object, error)
- func (a *Adapter) Keys() ([]string, error)
- func (a *Adapter) KeysRange(path string, from, to int64) ([]string, error)
- func (a *Adapter) Push(path string, data json.RawMessage) (string, error)
- func (a *Adapter) Set(key string, data json.RawMessage) (string, error)
- func (a *Adapter) SetAndUnlock(key string, data json.RawMessage) (string, error)
- func (a *Adapter) SetWithMeta(key string, data json.RawMessage, created, updated int64) (string, error)
- func (a *Adapter) Start(opt Options) error
- func (a *Adapter) Underlying() Database
- func (a *Adapter) Unlock(key string) error
- func (a *Adapter) WatchSharded() *ShardedChan
- type Database
- type EmbeddedLayer
- type EmbeddedWrapper
- func (e *EmbeddedWrapper) Active() bool
- func (e *EmbeddedWrapper) Clear()
- func (e *EmbeddedWrapper) Close()
- func (e *EmbeddedWrapper) Del(key string) error
- func (e *EmbeddedWrapper) Get(key string) (meta.Object, error)
- func (e *EmbeddedWrapper) GetList(path string) ([]meta.Object, error)
- func (e *EmbeddedWrapper) Keys() ([]string, error)
- func (e *EmbeddedWrapper) Load() (map[string]*meta.Object, error)
- func (e *EmbeddedWrapper) Set(key string, obj *meta.Object) error
- func (e *EmbeddedWrapper) Start(opt LayerOptions) error
- type Event
- type EventCallback
- type Layer
- type LayerOptions
- type Layered
- func (l *Layered) Active() bool
- func (l *Layered) Clear()
- func (l *Layered) Close()
- func (l *Layered) Del(path string) error
- func (l *Layered) DelSilent(path string) error
- func (l *Layered) Get(path string) (meta.Object, error)
- func (l *Layered) GetAndLock(path string) (meta.Object, error)
- func (l *Layered) GetList(path string) ([]meta.Object, error)
- func (l *Layered) GetListDescending(path string) ([]meta.Object, error)
- func (l *Layered) GetN(path string, limit int) ([]meta.Object, error)
- func (l *Layered) GetNAscending(path string, limit int) ([]meta.Object, error)
- func (l *Layered) GetNRange(path string, limit int, from, to int64) ([]meta.Object, error)
- func (l *Layered) Keys() ([]string, error)
- func (l *Layered) KeysRange(path string, from, to int64) ([]string, error)
- func (l *Layered) Push(path string, data json.RawMessage) (string, error)
- func (l *Layered) Set(path string, data json.RawMessage) (string, error)
- func (l *Layered) SetAndUnlock(path string, data json.RawMessage) (string, error)
- func (l *Layered) SetWithMeta(path string, data json.RawMessage, created, updated int64) (string, error)
- func (l *Layered) Start(opt Options) error
- func (l *Layered) Unlock(path string) error
- func (l *Layered) WatchSharded() *ShardedChan
- type LayeredConfig
- type MemoryLayer
- func (m *MemoryLayer) Active() bool
- func (m *MemoryLayer) Clear()
- func (m *MemoryLayer) Close()
- func (m *MemoryLayer) Del(k string) error
- func (m *MemoryLayer) Get(k string) (meta.Object, error)
- func (m *MemoryLayer) GetList(path string) ([]meta.Object, error)
- func (m *MemoryLayer) Keys() ([]string, error)
- func (m *MemoryLayer) Len() int
- func (m *MemoryLayer) Set(k string, obj *meta.Object) error
- func (m *MemoryLayer) Start(opt LayerOptions) error
- type Options
- type ShardedChan
- type StorageChan
Constants ¶
This section is empty.
Variables ¶
var ( ErrNotFound = errors.New("storage: not found") ErrInvalidPath = errors.New("storage: invalid path") ErrInvalidPattern = errors.New("storage: invalid pattern, glob required") ErrInvalidRange = errors.New("storage: invalid range") ErrInvalidLimit = errors.New("storage: invalid limit") ErrInvalidStorageData = errors.New("storage: invalid data (empty)") ErrGlobNotAllowed = errors.New("storage: glob pattern not allowed for this operation") ErrGlobRequired = errors.New("storage: glob pattern required for this operation") ErrCantLockGlob = errors.New("storage: can't lock a glob pattern path") ErrLockNotFound = errors.New("storage: lock not found, can't unlock") ErrNoop = errors.New("storage: no operation performed") ErrAllLayersNil = errors.New("storage: all storage layers are nil") ErrNotActive = errors.New("storage: storage is not active") )
Errors
Functions ¶
func WatchStorageNoop ¶
func WatchStorageNoop(dataStore Database)
WatchStorageNoop drains all events from a storage's sharded watcher channels. Use this for extra storages that are not directly hooked to a server.
func WatchWithCallback ¶
WatchWithCallback starts goroutines that watch all sharded channels and call the provided callback for each event. Use this for external storages that need to trigger sync on storage events.
Types ¶
type Adapter ¶
type Adapter struct {
// contains filtered or unexported fields
}
Adapter wraps a storage.Database to provide compatibility with ooo.Database interface This allows the new storage package to be used with the existing ooo server
func NewAdapter ¶
NewAdapter creates a new adapter wrapping a storage.Database
func (*Adapter) GetAndLock ¶
GetAndLock retrieves a value and locks the key
func (*Adapter) GetListDescending ¶
GetListDescending retrieves values matching a pattern in descending order
func (*Adapter) GetNAscending ¶
GetNAscending retrieves N values matching a pattern in ascending order
func (*Adapter) SetAndUnlock ¶
SetAndUnlock stores a value and unlocks the key
func (*Adapter) SetWithMeta ¶
func (a *Adapter) SetWithMeta(key string, data json.RawMessage, created, updated int64) (string, error)
SetWithMeta stores a value with metadata
func (*Adapter) Underlying ¶
Underlying returns the underlying database
func (*Adapter) WatchSharded ¶
func (a *Adapter) WatchSharded() *ShardedChan
WatchSharded returns the sharded storage channel
type Database ¶
type Database interface {
Active() bool
Start(Options) error
Close()
Keys() ([]string, error)
KeysRange(path string, from, to int64) ([]string, error)
Get(key string) (meta.Object, error)
GetAndLock(key string) (meta.Object, error)
GetList(path string) ([]meta.Object, error)
GetListDescending(path string) ([]meta.Object, error)
GetN(path string, limit int) ([]meta.Object, error)
GetNAscending(path string, limit int) ([]meta.Object, error)
GetNRange(path string, limit int, from, to int64) ([]meta.Object, error)
Set(key string, data json.RawMessage) (string, error)
Push(path string, data json.RawMessage) (string, error)
SetWithMeta(key string, data json.RawMessage, created, updated int64) (string, error)
SetAndUnlock(key string, data json.RawMessage) (string, error)
Unlock(key string) error
Del(key string) error
DelSilent(key string) error
Clear()
WatchSharded() *ShardedChan
}
Database interface to be implemented by storages This is the full interface that the layered storage implements
type EmbeddedLayer ¶
type EmbeddedLayer interface {
Layer
// Load reads all data from persistent storage (called during initialization)
Load() (map[string]*meta.Object, error)
}
EmbeddedLayer is the interface for embedded storage backends (leveldb, etc.) Implementations should handle their own persistence
type EmbeddedWrapper ¶
type EmbeddedWrapper struct {
// contains filtered or unexported fields
}
EmbeddedWrapper wraps an EmbeddedLayer to provide Layer interface with caching disabled This is used when the embedded layer is the only layer or when caching is handled elsewhere
func NewEmbeddedWrapper ¶
func NewEmbeddedWrapper(backend EmbeddedLayer) *EmbeddedWrapper
NewEmbeddedWrapper creates a wrapper around an embedded layer
func (*EmbeddedWrapper) Active ¶
func (e *EmbeddedWrapper) Active() bool
Active returns whether the layer is active
func (*EmbeddedWrapper) Close ¶
func (e *EmbeddedWrapper) Close()
Close shuts down the embedded layer
func (*EmbeddedWrapper) Get ¶
func (e *EmbeddedWrapper) Get(key string) (meta.Object, error)
Get retrieves a single value by exact key
func (*EmbeddedWrapper) GetList ¶
func (e *EmbeddedWrapper) GetList(path string) ([]meta.Object, error)
GetList retrieves all values matching a glob pattern
func (*EmbeddedWrapper) Keys ¶
func (e *EmbeddedWrapper) Keys() ([]string, error)
Keys returns all keys
func (*EmbeddedWrapper) Load ¶
func (e *EmbeddedWrapper) Load() (map[string]*meta.Object, error)
Load reads all data from persistent storage
func (*EmbeddedWrapper) Set ¶
func (e *EmbeddedWrapper) Set(key string, obj *meta.Object) error
Set stores a value
func (*EmbeddedWrapper) Start ¶
func (e *EmbeddedWrapper) Start(opt LayerOptions) error
Start initializes the embedded layer
type EventCallback ¶
type EventCallback func(event Event)
EventCallback is a callback type for storage events
type Layer ¶
type Layer interface {
// Active returns whether the layer is active
Active() bool
// Start initializes the layer
Start(opt LayerOptions) error
// Close shuts down the layer
Close()
// Get retrieves a single value by exact key
Get(key string) (meta.Object, error)
// GetList retrieves all values matching a glob pattern
GetList(path string) ([]meta.Object, error)
// Set stores a value
Set(key string, obj *meta.Object) error
// Del deletes a key
Del(key string) error
// Keys returns all keys
Keys() ([]string, error)
// Clear removes all data
Clear()
}
Layer is the interface for individual storage layers (memory, embedded, sql) This is a simpler interface focused on raw storage operations
type LayerOptions ¶
type LayerOptions struct {
// SkipLoadMemory when true, skips loading data from embedded layer into memory on startup
SkipLoadMemory bool
}
LayerOptions configuration for individual storage layers
type Layered ¶
type Layered struct {
// contains filtered or unexported fields
}
Layered is a multi-layer storage that coordinates between memory and embedded layers
func (*Layered) Get ¶
Get retrieves a single value by exact key Checks layers from fastest to slowest, populates faster layers on cache miss
func (*Layered) GetAndLock ¶
GetAndLock retrieves a single value and locks the key mutex
func (*Layered) GetList ¶
GetList retrieves list of values matching a glob pattern (ascending order)
func (*Layered) GetListDescending ¶
GetListDescending retrieves list of values matching a glob pattern (descending order)
func (*Layered) GetNAscending ¶
GetNAscending get first N elements of a path related value(s)
func (*Layered) SetAndUnlock ¶
SetAndUnlock sets a value and unlocks the key mutex
func (*Layered) SetWithMeta ¶
func (l *Layered) SetWithMeta(path string, data json.RawMessage, created, updated int64) (string, error)
SetWithMeta set entries with metadata created/updated values
func (*Layered) WatchSharded ¶
func (l *Layered) WatchSharded() *ShardedChan
WatchSharded returns the sharded storage channel
type LayeredConfig ¶
type LayeredConfig struct {
// Memory layer (fastest) - optional
Memory *MemoryLayer
// MemoryOptions configuration for memory layer
MemoryOptions LayerOptions
// Embedded layer (medium speed) - optional
Embedded EmbeddedLayer
// EmbeddedOptions configuration for embedded layer
EmbeddedOptions LayerOptions
}
LayeredConfig configuration for the layered storage
type MemoryLayer ¶
type MemoryLayer struct {
// contains filtered or unexported fields
}
MemoryLayer is an in-memory storage layer
func (*MemoryLayer) Active ¶
func (m *MemoryLayer) Active() bool
Active returns whether the layer is active
func (*MemoryLayer) Get ¶
func (m *MemoryLayer) Get(k string) (meta.Object, error)
Get retrieves a single value by exact key
func (*MemoryLayer) GetList ¶
func (m *MemoryLayer) GetList(path string) ([]meta.Object, error)
GetList retrieves all values matching a glob pattern
func (*MemoryLayer) Len ¶
func (m *MemoryLayer) Len() int
Len returns the number of entries (for testing)
func (*MemoryLayer) Set ¶
func (m *MemoryLayer) Set(k string, obj *meta.Object) error
Set stores a value
func (*MemoryLayer) Start ¶
func (m *MemoryLayer) Start(opt LayerOptions) error
Start initializes the memory layer
type Options ¶
type Options struct {
NoBroadcastKeys []string
BeforeRead func(key string)
AfterWrite func(key string)
Workers int
}
Options for the storage instance
type ShardedChan ¶
type ShardedChan struct {
// contains filtered or unexported fields
}
ShardedChan manages multiple channels for per-key ordering.
func NewShardedChan ¶
func NewShardedChan(shardCount int) *ShardedChan
NewShardedChan creates a new sharded storage channel with the given number of shards.
func (*ShardedChan) Send ¶
func (s *ShardedChan) Send(event Event)
Send routes an event to the appropriate shard based on key hash.
func (*ShardedChan) Shard ¶
func (s *ShardedChan) Shard(index int) StorageChan
Shard returns the channel for a specific shard index.
func (*ShardedChan) ShardFor ¶
func (s *ShardedChan) ShardFor(key string) int
ShardFor returns the shard index for a given key using FNV-1a hash.