contentcache

package
v1.0.13 Latest Latest
Warning

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

Go to latest
Published: Mar 20, 2024 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Overview

Package contentcache stores GCS object contents locally. Note: The content cache is not concurrent safe and callers should ensure thread safety

Index

Constants

View Source
const CacheFilePrefix = "gcsfusecache"

Variables

This section is empty.

Functions

This section is empty.

Types

type CacheFileObjectMetadata

type CacheFileObjectMetadata struct {
	CacheFileNameOnDisk string
	BucketName          string
	ObjectName          string
	Generation          int64
	MetaGeneration      int64
}

Metadata store struct

type CacheObject

type CacheObject struct {
	MetadataFileName        string
	CacheFileObjectMetadata *CacheFileObjectMetadata
	CacheFile               gcsx.TempFile
}

CacheObject is a wrapper struct for a cache file and its associated metadata

func (*CacheObject) Destroy

func (c *CacheObject) Destroy()

Destroy performs disk clean up of cache files and metadata files

func (*CacheObject) ValidateGeneration

func (c *CacheObject) ValidateGeneration(generation int64, metaGeneration int64) bool

ValidateGeneration compares fresh gcs object generation and metageneration numbers against cached objects

type CacheObjectKey

type CacheObjectKey struct {
	BucketName string
	ObjectName string
}

CacheObjectKey uniquely identifies GCS objects by bucket name and object name

type ContentCache

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

ContentCache is a directory on local disk to store the object content ContentCache is thread-safe fileMap is an in memory map to represent cache contents on disk

func New

func New(tempDir string, mtimeClock timeutil.Clock) *ContentCache

New creates a ContentCache.

func (*ContentCache) AddOrReplace

func (c *ContentCache) AddOrReplace(cacheObjectKey *CacheObjectKey, generation int64, metaGeneration int64, rc io.ReadCloser) (*CacheObject, error)

AddOrReplace creates a new cache file or updates an existing cache file AddOrReplace is thread-safe

func (*ContentCache) Get

func (c *ContentCache) Get(cacheObjectKey *CacheObjectKey) (*CacheObject, bool)

Get retrieves a file from the cache given the GCS object name and bucket name Get is thread-safe

func (*ContentCache) NewCacheFile

func (c *ContentCache) NewCacheFile(rc io.ReadCloser, f *os.File) gcsx.TempFile

NewCacheFile returns a cache tempfile wrapper around the source reader and file

func (*ContentCache) NewTempFile

func (c *ContentCache) NewTempFile(rc io.ReadCloser) (gcsx.TempFile, error)

NewTempFile returns a handle for a temporary file on the disk. The caller must call Destroy on the TempFile before releasing it.

func (*ContentCache) RecoverCache

func (c *ContentCache) RecoverCache() error

RecoverCache recovers the cache with existing persisted files when gcsfuse starts RecoverCache should not be called concurrently

func (*ContentCache) Remove

func (c *ContentCache) Remove(cacheObjectKey *CacheObjectKey)

Remove and destroys the specfied cache file and metadata on disk Remove is thread-safe

func (*ContentCache) Size

func (c *ContentCache) Size() int

Size returns the size of the in memory map of cache files

func (*ContentCache) WriteMetadataCheckpointFile

func (c *ContentCache) WriteMetadataCheckpointFile(cacheFileName string, cacheFileObjectMetadata *CacheFileObjectMetadata) (metadataFileName string, err error)

WriteMetadataCheckpointFile writes the metadata struct to a json file so cache files can be recovered on startup

Jump to

Keyboard shortcuts

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