Documentation ¶
Overview ¶
Package content implements repository support content-addressable storage contents.
Index ¶
- Constants
- Variables
- func CreateHashAndEncryptor(f *FormattingOptions) (HashFunc, Encryptor, error)
- func RegisterEncryption(name string, newEncryptor EncryptorFactory)
- func RegisterHash(name string, newHashFunc HashFuncFactory)
- func SupportedEncryptionAlgorithms() []string
- func SupportedHashAlgorithms() []string
- func UsingContentCache(ctx context.Context, enabled bool) context.Context
- func UsingListCache(ctx context.Context, enabled bool) context.Context
- type CachingOptions
- type CompactOptions
- type Encryptor
- type EncryptorFactory
- type Format
- type FormattingOptions
- type HashFunc
- type HashFuncFactory
- type ID
- type IndexBlobInfo
- type Info
- type Manager
- func (bm *Manager) Close()
- func (bm *Manager) CompactIndexes(ctx context.Context, opt CompactOptions) error
- func (bm *Manager) ContentInfo(ctx context.Context, contentID ID) (Info, error)
- func (bm *Manager) DeleteContent(contentID ID) error
- func (bm *Manager) DisableIndexFlush()
- func (bm *Manager) EnableIndexFlush()
- func (bm *Manager) FindUnreferencedBlobs(ctx context.Context) ([]blob.Metadata, error)
- func (bm *Manager) Flush(ctx context.Context) error
- func (bm *Manager) GetContent(ctx context.Context, contentID ID) ([]byte, error)
- func (bm *Manager) IndexBlobs(ctx context.Context) ([]IndexBlobInfo, error)
- func (bm *Manager) ListContentInfos(prefix ID, includeDeleted bool) ([]Info, error)
- func (bm *Manager) ListContents(prefix ID) ([]ID, 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) ResetStats()
- func (bm *Manager) RewriteContent(ctx context.Context, contentID ID) error
- func (bm *Manager) Stats() Stats
- func (bm *Manager) WriteContent(ctx context.Context, data []byte, prefix ID) (ID, error)
- type Stats
Constants ¶
const DefaultEncryption = "SALSA20-HMAC"
DefaultEncryption is the name of the default encryption algorithm.
const DefaultHash = "BLAKE2B-256-128"
DefaultHash is the name of the default hash algorithm.
const PackBlobIDPrefix = "p"
PackBlobIDPrefix is the prefix for all pack blobs.
Variables ¶
var ErrContentNotFound = errors.New("content not found")
ErrContentNotFound is returned when content is not found.
Functions ¶
func CreateHashAndEncryptor ¶
func CreateHashAndEncryptor(f *FormattingOptions) (HashFunc, Encryptor, error)
func RegisterEncryption ¶
func RegisterEncryption(name string, newEncryptor EncryptorFactory)
RegisterEncryption registers new encryption algorithm.
func RegisterHash ¶
func RegisterHash(name string, newHashFunc HashFuncFactory)
RegisterHash registers a hash function with a given name.
func SupportedEncryptionAlgorithms ¶
func SupportedEncryptionAlgorithms() []string
func SupportedHashAlgorithms ¶
func SupportedHashAlgorithms() []string
func UsingContentCache ¶
UsingContentCache returns a derived context that causes content manager to use cache.
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"` IgnoreListCache bool `json:"-"` HMACSecret []byte `json:"-"` }
CachingOptions specifies configuration of local cache.
type CompactOptions ¶
type CompactOptions struct { MinSmallBlobs int MaxSmallBlobs int AllIndexes bool SkipDeletedOlderThan time.Duration }
CompactOptions provides options for compaction
type Encryptor ¶
type Encryptor interface { // Encrypt returns encrypted bytes corresponding to the given plaintext. // Must not clobber the input slice and return ciphertext with additional padding and checksum. Encrypt(plainText, contentID []byte) ([]byte, error) // Decrypt returns unencrypted bytes corresponding to the given ciphertext. // Must not clobber the input slice. If IsAuthenticated() == true, Decrypt will perform // authenticity check before decrypting. Decrypt(cipherText, contentID []byte) ([]byte, error) // IsAuthenticated returns true if encryption is authenticated. // In this case Decrypt() is expected to perform authenticity check. IsAuthenticated() bool }
Encryptor performs encryption and decryption of contents of data.
type EncryptorFactory ¶
type EncryptorFactory func(o *FormattingOptions) (Encryptor, error)
EncryptorFactory creates new Encryptor for given FormattingOptions
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.
type HashFunc ¶
HashFunc computes hash of content of data using a cryptographic hash function, possibly with HMAC and/or truncation.
type HashFuncFactory ¶
type HashFuncFactory func(o *FormattingOptions) (HashFunc, error)
HashFuncFactory returns a hash function for given formatting options.
type ID ¶
type ID string
ID is an identifier of content in content-addressable storage.
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"` Payload []byte `json:"payload"` // set for payloads stored inline FormatVersion byte `json:"formatVersion"` }
Info is an information about a single piece of content managed by Manager.
type Manager ¶
type Manager struct { Format FormattingOptions // 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, repositoryFormatBytes []byte) (*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 contents is between minSmallContentCount and maxSmallContentCount
func (*Manager) ContentInfo ¶
ContentInfo returns information about a single content.
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 ¶
func (bm *Manager) DisableIndexFlush()
DisableIndexFlush increments the counter preventing automatic index flushes.
func (*Manager) EnableIndexFlush ¶
func (bm *Manager) EnableIndexFlush()
EnableIndexFlush decrements the counter preventing automatic index flushes. The flushes will be reenabled when the index drops to zero.
func (*Manager) FindUnreferencedBlobs ¶
FindUnreferencedBlobs returns the list of unreferenced storage contents.
func (*Manager) Flush ¶
Flush completes writing any pending packs and writes pack indexes to the underlyign storage.
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) ([]IndexBlobInfo, error)
IndexBlobs returns the list of active index blobs.
func (*Manager) ListContentInfos ¶
ListContentInfos returns the metadata about contents with a given prefix and kind.
func (*Manager) ListContents ¶
ListContents returns IDs of contents matching given prefix.
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) ResetStats ¶
func (bm *Manager) ResetStats()
ResetStats resets statistics to zero values.
func (*Manager) RewriteContent ¶
RewriteContent causes reads and re-writes a given content using the most recent format.
type Stats ¶
type Stats struct { // Keep int64 fields first to ensure they get aligned to at least 64-bit boundaries // which is required for atomic access on ARM and x86-32. ReadBytes int64 `json:"readBytes,omitempty"` WrittenBytes int64 `json:"writtenBytes,omitempty"` DecryptedBytes int64 `json:"decryptedBytes,omitempty"` EncryptedBytes int64 `json:"encryptedBytes,omitempty"` HashedBytes int64 `json:"hashedBytes,omitempty"` ReadContents int32 `json:"readContents,omitempty"` WrittenContents int32 `json:"writtenContents,omitempty"` CheckedContents int32 `json:"checkedContents,omitempty"` HashedContents int32 `json:"hashedContents,omitempty"` InvalidContents int32 `json:"invalidContents,omitempty"` PresentContents int32 `json:"presentContents,omitempty"` ValidContents int32 `json:"validContents,omitempty"` }
Stats exposes statistics about content operation.
Source Files ¶
- block_manager_compaction.go
- builder.go
- cache_hmac.go
- caching_options.go
- committed_content_index.go
- committed_content_index_disk_cache.go
- committed_content_index_mem_cache.go
- content_cache.go
- content_formatter.go
- content_formatting_options.go
- content_id_to_bytes.go
- content_index_recovery.go
- content_manager.go
- context.go
- format.go
- index.go
- info.go
- list_cache.go
- merged.go
- stats.go