Documentation
¶
Overview ¶
Package tieredwatcher implements tiered file watching with a HOT tier using real-time fsnotify and a COLD tier using periodic polling, reducing file descriptor usage while keeping recently active sessions responsive.
Index ¶
- Constants
- type Config
- type Manager
- func (m *Manager) AddWatcher(adapterID string, tw *TieredWatcher, ch <-chan adapter.Event)
- func (m *Manager) Close() error
- func (m *Manager) Closers() []io.Closer
- func (m *Manager) Events() <-chan adapter.Event
- func (m *Manager) PromoteSession(adapterID, sessionID string)
- func (m *Manager) RegisterSession(adapterID, sessionID, path string)
- func (m *Manager) SetHotTarget(adapterID string, target int)
- func (m *Manager) Stats() (hotCount, coldCount, frozenCount, watchedDirs int)
- func (m *Manager) Touch(adapterID, sessionID string)
- type SessionInfo
- type TieredCloser
- type TieredWatcher
- func (tw *TieredWatcher) Close() error
- func (tw *TieredWatcher) NewCloser() io.Closer
- func (tw *TieredWatcher) PromoteToHot(sessionID string)
- func (tw *TieredWatcher) RegisterSession(id, path string)
- func (tw *TieredWatcher) RegisterSessions(sessions []SessionInfo)
- func (tw *TieredWatcher) SetHotTarget(target int)
- func (tw *TieredWatcher) Stats() (hotCount, coldCount, frozenCount, watchedDirs int)
- func (tw *TieredWatcher) Touch(sessionID string)
Constants ¶
const ( // ColdPollInterval is how often COLD tier sessions are polled for changes. ColdPollInterval = 30 * time.Second // HotInactivityTimeout demotes sessions to COLD after this period without activity. HotInactivityTimeout = 5 * time.Minute // FrozenThreshold is the duration after which unchanged COLD sessions stop being polled. FrozenThreshold = 24 * time.Hour )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Config ¶
type Config struct {
// RootDir is the root directory to watch
RootDir string
// FilePattern is the file extension to watch (e.g., ".jsonl")
FilePattern string
// ExtractID extracts session ID from a file path
ExtractID func(path string) string
// ScanDir scans a directory and returns session info (optional, for COLD tier)
ScanDir func(dir string) ([]SessionInfo, error)
// Filter optionally filters watched paths (overrides FilePattern if set)
Filter func(path string) bool
}
Config holds configuration for creating a TieredWatcher.
type Manager ¶
type Manager struct {
// contains filtered or unexported fields
}
Manager coordinates tiered watching across multiple adapters. It merges events from all adapter watchers into a single channel.
func (*Manager) AddWatcher ¶
func (m *Manager) AddWatcher(adapterID string, tw *TieredWatcher, ch <-chan adapter.Event)
AddWatcher adds a tiered watcher for an adapter and starts forwarding its events.
func (*Manager) PromoteSession ¶
PromoteSession promotes a session to HOT tier for a specific adapter. If adapterID is empty, promotes across all watchers.
func (*Manager) RegisterSession ¶
RegisterSession registers a session with the appropriate watcher.
func (*Manager) SetHotTarget ¶
SetHotTarget sets the desired HOT session count for a specific adapter.
type SessionInfo ¶
type SessionInfo struct {
ID string // Session ID (e.g., filename without extension)
Path string // Full path to session file
ModTime time.Time // Last known modification time
LastHot time.Time // When this session was last in HOT tier or accessed
FileSize int64 // Last known file size
Frozen bool // true = unchanged >24h, skip in pollColdSessions
}
SessionInfo tracks a watched session's path and modification time.
type TieredCloser ¶
type TieredCloser struct {
// contains filtered or unexported fields
}
TieredCloser wraps TieredWatcher to implement io.Closer.
type TieredWatcher ¶
type TieredWatcher struct {
// contains filtered or unexported fields
}
TieredWatcher manages tiered watching for a single adapter's sessions.
func New ¶
func New(cfg Config) (*TieredWatcher, <-chan adapter.Event, error)
New creates a new TieredWatcher.
func (*TieredWatcher) NewCloser ¶
func (tw *TieredWatcher) NewCloser() io.Closer
NewCloser returns an io.Closer for the TieredWatcher.
func (*TieredWatcher) PromoteToHot ¶
func (tw *TieredWatcher) PromoteToHot(sessionID string)
PromoteToHot promotes a session to the HOT tier (e.g., when user selects it).
func (*TieredWatcher) RegisterSession ¶
func (tw *TieredWatcher) RegisterSession(id, path string)
RegisterSession adds a session to tracking (starts in COLD tier).
func (*TieredWatcher) RegisterSessions ¶
func (tw *TieredWatcher) RegisterSessions(sessions []SessionInfo)
RegisterSessions adds multiple sessions to tracking.
func (*TieredWatcher) SetHotTarget ¶
func (tw *TieredWatcher) SetHotTarget(target int)
SetHotTarget sets the desired number of HOT sessions and rebuilds the HOT set.
func (*TieredWatcher) Stats ¶
func (tw *TieredWatcher) Stats() (hotCount, coldCount, frozenCount, watchedDirs int)
Stats returns current watcher statistics.
func (*TieredWatcher) Touch ¶
func (tw *TieredWatcher) Touch(sessionID string)
Touch unfreezes a session so it will be polled again in COLD tier.