blockstore

package
v0.0.0-...-cd15beb Latest Latest
Warning

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

Go to latest
Published: May 21, 2024 License: Apache-2.0 Imports: 19 Imported by: 0

Documentation

Index

Constants

View Source
const DBFileName = "blockstore.db"
View Source
const DefaultFlushTimeout = 1 * time.Second
View Source
const MaxBlockSize = int64(128 * UnitsKB)
View Source
const MaxSizeError = "MaxSizeError"
View Source
const UnitsGB = 1024 * UnitsMB
View Source
const UnitsKB = 1024 * 1024
View Source
const UnitsMB = 1024 * UnitsKB

Variables

This section is empty.

Functions

func AppendData

func AppendData(ctx context.Context, blockId string, name string, p []byte) (int, error)

func CloseDB

func CloseDB()

func DeleteBlock

func DeleteBlock(ctx context.Context, blockId string) error

func DeleteBlockFromDB

func DeleteBlockFromDB(ctx context.Context, blockId string) error

func DeleteCacheEntry

func DeleteCacheEntry(ctx context.Context, blockId string, name string)

func DeleteFile

func DeleteFile(ctx context.Context, blockId string, name string) error

func DeleteFileFromDB

func DeleteFileFromDB(ctx context.Context, blockId string, name string) error

func FlushCache

func FlushCache(ctx context.Context) error

func GetAllBlockIds

func GetAllBlockIds(ctx context.Context) []string

func GetAllBlockIdsInDB

func GetAllBlockIdsInDB(ctx context.Context) ([]string, error)

func GetAllBlockSizes

func GetAllBlockSizes(dataBlocks []*CacheBlock) (int, int)

func GetCacheFromDB

func GetCacheFromDB(ctx context.Context, blockId string, name string, off int64, length int64, cacheNum int64) (*[]byte, error)

func GetCacheId

func GetCacheId(blockId string, name string) string

func GetClockString

func GetClockString(t time.Time) string

func GetDB

func GetDB(ctx context.Context) (*sqlx.DB, error)

func GetDBName

func GetDBName() string

func GetMigrateVersion

func GetMigrateVersion(m *migrate.Migrate) (uint, bool, error)

func GetValuesFromCacheId

func GetValuesFromCacheId(cacheId string) (blockId string, name string)

func InsertFileIntoDB

func InsertFileIntoDB(ctx context.Context, fileInfo FileInfo) error

func MakeBlockstoreMigrate

func MakeBlockstoreMigrate() (*migrate.Migrate, error)

func MakeFile

func MakeFile(ctx context.Context, blockId string, name string, meta FileMeta, opts FileOptsType) error

func MigrateBlockstore

func MigrateBlockstore() error

func ReadAt

func ReadAt(ctx context.Context, blockId string, name string, p *[]byte, off int64) (int, error)

func ReadFromCacheBlock

func ReadFromCacheBlock(ctx context.Context, blockId string, name string, block *CacheBlock, p *[]byte, pos int, length int, destOffset int, maxRead int64) (int, error)

func SetCacheEntry

func SetCacheEntry(ctx context.Context, cacheId string, cacheEntry *CacheEntry)

func SetFlushTimeout

func SetFlushTimeout(newTimeout time.Duration)

func StartFlushTimer

func StartFlushTimer(ctx context.Context)

func WithTx

func WithTx(ctx context.Context, fn func(tx *TxWrap) error) error

func WithTxRtn

func WithTxRtn[RT any](ctx context.Context, fn func(tx *TxWrap) (RT, error)) (RT, error)

func WriteAt

func WriteAt(ctx context.Context, blockId string, name string, p []byte, off int64) (int, error)

func WriteAtHelper

func WriteAtHelper(ctx context.Context, blockId string, name string, p []byte, off int64, flushCache bool) (int, error)

func WriteDataBlockToDB

func WriteDataBlockToDB(ctx context.Context, blockId string, name string, index int, data []byte) error

func WriteFile

func WriteFile(ctx context.Context, blockId string, name string, meta FileMeta, opts FileOptsType, data []byte) (int, error)

func WriteFileToDB

func WriteFileToDB(ctx context.Context, fileInfo FileInfo) error

func WriteMeta

func WriteMeta(ctx context.Context, blockId string, name string, meta FileMeta) error

