store

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: May 13, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const ChunkSize = 8192

ChunkSize is the number of lines per chunk.

View Source
const DefaultDiskCap int64 = 1 << 30

DefaultDiskCap is the maximum disk usage for offloaded chunks (1 GB).

View Source
const OffloadThreshold = 50000

OffloadThreshold is the minimum total line count before offloading begins.

Variables

This section is empty.

Functions

This section is empty.

Types

type ChunkState

type ChunkState int

ChunkState tracks whether a chunk is in memory, on disk, or evicted.

const (
	ChunkHot        ChunkState = iota // in memory
	ChunkOffloading                   // queued for async disk write (still in memory)
	ChunkCold                         // serialized to disk, loadable
	ChunkEvicted                      // disk file deleted, data lost
)

type LineStore

type LineStore struct {
	// contains filtered or unexported fields
}

LineStore manages log line storage with lightweight stubs always in memory. Lines are organized into fixed-size chunks. Each chunk can be independently offloaded to disk and reloaded on demand.

func New

func New() *LineStore

New creates an empty LineStore.

func NewFromSlice

func NewFromSlice(lines []*line.LogLine) *LineStore

NewFromSlice creates a LineStore pre-populated from an existing slice. Used for benchmarks and tests that construct models directly.

func NewWithDiskCap

func NewWithDiskCap(cap int64) *LineStore

NewWithDiskCap creates an empty LineStore with a custom disk cap.

func (*LineStore) Append

func (s *LineStore) Append(l *line.LogLine)

Append adds a new line to the store.

func (*LineStore) ApplyOffloadResults

func (s *LineStore) ApplyOffloadResults()

ApplyOffloadResults drains completion messages from the worker and flips their chunks from Offloading to Cold (or back to Hot on write error). Caller must hold the store's external synchronization (e.g. s.mu in sharedState) because this mutates c.state, c.lines, c.diskPath, diskUsed — fields read by other goroutines under the same lock.

func (*LineStore) ChunkCount

func (s *LineStore) ChunkCount() int

ChunkCount returns the number of chunks.

func (*LineStore) ChunkStateAt

func (s *LineStore) ChunkStateAt(ci int) ChunkState

ChunkStateAt returns the state of chunk ci.

func (*LineStore) Close

func (s *LineStore) Close()

Close releases resources: stops the prefetch goroutine and removes temp files. Safe to call multiple times.

func (*LineStore) DiskUsed

func (s *LineStore) DiskUsed() int64

DiskUsed returns the current disk usage in bytes.

func (*LineStore) Get

func (s *LineStore) Get(i int) *line.LogLine

Get returns the LogLine at index i. If the chunk is cold, it loads it from disk first. If evicted, returns a placeholder.

func (*LineStore) IsHiddenGroupMember

func (s *LineStore) IsHiddenGroupMember(i int) bool

IsHiddenGroupMember returns true if line i is a non-head member of a multiline JSON group. Uses only stub data (no I/O).

func (*LineStore) Len

func (s *LineStore) Len() int

Len returns the total number of lines.

func (*LineStore) PrefetchAdjacent

func (s *LineStore) PrefetchAdjacent(cursor int)

PrefetchAdjacent pre-loads chunks adjacent to the cursor zone. Call after cursor movement to reduce latency when scrolling into cold regions.

func (*LineStore) RequestPrefetch

func (s *LineStore) RequestPrefetch(ci int)

RequestPrefetch asks the background goroutine to load a chunk. Non-blocking: if the prefetch channel is full, the request is dropped.

func (*LineStore) RunOffloadCycle

func (s *LineStore) RunOffloadCycle(cursor, offset, viewportH int)

RunOffloadCycle evaluates which chunks should be offloaded or reloaded based on the current cursor position and viewport. Only runs when the total line count exceeds OffloadThreshold.

Offloads are queued asynchronously — the actual serialize + WriteFile happens on the background worker goroutine (see offloadLoop), so the caller isn't blocked on disk I/O. Completions are applied via ApplyOffloadResults on the next cycle.

func (*LineStore) Search

func (s *LineStore) Search(query string, startIdx int) int

Search finds the next line containing query (case-insensitive) starting from startIdx, wrapping around. For hot chunks, searches in memory. For cold chunks, loads them from disk temporarily. Evicted chunks are skipped.

func (*LineStore) SearchReverse

func (s *LineStore) SearchReverse(query string, startIdx int) int

SearchReverse finds the previous line containing query starting from startIdx.

func (*LineStore) Stub

func (s *LineStore) Stub(i int) line.LineStub

Stub returns the lightweight stub for line i.

func (*LineStore) UpdateStub

func (s *LineStore) UpdateStub(i int)

UpdateStub re-syncs the stub for line i from the actual LogLine data. Call after in-place mutations (e.g., parser multiline JSON detection, expand/collapse).

func (*LineStore) WaitOffloadsForTest

func (s *LineStore) WaitOffloadsForTest()

WaitOffloadsForTest blocks until all queued offloads have been written by the worker, then applies their results. For use in tests that need deterministic "chunk is Cold now" behavior after RunOffloadCycle.

Jump to

Keyboard shortcuts

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