file

package
v2.0.8 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CacheHandle

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

func NewCacheHandle

func NewCacheHandle(localFileHandle *os.File, fileDownloadJob *downloader.Job,
	fileInfoCache *lru.Cache, cacheFileForRangeRead bool, initialOffset int64) *CacheHandle

func (*CacheHandle) Close

func (fch *CacheHandle) Close() (err error)

Close closes the underlying fileHandle pointing to locally downloaded cache file.

func (*CacheHandle) IsSequential

func (fch *CacheHandle) IsSequential(currentOffset int64) bool

IsSequential returns true if the sequential read is being performed, false for random read.

func (*CacheHandle) Read

func (fch *CacheHandle) Read(ctx context.Context, bucket gcs.Bucket, object *gcs.MinObject, offset int64, dst []byte) (n int, cacheHit bool, err error)

Read attempts to read the data from the cached location. For sequential reads, it will wait to download the requested chunk if it is not already present. For random reads, it does not wait for download. Additionally, for random reads, the download will not be initiated if fch.cacheFileForRangeRead is false.

type CacheHandler

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

CacheHandler is responsible for creating CacheHandle and invalidating file cache for a given object in the bucket. CacheHandle contains reference to download job and file handle to file in cache. Additionally, while creating the CacheHandle, it ensures that the file info entry is present in the fileInfoCache and a file is present in cache inside the appropriate directory.

func NewCacheHandler

func NewCacheHandler(fileInfoCache *lru.Cache, jobManager *downloader.JobManager, cacheDir string, filePerm os.FileMode, dirPerm os.FileMode) *CacheHandler

func (*CacheHandler) Destroy

func (chr *CacheHandler) Destroy() (err error)

Destroy destroys the job manager (i.e. invalidate all the jobs). Note: This method is expected to be called at the time of unmounting and because file info cache is in-memory, it is not required to destroy it.

Acquires and releases Lock(chr.mu)

func (*CacheHandler) GetCacheHandle

func (chr *CacheHandler) GetCacheHandle(object *gcs.MinObject, bucket gcs.Bucket, cacheForRangeRead bool, initialOffset int64) (*CacheHandle, error)

GetCacheHandle creates an entry in fileInfoCache if it does not already exist. It creates downloader.Job if not already exis and requiredt. Also, creates local file into which the download job downloads the object content. Finally, it returns a CacheHandle that contains the reference to downloader.Job and the local file handle. This method is atomic, that means all the above-mentioned tasks are completed in one uninterrupted sequence guarded by (CacheHandler.mu). Note: It returns nil if cacheForRangeRead is set to False, initialOffset is non-zero (i.e. random read) and entry for file doesn't already exist in fileInfoCache then no need to create file in cache.

Acquires and releases LOCK(CacheHandler.mu)

func (*CacheHandler) InvalidateCache

func (chr *CacheHandler) InvalidateCache(objectName string, bucketName string) error

InvalidateCache removes the file entry from the fileInfoCache and performs clean up for the removed entry.

Acquires and releases LOCK(CacheHandler.mu)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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