chunks

package
v0.0.0-...-8b91daf Latest Latest
Warning

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

Go to latest
Published: Apr 19, 2025 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ClearCache

func ClearCache()

func PrintCacheStats

func PrintCacheStats()

Types

type CacheStats

type CacheStats struct {
	Hits   atomic.Int64
	Misses atomic.Int64
	// contains filtered or unexported fields
}

func (*CacheStats) Hit

func (c *CacheStats) Hit()

func (*CacheStats) Miss

func (c *CacheStats) Miss()

func (*CacheStats) Reset

func (c *CacheStats) Reset()

func (*CacheStats) String

func (c *CacheStats) String() string

type Chunk

type Chunk struct {
	Header Header
	Data   ChunkData
}

This reprsents a chunk of data that would be stored on disk

func NewChunk

func NewChunk(timestamp time.Time) *Chunk

func (Chunk) EstimateSize

func (c Chunk) EstimateSize() (int64, error)

func (*Chunk) Finish

func (c *Chunk) Finish(keyFrame KeyFrame, events []Event)

func (Chunk) GetStateAt

func (c Chunk) GetStateAt(timestamp time.Time) (map[string][]byte, error)

func (Chunk) Save

func (c Chunk) Save(ctx context.Context, s storage.System) error

Saves a header to the storage system

type ChunkData

type ChunkData struct {
	Id              ChunkId
	Timestamp       time.Time
	Keys            []string
	IndexedKeyFrame IndexedKeyFrame
	Diffs           []DiffEvent
	// contains filtered or unexported fields
}

This is what is actually stored on disk

func (ChunkData) GetDiskSize

func (c ChunkData) GetDiskSize() int

func (ChunkData) RawSize

func (c ChunkData) RawSize() int

type ChunkId

type ChunkId string

A chunk Id is in the form YYYY/MM/DD/YYYYMMDD_HHMMSS.sssssssss $ChunkId.data would be the key in a storage system to locate a chunks data $ChunkId.header would be the key in a storage system to locate a chunks meta data

func NewChunkId

func NewChunkId(t time.Time) ChunkId

func (ChunkId) ChunkKey

func (c ChunkId) ChunkKey() string

func (ChunkId) HeaderKey

func (c ChunkId) HeaderKey() string

type Diff

type Diff []byte

type DiffEvent

type DiffEvent struct {
	Timestamp time.Time
	KeyIndex  int32
	Diff      Diff
}

type Event

type Event struct {
	Timestamp time.Time
	Key       string
	Data      []byte
	Delete    bool
}

func (Event) Apply

func (e Event) Apply(ret map[string][]byte)
type Header struct {
	LastUpdate time.Time
	Id         ChunkId
	Prev       ChunkId
	Next       ChunkId
	Min        time.Time
	Max        time.Time
}

This reprsents a chunk of data that would be stored on disk It is small so it can quickly be overwritten.

func LoadHeader

func LoadHeader(ctx context.Context, s storage.System, id ChunkId) (Header, error)

Loads a header from the storage system

func (Header) LoadChunk

func (h Header) LoadChunk(ctx context.Context, s storage.System) (Chunk, error)

Loads the chunk associated with this header

func (Header) RemoveFromStorage

func (h Header) RemoveFromStorage(ctx context.Context, s storage.System) error

func (Header) ResponsibleFor

func (h Header) ResponsibleFor(timestamp time.Time) bool

func (Header) Save

func (h Header) Save(ctx context.Context, s storage.System) error

Saves a header to the storage system

type Index

type Index interface {
	UpdateIndex(header Header) error

	GetStateAt(timestamp time.Time) (map[string][]byte, error)
	GetMinTime() time.Time
	GetMaxTime() time.Time
	GetHeaders() []Header
	// contains filtered or unexported methods
}

func NewChunkIndex

func NewChunkIndex(s storage.System, maxChunkAge time.Duration, logger telemetry.Logger, metrics telemetry.Metrics) (Index, error)

type IndexedKVPair

type IndexedKVPair struct {
	KeyIndex int32
	Data     []byte
}

type IndexedKeyFrame

type IndexedKeyFrame []IndexedKVPair

func NewIndexedKeyFrame

func NewIndexedKeyFrame(keyFrame KeyFrame, keyIndex map[string]int32) IndexedKeyFrame

type KVPair

type KVPair struct {
	Key  string
	Data []byte
}

type KeyFrame

type KeyFrame []KVPair

A sorted array of KVPairs

func NewKeyFrame

func NewKeyFrame(state map[string][]byte) KeyFrame

Jump to

Keyboard shortcuts

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