filestore

package
v0.0.0-...-357036e Latest Latest
Warning

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

Go to latest
Published: Feb 10, 2022 License: GPL-3.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 FileStore

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

FileStore implements ObjectStore and stores objects in files on disk. It uses one file per bucket named <bucketId>.dat and in each file it stores data with the following format: <objId> <obj len in bytes> <obj data>\n In order to retrieve data faster, FileStore holds some metadata about buckets and objects in memory. In particular, it retains each object offset in its bucket file and its size in bytes.

To allow concurrent access to multiple buckets, it is used an array of `numMutexes` mutexes. Instead of having a mutex per bucket, these mutexes are in a fixed number to avoid: 1. to have too many mutexes which can use a lot of memory and decrease performances 2. to have maximum 2*numMutexes open files at the same time and avoid errors related to too many open files

Every change to a bucket file is performed in three steps 1. copy old data to a temporary file writing new data if needed (like add or replace and object) 2. move the temp file and overwrite the actual bucket file 3. update bucket's objects metadata if needed This mitigates the possibility of data corruption or mismatch between data on file and metadata in memory Because of this Store and deletion times depend on the size of the bucket (the whole bucket is copied). The retrieving time is bucket size independent because of the metadata stored in maps in memory.

func NewStore

func NewStore(storePath string) (*FileStore, error)

func (*FileStore) Delete

func (f *FileStore) Delete(objId, bucketId string) (bool, error)

Delete deletes the object `objId` in bucket `bucketId`. If the bucket is emptied it removes both the bucket file and metadata from the bucket metadata map. It returns whether the object has been deleted or not along with any error.

func (*FileStore) Retrieve

func (f *FileStore) Retrieve(objId, bucketId string) ([]byte, bool, error)

Retrieve retrieves the object `objId` in bucket `bucketId`. It returns the object in bytes (or nil if it was not found), whether it has been found or not, along with any error.

func (*FileStore) Store

func (f *FileStore) Store(obj []byte, objId, bucketId string) (bool, error)

Store stores the given object with ID `objId` in bucket `bucketId`. Returns whether the object has been replaced along with any error encountered. If `bucketId` is a new bucket it gets created.

Jump to

Keyboard shortcuts

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