Documentation
¶
Index ¶
- Constants
- func GetDBName() string
- func InitFilestore() error
- func MakeDB(ctx context.Context) (*sqlx.DB, error)
- func TerminalFileEpoch(meta wshrpc.FileMeta) int64
- func TerminalStateLock(zoneId string) *sync.Mutex
- func WithTx(ctx context.Context, fn func(tx *TxWrap) error) error
- func WithTxRtn[RT any](ctx context.Context, fn func(tx *TxWrap) (RT, error)) (RT, error)
- type CacheEntry
- type DataCacheEntry
- type FileData
- type FileStore
- func (s *FileStore) AppendData(ctx context.Context, zoneId string, name string, data []byte) error
- func (s *FileStore) AppendDataWithOffset(ctx context.Context, zoneId string, name string, data []byte) (int64, error)
- func (s *FileStore) AppendDataWithOffsetAndEpoch(ctx context.Context, zoneId string, name string, data []byte) (int64, int64, error)
- func (s *FileStore) AppendIJson(ctx context.Context, zoneId string, name string, command map[string]any) error
- func (s *FileStore) CompactIJson(ctx context.Context, zoneId string, name string) error
- func (s *FileStore) DeleteFile(ctx context.Context, zoneId string, name string) error
- func (s *FileStore) DeleteZone(ctx context.Context, zoneId string) error
- func (s *FileStore) FlushCache(ctx context.Context) (stats FlushStats, rtnErr error)
- func (s *FileStore) GetAllZoneIds(ctx context.Context) ([]string, error)
- func (s *FileStore) ListFiles(ctx context.Context, zoneId string) ([]*WaveFile, error)
- func (s *FileStore) MakeFile(ctx context.Context, zoneId string, name string, meta wshrpc.FileMeta, ...) error
- func (s *FileStore) ReadAt(ctx context.Context, zoneId string, name string, offset int64, size int64) (rtnOffset int64, rtnData []byte, rtnErr error)
- func (s *FileStore) ReadFile(ctx context.Context, zoneId string, name string) (rtnOffset int64, rtnData []byte, rtnErr error)
- func (s *FileStore) Stat(ctx context.Context, zoneId string, name string) (*WaveFile, error)
- func (s *FileStore) TruncateWithEpoch(ctx context.Context, zoneId string, name string, ...) (int64, error)
- func (s *FileStore) WriteAt(ctx context.Context, zoneId string, name string, offset int64, data []byte) error
- func (s *FileStore) WriteFile(ctx context.Context, zoneId string, name string, data []byte) error
- func (s *FileStore) WriteMeta(ctx context.Context, zoneId string, name string, meta wshrpc.FileMeta, ...) error
- type FlushStats
- type TxWrap
- type WaveFile
Constants ¶
const ( // ijson meta keys IJsonNumCommands = "ijson:numcmds" IJsonIncrementalBytes = "ijson:incbytes" )
const ( IJsonHighCommands = 100 IJsonHighRatio = 3 IJsonLowRatio = 1 IJsonLowCommands = 10 )
const DefaultFlushTime = 5 * time.Second
const DefaultPartDataSize = 64 * 1024
const FilestoreDBName = "filestore.db"
const NoPartIdx = -1
Variables ¶
This section is empty.
Functions ¶
func InitFilestore ¶
func InitFilestore() error
func TerminalFileEpoch ¶ added in v0.4.91
func TerminalStateLock ¶ added in v0.4.91
Types ¶
type CacheEntry ¶
type CacheEntry struct {
PinCount int // this is synchronzed with the FileStore lock (not the entry lock)
Lock *sync.Mutex
ZoneId string
Name string
File *WaveFile
DataEntries map[int]*DataCacheEntry
FlushErrors int
}
if File or DataEntries are not nil then they are dirty (need to be flushed to disk)
type DataCacheEntry ¶
type FileData ¶
type FileStore ¶
type FileStore struct {
Lock *sync.Mutex
Cache map[cacheKey]*CacheEntry
IsFlushing bool
}
func (*FileStore) AppendData ¶
func (*FileStore) AppendDataWithOffset ¶ added in v0.4.91
func (*FileStore) AppendDataWithOffsetAndEpoch ¶ added in v0.5.0
func (s *FileStore) AppendDataWithOffsetAndEpoch(ctx context.Context, zoneId string, name string, data []byte) (int64, int64, error)
The epoch (TerminalFileEpoch of the file meta) is read under the same lock as the offset, so a concurrent TruncateWithEpoch either happens entirely before this append (new epoch, offset 0..) or entirely after it (old epoch), and readers can drop appends whose epoch is stale.
func (*FileStore) AppendIJson ¶
func (*FileStore) CompactIJson ¶
func (*FileStore) DeleteFile ¶
func (*FileStore) DeleteZone ¶
func (*FileStore) FlushCache ¶
func (s *FileStore) FlushCache(ctx context.Context) (stats FlushStats, rtnErr error)
func (*FileStore) GetAllZoneIds ¶
func (*FileStore) MakeFile ¶
func (s *FileStore) MakeFile(ctx context.Context, zoneId string, name string, meta wshrpc.FileMeta, opts wshrpc.FileOpts) error
synchronous (does not interact with the cache)
func (*FileStore) ReadAt ¶
func (s *FileStore) ReadAt(ctx context.Context, zoneId string, name string, offset int64, size int64) (rtnOffset int64, rtnData []byte, rtnErr error)
returns (offset, data, error) we return the offset because the offset may have been adjusted if the size was too big (for circular files)
func (*FileStore) ReadFile ¶
func (s *FileStore) ReadFile(ctx context.Context, zoneId string, name string) (rtnOffset int64, rtnData []byte, rtnErr error)
returns (offset, data, error)
func (*FileStore) TruncateWithEpoch ¶ added in v0.5.0
func (s *FileStore) TruncateWithEpoch(ctx context.Context, zoneId string, name string, afterTruncateFn func(newEpoch int64)) (int64, error)
Bumps the file's "fileepoch" meta and truncates it to zero length under a single lock (two separate calls would let an append land between them, tagged with the new epoch but at a pre-truncate offset). afterTruncateFn (optional) runs while the lock is still held, so anything it publishes is ordered before every append that observes the new epoch. Returns the new epoch.
type FlushStats ¶
type WaveFile ¶
type WaveFile struct {
// these fields are static (not updated)
ZoneId string `json:"zoneid"`
Name string `json:"name"`
Opts wshrpc.FileOpts `json:"opts"`
CreatedTs int64 `json:"createdts"`
// these fields are mutable
Size int64 `json:"size"`
ModTs int64 `json:"modts"`
Meta wshrpc.FileMeta `json:"meta"` // only top-level keys can be updated (lower levels are immutable)
}
func (WaveFile) DataLength ¶
for regular files this is just Size for circular files this is min(Size, MaxSize)
func (WaveFile) DataStartIdx ¶
for regular files this is just 0 for circular files this is the index of the first byte of data we have