chunkstore

package
v1.3.0 Latest Latest
Warning

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

Go to latest
Published: Jan 21, 2026 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

internal/chunkstore/store.go

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ChunkInfo

type ChunkInfo = format.ChunkInfo

ChunkInfo is an alias for format.ChunkInfo for convenience

type Stats

type Stats struct {
	TotalChunks   uint64 // Total chunks processed
	UniqueChunks  uint64 // Unique chunks stored
	DedupedChunks uint64 // Chunks that were deduplicated
	BytesSaved    uint64 // Bytes saved through deduplication
	Evictions     uint64 // Chunks evicted from store due to capacity limit
}

Stats contains deduplication statistics

func (Stats) DedupRatio

func (s Stats) DedupRatio() float64

DedupRatio returns the deduplication ratio as a percentage

type Store

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

Store maintains a thread-safe map of chunks for deduplication with bounded capacity

func NewStore

func NewStore() *Store

NewStore creates a new chunk store with unlimited capacity

func NewStoreWithCapacity

func NewStoreWithCapacity(maxChunks int) *Store

NewStoreWithCapacity creates a chunk store with a maximum capacity maxChunks: maximum number of chunks to keep (0 = unlimited)

func (*Store) All

func (s *Store) All() map[[32]byte]ChunkInfo

All returns all chunks ever seen (including evicted ones) This is critical: evicted chunks are removed from s.chunks but their metadata (hash, offset, sizes) must be preserved for the archive index

func (*Store) Count

func (s *Store) Count() int

Count returns the number of unique chunks

func (*Store) Get

func (s *Store) Get(hash [32]byte) (ChunkInfo, bool)

Get retrieves chunk info by hash (read-only)

func (*Store) GetOrAdd

func (s *Store) GetOrAdd(hash [32]byte, origSize uint64, writeFunc func() (offset uint64, comprSize uint64, err error)) (ChunkInfo, bool, error)

GetOrAdd checks if a chunk exists, and if not, calls writeFunc to store it Returns (ChunkInfo, isNew, error) If isNew=false, the chunk was deduplicated

func (*Store) Stats

func (s *Store) Stats() Stats

Stats returns deduplication statistics

Jump to

Keyboard shortcuts

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