Documentation ¶
Index ¶
- Constants
- type BoltCache
- func (bc *BoltCache) Cleanup() error
- func (bc *BoltCache) ClearAllChunks() error
- func (bc *BoltCache) CloseDatabase() error
- func (bc *BoltCache) GetAllChunks(chunkStreamChan chan structs.ChunkStream) error
- func (bc *BoltCache) GetChunk(chunkId uint64) (structs.Chunk, error)
- func (bc *BoltCache) GetChunksCount() (int, error)
- func (bc *BoltCache) GetFileInfo() (structs.FileData, error)
- func (bc *BoltCache) InitDatabase(cachefilename string) error
- func (bc *BoltCache) StoreChunk(chunkId uint64, chunk structs.Chunk) error
- func (bc *BoltCache) StoreFileInfo(fd structs.FileData) error
- type CacheDB
Constants ¶
const ( BOLT_BUCKETNAME_INFO = "info" BOLT_BUCKETNAME_CHUNKS = "chunks" )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type BoltCache ¶
func NewBoltCache ¶
func NewBoltCache() *BoltCache
func (*BoltCache) ClearAllChunks ¶
ClearAllChunks remove all previous stored chunks from bolt database (delete * from chunks)
func (*BoltCache) CloseDatabase ¶
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 ¶
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 ¶
GetChunksCount return the number of stored chunks. In case of an error, this error is returned.
func (*BoltCache) GetFileInfo ¶
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 ¶
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 ¶
StoreChunk store the passed chunk in the database. The chunk, is a marshalled json string.
func (*BoltCache) StoreFileInfo ¶
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 }