Documentation ¶
Overview ¶
Package content implements repository support for content-addressable storage.
Index ¶
- Constants
- Variables
- func CreateHashAndEncryptor(f *FormattingOptions) (hashing.HashFunc, encryption.Encryptor, error)
- func UsingContentCache(ctx context.Context, enabled bool) context.Context
- func UsingListCache(ctx context.Context, enabled bool) context.Context
- func ValidatePrefix(prefix ID) error
- type CachingOptions
- type CompactOptions
- type Format
- type FormattingOptions
- type ID
- type IDRange
- type IndexBlobInfo
- type Info
- type IterateCallback
- type IterateOptions
- type IteratePackOptions
- type IteratePacksCallback
- type Manager
- func (bm *Manager) Close(ctx context.Context) error
- func (bm *Manager) CompactIndexes(ctx context.Context, opt CompactOptions) error
- func (bm *Manager) ContentInfo(ctx context.Context, contentID ID) (Info, error)
- func (bm *Manager) DecryptBlob(ctx context.Context, blobID blob.ID) ([]byte, error)
- func (bm *Manager) DeleteContent(ctx context.Context, contentID ID) error
- func (bm *Manager) DisableIndexFlush(ctx context.Context)
- func (bm *Manager) EnableIndexFlush(ctx context.Context)
- func (bm *Manager) Flush(ctx context.Context) error
- func (bm *Manager) GetContent(ctx context.Context, contentID ID) (v []byte, err error)
- func (bm *Manager) IndexBlobs(ctx context.Context, includeInactive bool) ([]IndexBlobInfo, error)
- func (bm *Manager) IterateContents(ctx context.Context, opts IterateOptions, callback IterateCallback) error
- func (bm *Manager) IteratePacks(ctx context.Context, options IteratePackOptions, callback IteratePacksCallback) error
- func (bm *Manager) IterateUnreferencedBlobs(ctx context.Context, blobPrefixes []blob.ID, parallellism int, ...) error
- func (bm *Manager) ParseIndexBlob(ctx context.Context, blobID blob.ID) ([]Info, error)
- func (bm *Manager) RecoverIndexFromPackBlob(ctx context.Context, packFile blob.ID, packFileLength int64, commit bool) ([]Info, error)
- func (bm *Manager) Refresh(ctx context.Context) (bool, error)
- func (bm *Manager) RewriteContent(ctx context.Context, contentID ID) error
- func (bm *Manager) SyncMetadataCache(ctx context.Context) error
- func (bm *Manager) UndeleteContent(ctx context.Context, contentID ID) error
- func (bm *Manager) WriteContent(ctx context.Context, data []byte, prefix ID) (ID, error)
- type ManagerOptions
- type PackInfo
- type Stats
- func (s *Stats) DecryptedBytes() int64
- func (s *Stats) EncryptedBytes() int64
- func (s *Stats) HashedContent() (count uint32, bytes int64)
- func (s *Stats) InvalidContents() uint32
- func (s *Stats) ReadContent() (count uint32, bytes int64)
- func (s *Stats) Reset()
- func (s *Stats) ValidContents() uint32
- func (s *Stats) WrittenContent() (count uint32, bytes int64)
Constants ¶
const ( PackBlobIDPrefixRegular blob.ID = "p" PackBlobIDPrefixSpecial blob.ID = "q" FormatLogModule = "kopia/format" )
Prefixes for pack blobs.
Variables ¶
var AllIDs = IDRange{"", maxIDCharacterPlus1}
AllIDs is an IDRange that contains all valid IDs.
var AllNonPrefixedIDs = IDRange{"0", "g"}
AllNonPrefixedIDs is an IDRange that contains all valid IDs non-prefixed IDs ('0' .. 'f').
var AllPrefixedIDs = IDRange{"g", maxIDCharacterPlus1}
AllPrefixedIDs is an IDRange that contains all valid IDs prefixed IDs ('g' .. 'z').
var ErrContentNotFound = errors.New("content not found")
ErrContentNotFound is returned when content is not found.
var PackBlobIDPrefixes = []blob.ID{ PackBlobIDPrefixRegular, PackBlobIDPrefixSpecial, }
PackBlobIDPrefixes contains all possible prefixes for pack blobs.
Functions ¶
func CreateHashAndEncryptor ¶
func CreateHashAndEncryptor(f *FormattingOptions) (hashing.HashFunc, encryption.Encryptor, error)
CreateHashAndEncryptor returns new hashing and encrypting functions based on the specified formatting options.
func UsingContentCache ¶
UsingContentCache returns a derived context that causes content manager to use cache.
func UsingListCache ¶
UsingListCache returns a derived context that causes content manager to use cache.
func ValidatePrefix ¶ added in v0.6.0
ValidatePrefix returns an error if a given prefix is invalid.
Types ¶
type CachingOptions ¶
type CachingOptions struct { CacheDirectory string `json:"cacheDirectory,omitempty"` MaxCacheSizeBytes int64 `json:"maxCacheSize,omitempty"` MaxMetadataCacheSizeBytes int64 `json:"maxMetadataCacheSize,omitempty"` MaxListCacheDurationSec int `json:"maxListCacheDuration,omitempty"` HMACSecret []byte `json:"-"` // contains filtered or unexported fields }
CachingOptions specifies configuration of local cache.
func (*CachingOptions) CloneOrDefault ¶ added in v0.6.0
func (c *CachingOptions) CloneOrDefault() *CachingOptions
CloneOrDefault returns a clone of the caching options or empty options for nil.
type CompactOptions ¶
type CompactOptions struct { MaxSmallBlobs int AllIndexes bool DropDeletedBefore time.Time DropContents []ID }
CompactOptions provides options for compaction.
type Format ¶
type Format struct { Version byte // format version number must be 0x01 KeySize byte // size of each key in bytes EntrySize uint16 // size of each entry in bytes, big-endian EntryCount uint32 // number of sorted (key,value) entries that follow Entries []struct { Key []byte // key bytes (KeySize) Entry entry } ExtraData []byte // extra data }
Format describes a format of a single pack index. The actual structure is not used, it's purely for documentation purposes. The struct is byte-aligned.
type FormattingOptions ¶
type FormattingOptions struct { Version int `json:"version,omitempty"` // version number, must be "1" Hash string `json:"hash,omitempty"` // identifier of the hash algorithm used Encryption string `json:"encryption,omitempty"` // identifier of the encryption algorithm used HMACSecret []byte `json:"secret,omitempty"` // HMAC secret used to generate encryption keys MasterKey []byte `json:"masterKey,omitempty"` // master encryption key (SIV-mode encryption only) MaxPackSize int `json:"maxPackSize,omitempty"` // maximum size of a pack object }
FormattingOptions describes the rules for formatting contents in repository.
func (*FormattingOptions) GetEncryptionAlgorithm ¶ added in v0.5.2
func (f *FormattingOptions) GetEncryptionAlgorithm() string
GetEncryptionAlgorithm implements encryption.Parameters.
func (*FormattingOptions) GetHMACSecret ¶ added in v0.5.2
func (f *FormattingOptions) GetHMACSecret() []byte
GetHMACSecret implements hashing.Parameters.
func (*FormattingOptions) GetHashFunction ¶ added in v0.5.2
func (f *FormattingOptions) GetHashFunction() string
GetHashFunction implements hashing.Parameters.
func (*FormattingOptions) GetMasterKey ¶ added in v0.5.2
func (f *FormattingOptions) GetMasterKey() []byte
GetMasterKey implements encryption.Parameters.
type ID ¶
type ID string
ID is an identifier of content in content-addressable storage.
type IDRange ¶ added in v0.6.0
IDRange represents a range of IDs.
func PrefixRange ¶ added in v0.6.0
PrefixRange returns ID range that contains all IDs with a given prefix.
type IndexBlobInfo ¶
IndexBlobInfo is an information about a single index blob managed by Manager.
type Info ¶
type Info struct { ID ID `json:"contentID"` Length uint32 `json:"length"` TimestampSeconds int64 `json:"time"` PackBlobID blob.ID `json:"packFile,omitempty"` PackOffset uint32 `json:"packOffset,omitempty"` Deleted bool `json:"deleted"` FormatVersion byte `json:"formatVersion"` }
Info is an information about a single piece of content managed by Manager.
type IterateCallback ¶
IterateCallback is the function type used as a callback during content iteration.
type IterateOptions ¶
IterateOptions contains the options used for iterating over content.
type IteratePackOptions ¶
type IteratePackOptions struct { IncludePacksWithOnlyDeletedContent bool IncludeContentInfos bool Prefixes []blob.ID }
IteratePackOptions are the options used to iterate over packs.
type IteratePacksCallback ¶
IteratePacksCallback is the function type used as callback during pack iteration.
type Manager ¶
type Manager struct {
// contains filtered or unexported fields
}
Manager builds content-addressable storage with encryption, deduplication and packaging on top of BLOB store.
func NewManager ¶
func NewManager(ctx context.Context, st blob.Storage, f *FormattingOptions, caching *CachingOptions, options ManagerOptions) (*Manager, error)
NewManager creates new content manager with given packing options and a formatter.
func (*Manager) CompactIndexes ¶
func (bm *Manager) CompactIndexes(ctx context.Context, opt CompactOptions) error
CompactIndexes performs compaction of index blobs ensuring that # of small index blobs is below opt.maxSmallBlobs.
func (*Manager) ContentInfo ¶
ContentInfo returns information about a single content.
func (*Manager) DecryptBlob ¶ added in v0.6.0
DecryptBlob returns the contents of an encrypted blob that can be decrypted (n,m,l).
func (*Manager) DeleteContent ¶
DeleteContent marks the given contentID as deleted.
NOTE: To avoid race conditions only contents that cannot be possibly re-created should ever be deleted. That means that contents of such contents should include some element of randomness or a contemporaneous timestamp that will never reappear.
func (*Manager) DisableIndexFlush ¶
DisableIndexFlush increments the counter preventing automatic index flushes.
func (*Manager) EnableIndexFlush ¶
EnableIndexFlush decrements the counter preventing automatic index flushes. The flushes will be reenabled when the index drops to zero.
func (*Manager) Flush ¶
Flush completes writing any pending packs and writes pack indexes to the underlying storage. Any pending writes completed before Flush() has started are guaranteed to be committed to the repository before Flush() returns.
func (*Manager) GetContent ¶
GetContent gets the contents of a given content. If the content is not found returns ErrContentNotFound.
func (*Manager) IndexBlobs ¶
func (bm *Manager) IndexBlobs(ctx context.Context, includeInactive bool) ([]IndexBlobInfo, error)
IndexBlobs returns the list of active index blobs.
func (*Manager) IterateContents ¶
func (bm *Manager) IterateContents(ctx context.Context, opts IterateOptions, callback IterateCallback) error
IterateContents invokes the provided callback for each content starting with a specified prefix and possibly including deleted items.
func (*Manager) IteratePacks ¶
func (bm *Manager) IteratePacks(ctx context.Context, options IteratePackOptions, callback IteratePacksCallback) error
IteratePacks invokes the provided callback for all pack blobs.
func (*Manager) IterateUnreferencedBlobs ¶
func (bm *Manager) IterateUnreferencedBlobs(ctx context.Context, blobPrefixes []blob.ID, parallellism int, callback func(blob.Metadata) error) error
IterateUnreferencedBlobs returns the list of unreferenced storage blobs.
func (*Manager) ParseIndexBlob ¶ added in v0.7.0
ParseIndexBlob loads entries in a given index blob and returns them.
func (*Manager) RecoverIndexFromPackBlob ¶
func (bm *Manager) RecoverIndexFromPackBlob(ctx context.Context, packFile blob.ID, packFileLength int64, commit bool) ([]Info, error)
RecoverIndexFromPackBlob attempts to recover index blob entries from a given pack file. Pack file length may be provided (if known) to reduce the number of bytes that are read from the storage.
func (*Manager) RewriteContent ¶
RewriteContent causes reads and re-writes a given content using the most recent format.
func (*Manager) SyncMetadataCache ¶ added in v0.6.0
SyncMetadataCache synchronizes metadata cache with metadata blobs in storage.
func (*Manager) UndeleteContent ¶ added in v0.6.0
UndeleteContent rewrites the content with the given ID if the content exists and is mark deleted. If the content exists and is not marked deleted, this operation is a no-op.
type ManagerOptions ¶ added in v0.6.0
type ManagerOptions struct { RepositoryFormatBytes []byte TimeNow func() time.Time // Time provider }
ManagerOptions are the optional parameters for manager creation.
type Stats ¶
type Stats struct {
// contains filtered or unexported fields
}
Stats exposes statistics about content operation.
func (*Stats) DecryptedBytes ¶
DecryptedBytes returns the approximate total number of decrypted bytes.
func (*Stats) EncryptedBytes ¶
EncryptedBytes returns the approximate total number of decrypted bytes.
func (*Stats) HashedContent ¶ added in v0.6.0
HashedContent returns the approximate hashed content count and their total size in bytes.
func (*Stats) InvalidContents ¶
InvalidContents returns the approximate count of invalid contents found.
func (*Stats) ReadContent ¶ added in v0.6.0
ReadContent returns the approximate read content count and their total size in bytes.
func (*Stats) ValidContents ¶
ValidContents returns the approximate count of valid contents found.
func (*Stats) WrittenContent ¶ added in v0.6.0
WrittenContent returns the approximate written content count and their total size in bytes.
Source Files ¶
- builder.go
- caching_options.go
- committed_content_index.go
- committed_content_index_disk_cache.go
- committed_content_index_mem_cache.go
- content_cache.go
- content_cache_base.go
- content_cache_data.go
- content_cache_metadata.go
- content_cache_metrics.go
- content_cache_passthrough.go
- content_formatting_options.go
- content_id_to_bytes.go
- content_index_recovery.go
- content_manager.go
- content_manager_indexes.go
- content_manager_iterate.go
- content_manager_lock_free.go
- content_manager_metrics.go
- content_manager_own_writes.go
- context.go
- format.go
- index.go
- index_blob_manager.go
- info.go
- list_cache.go
- merged.go
- stats.go