Documentation
¶
Overview ¶
Package storage provides storage management functionality including filesystem space detection, access tracking for events, and garbage collection based on access patterns.
Index ¶
- func CalculateMaxStorage(dataDir string, configuredMax int64) (int64, error)
- func GetCurrentStorageUsage(dataDir string) (int64, error)
- type AccessTracker
- func (t *AccessTracker) ClearConnection(connectionID string)
- func (t *AccessTracker) GetAccessInfo(serial uint64) (lastAccess int64, accessCount uint32, err error)
- func (t *AccessTracker) GetColdestEvents(limit int, minAgeSec int64) ([]uint64, error)
- func (t *AccessTracker) RecordAccess(serial uint64, connectionID string) (bool, error)
- func (t *AccessTracker) Start()
- func (t *AccessTracker) Stats() AccessTrackerStats
- func (t *AccessTracker) Stop()
- type AccessTrackerDatabase
- type AccessTrackerStats
- type FilesystemStats
- type GCConfig
- type GCDatabase
- type GCStats
- type GarbageCollector
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CalculateMaxStorage ¶
CalculateMaxStorage calculates the maximum storage limit for the relay. If configuredMax > 0, it returns that value directly. Otherwise, it returns 80% of the available filesystem space.
Types ¶
type AccessTracker ¶
type AccessTracker struct {
// contains filtered or unexported fields
}
AccessTracker tracks event access patterns with session deduplication. It maintains an in-memory cache to deduplicate accesses from the same connection, reducing database writes while ensuring unique session counting.
func NewAccessTracker ¶
func NewAccessTracker(db AccessTrackerDatabase, maxSeenEntries int) *AccessTracker
NewAccessTracker creates a new access tracker. maxSeenEntries controls the size of the deduplication cache.
func (*AccessTracker) ClearConnection ¶
func (t *AccessTracker) ClearConnection(connectionID string)
ClearConnection removes all dedup entries for a specific connection. Call this when a connection closes to free up cache space.
func (*AccessTracker) GetAccessInfo ¶
func (t *AccessTracker) GetAccessInfo(serial uint64) (lastAccess int64, accessCount uint32, err error)
GetAccessInfo returns the access information for an event.
func (*AccessTracker) GetColdestEvents ¶
func (t *AccessTracker) GetColdestEvents(limit int, minAgeSec int64) ([]uint64, error)
GetColdestEvents returns event serials sorted by coldness. limit: max events to return minAgeSec: minimum age in seconds since last access
func (*AccessTracker) RecordAccess ¶
func (t *AccessTracker) RecordAccess(serial uint64, connectionID string) (bool, error)
RecordAccess records an access to an event by a connection. Deduplicates accesses from the same connection within the cache window. Returns true if this was a new access, false if deduplicated.
func (*AccessTracker) Start ¶
func (t *AccessTracker) Start()
Start starts any background goroutines for the tracker. Currently a no-op but provided for future use.
func (*AccessTracker) Stats ¶
func (t *AccessTracker) Stats() AccessTrackerStats
Stats returns current cache statistics.
func (*AccessTracker) Stop ¶
func (t *AccessTracker) Stop()
Stop stops the access tracker and releases resources.
type AccessTrackerDatabase ¶
type AccessTrackerDatabase interface {
RecordEventAccess(serial uint64, connectionID string) error
GetEventAccessInfo(serial uint64) (lastAccess int64, accessCount uint32, err error)
GetLeastAccessedEvents(limit int, minAgeSec int64) (serials []uint64, err error)
}
AccessTrackerDatabase defines the interface for the underlying database that stores access tracking information.
type AccessTrackerStats ¶
AccessTrackerStats holds access tracker statistics.
type FilesystemStats ¶
type FilesystemStats struct {
Total uint64 // Total bytes on filesystem
Available uint64 // Available bytes (for unprivileged users)
Used uint64 // Used bytes
}
FilesystemStats holds information about filesystem space usage.
func GetFilesystemStats ¶
func GetFilesystemStats(path string) (stats FilesystemStats, err error)
GetFilesystemStats returns filesystem space information for the given path. The path should be a directory within the filesystem to check.
type GCConfig ¶
type GCConfig struct {
MaxStorageBytes int64 // 0 = auto-calculate (80% of filesystem)
Interval time.Duration // How often to check storage
BatchSize int // Events to consider per GC run
MinAgeSec int64 // Minimum age before eviction (default: 1 hour)
}
GCConfig holds configuration for the garbage collector.
type GCDatabase ¶
type GCDatabase interface {
Path() string
FetchEventBySerial(ser *types.Uint40) (ev *event.E, err error)
DeleteEventBySerial(ctx context.Context, ser *types.Uint40, ev *event.E) error
}
GCDatabase defines the interface for database operations needed by the GC.
type GCStats ¶
type GCStats struct {
Running bool
LastRunTime time.Time
TotalEvicted uint64
CurrentStorageBytes int64
MaxStorageBytes int64
StoragePercentage float64
}
GCStats holds garbage collector statistics.
type GarbageCollector ¶
type GarbageCollector struct {
// contains filtered or unexported fields
}
GarbageCollector manages continuous event eviction based on access patterns. It monitors storage usage and evicts the least accessed events when the storage limit is exceeded.
func NewGarbageCollector ¶
func NewGarbageCollector( ctx context.Context, db GCDatabase, tracker *AccessTracker, cfg GCConfig, ) *GarbageCollector
NewGarbageCollector creates a new garbage collector.
func (*GarbageCollector) Start ¶
func (gc *GarbageCollector) Start()
Start begins the garbage collection loop.
func (*GarbageCollector) Stats ¶
func (gc *GarbageCollector) Stats() GCStats
Stats returns current GC statistics.
func (*GarbageCollector) Stop ¶
func (gc *GarbageCollector) Stop()
Stop stops the garbage collector.
Source Files
¶
- access_tracker.go
- gc.go
- limits.go