func WriteToCacheBlockNum

func WriteToCacheBlockNum(ctx context.Context, blockId string, name string, p []byte, pos int, length int, cacheNum int, pullFromDB bool) (int64, int, error)

func WriteToCacheBuf

func WriteToCacheBuf(buf *[]byte, p []byte, pos int, length int, maxWrite int64) (int, error)

Types

type BlockStore

type BlockStore interface {
	MakeFile(ctx context.Context, blockId string, name string, meta FileMeta, opts FileOptsType) error
	WriteFile(ctx context.Context, blockId string, name string, meta FileMeta, opts FileOptsType, data []byte) (int, error)
	AppendData(ctx context.Context, blockId string, name string, p []byte) (int, error)
	WriteAt(ctx context.Context, blockId string, name string, p []byte, off int64) (int, error)
	ReadAt(ctx context.Context, blockId string, name string, p *[]byte, off int64) (int, error)
	Stat(ctx context.Context, blockId string, name string) (FileInfo, error)
	CollapseIJson(ctx context.Context, blockId string, name string) error
	WriteMeta(ctx context.Context, blockId string, name string, meta FileMeta) error
	DeleteFile(ctx context.Context, blockId string, name string) error
	DeleteBlock(ctx context.Context, blockId string) error
	ListFiles(ctx context.Context, blockId string) []*FileInfo
	FlushCache(ctx context.Context) error
	GetAllBlockIds(ctx context.Context) []string
}

add ctx context.Context to all these methods

type CacheBlock

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

func GetCacheBlock

func GetCacheBlock(ctx context.Context, blockId string, name string, cacheNum int, pullFromDB bool) (*CacheBlock, error)

type CacheEntry

type CacheEntry struct {
	Lock       *sync.Mutex
	CacheTs    int64
	Info       *FileInfo
	DataBlocks []*CacheBlock
	Refs       int64
}

func GetCacheEntry

func GetCacheEntry(ctx context.Context, blockId string, name string) (*CacheEntry, bool)

func GetCacheEntryOrPopulate

func GetCacheEntryOrPopulate(ctx context.Context, blockId string, name string) (*CacheEntry, error)

func MakeCacheEntry

func MakeCacheEntry(info *FileInfo) *CacheEntry

func (*CacheEntry) DecRefs

func (c *CacheEntry) DecRefs()

func (*CacheEntry) IncRefs

func (c *CacheEntry) IncRefs()

type FileInfo

type FileInfo struct {
	BlockId   string
	Name      string
	Size      int64
	CreatedTs int64
	ModTs     int64
	Opts      FileOptsType
	Meta      FileMeta
}

func DeepCopyFileInfo

func DeepCopyFileInfo(fInfo *FileInfo) *FileInfo

func GetAllFilesInDB

func GetAllFilesInDB(ctx context.Context) ([]*FileInfo, error)

func GetAllFilesInDBForBlockId

func GetAllFilesInDBForBlockId(ctx context.Context, blockId string) ([]*FileInfo, error)

func GetFileInfo

func GetFileInfo(ctx context.Context, blockId string, name string) (*FileInfo, error)

func ListAllFiles

func ListAllFiles(ctx context.Context) []*FileInfo

func ListFiles

func ListFiles(ctx context.Context, blockId string) []*FileInfo

func Stat

func Stat(ctx context.Context, blockId string, name string) (*FileInfo, error)

func (*FileInfo) FromMap

func (fInfo *FileInfo) FromMap(m map[string]interface{}) bool

func (*FileInfo) ToMap

func (f *FileInfo) ToMap() map[string]interface{}

type FileMeta

type FileMeta = map[string]any

type FileOptsType

type FileOptsType struct {
	MaxSize  int64
	Circular bool
	IJson    bool
}

type SingleConnDBGetter

type SingleConnDBGetter struct {
	SingleConnLock *sync.Mutex
}

func (*SingleConnDBGetter) GetDB

func (dbg *SingleConnDBGetter) GetDB(ctx context.Context) (*sqlx.DB, error)

func (*SingleConnDBGetter) ReleaseDB

func (dbg *SingleConnDBGetter) ReleaseDB(db *sqlx.DB)

type TxWrap

type TxWrap = txwrap.TxWrap

Jump to

Keyboard shortcuts

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