cache

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Mar 27, 2017 License: GPL-3.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const (
	BOLT_BUCKETNAME_INFO   = "info"
	BOLT_BUCKETNAME_CHUNKS = "chunks"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type BoltCache

type BoltCache struct {
	DbFilename string
	DB         bolt.DB
}

func NewBoltCache

func NewBoltCache() *BoltCache

func (*BoltCache) Cleanup

func (bc *BoltCache) Cleanup() error

Cleanup delete the bolt db file in the filesystem

func (*BoltCache) ClearAllChunks

func (bc *BoltCache) ClearAllChunks() error

ClearAllChunks remove all previous stored chunks from bolt database (delete * from chunks)

func (*BoltCache) CloseDatabase

func (bc *BoltCache) CloseDatabase() error

CloseDatabase sync and close the bolt database

func (*BoltCache) GetAllChunks

func (bc *BoltCache) GetAllChunks(chunkStreamChan chan structs.ChunkStream) error

GetChunksCount return the number of stored chunks. In case of an error, this error is returned. TODO: do we need to sort them?

func (*BoltCache) GetChunk

func (bc *BoltCache) GetChunk(chunkId uint64) (structs.Chunk, error)

GetChunk returns the chunk stored under the paramter chunkid. An error is return when the chunk was not found. The complete Chunk strict will be returned.

func (*BoltCache) GetChunksCount

func (bc *BoltCache) GetChunksCount() (int, error)

GetChunksCount return the number of stored chunks. In case of an error, this error is returned.

func (*BoltCache) GetFileInfo

func (bc *BoltCache) GetFileInfo() (structs.FileData, error)

GetFileInfo reads the stored file information from the bolt database. The file information will be returned in a FileData struct and an optional error might be returned. The file information is stored as marshaled json data in the bucket BOLT_BUCKETNAME_INFO

func (*BoltCache) InitDatabase

func (bc *BoltCache) InitDatabase(cachefilename string) error

InitDatabase creates a new BoltDB database and initialize some default buckets The filename of the database is specified in the cachefilename parameter

func (*BoltCache) StoreChunk

func (bc *BoltCache) StoreChunk(chunkId uint64, chunk structs.Chunk) error

StoreChunk store the passed chunk in the database. The chunk, is a marshalled json string.

func (*BoltCache) StoreFileInfo

func (bc *BoltCache) StoreFileInfo(fd structs.FileData) error

StoreFileInfo takes a FileData struct and store those data in the bolt database. If an error occures, this error will be returned. The file information is stored as marshaled json data in the bucket BOLT_BUCKETNAME_INFO

type CacheDB

type CacheDB interface {
	// Open a connecton to the database. This will not fill chunk details.
	InitDatabase(sourcefile string) error
	// Close the connection to the database
	CloseDatabase() error
	// Cleanup database (delete table or file; depending on the implementation)
	Cleanup() error

	// Remove all existing chunks from database
	ClearAllChunks() error

	// Return stored file details from cache database
	GetFileInfo() (structs.FileData, error)
	// Store file details in cache database
	StoreFileInfo(fd structs.FileData) error

	// Get individual chunks (by chunk id) from database
	GetChunk(chunkId uint64) (structs.Chunk, error)
	// Store chunk under the specified chunk id
	StoreChunk(chunkId uint64, chunk structs.Chunk) error

	// Get the total number of stored chunks
	GetChunksCount() (int, error)
	// Return a channel to iterate over all stored chunks
	GetAllChunks(chunkChan chan structs.ChunkStream) error
}

Jump to

Keyboard shortcuts

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