block_cache

package
v2.0.0-...-f5fadf4 Latest Latest
Warning

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

Go to latest
Published: Mar 19, 2024 License: MIT Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
const (
	BlockFlagFresh       uint16 = iota
	BlockFlagDownloading        // Block is being downloaded
	BlockFlagUploading          // Block is being uploaded
	BlockFlagDirty              // Block has been written and data is not persisted yet
	BlockFlagSynced             // Block has been written and data is persisted
	BlockFlagFailed             // Block upload/download has failed
)

Various flags denoting state of a block

View Source
const (
	MAX_POOL_USAGE  uint32 = 80
	MIN_POOL_USAGE  uint32 = 50
	MIN_PREFETCH           = 5
	MIN_WRITE_BLOCK        = 3
	MIN_RANDREAD           = 10
	MAX_FAIL_CNT           = 3
	MAX_BLOCKS             = 50000
)

Variables

This section is empty.

Functions

func NewBlockCacheComponent

func NewBlockCacheComponent() internal.Component

------------------------- Factory ------------------------------------------- Pipeline will call this method to create your object, initialize your variables here << DO NOT DELETE ANY AUTO GENERATED CODE HERE >>

Types

type Block

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

Block is a memory mapped buffer with its state to hold data

func AllocateBlock

func AllocateBlock(size uint64) (*Block, error)

AllocateBlock creates a new memory mapped buffer for the given size

func (*Block) Delete

func (b *Block) Delete() error

Delete cleans up the memory mapped buffer

func (*Block) Dirty

func (b *Block) Dirty()

Mark this block as dirty as it has been modified

func (*Block) Failed

func (b *Block) Failed()

Mark this block as failed

func (*Block) IsDirty

func (b *Block) IsDirty() bool

Check if this block has been modified or not

func (*Block) IsFailed

func (b *Block) IsFailed() bool

Check this block as failed

func (*Block) NoMoreDirty

func (b *Block) NoMoreDirty()

Mark this block as dirty as it has been modified

func (*Block) ReUse

func (b *Block) ReUse()

ReUse reinits the Block by recreating its channel

func (*Block) Ready

func (b *Block) Ready()

Ready marks this Block is now ready for reading by its first reader (data download completed)

func (*Block) Unblock

func (b *Block) Unblock()

Unblock marks this Block is ready to be read in parllel now

func (*Block) Uploading

func (b *Block) Uploading()

Uploading marks buffer is under upload

type BlockCache

type BlockCache struct {
	internal.BaseComponent
	// contains filtered or unexported fields
}

Common structure for Component

func (*BlockCache) CloseFile

func (bc *BlockCache) CloseFile(options internal.CloseFileOptions) error

CloseFile: File is closed by application so release all the blocks and submit back to blockPool

func (*BlockCache) Configure

func (bc *BlockCache) Configure(_ bool) error

Configure : Pipeline will call this method after constructor so that you can read config and initialize yourself

Return failure if any config is not valid to exit the process

func (*BlockCache) CreateFile

func (bc *BlockCache) CreateFile(options internal.CreateFileOptions) (*handlemap.Handle, error)

CreateFile: Create a new file

func (*BlockCache) DeleteDir

func (bc *BlockCache) DeleteDir(options internal.DeleteDirOptions) error

DeleteDir: Recursively invalidate the directory and its children

func (*BlockCache) DeleteFile

func (bc *BlockCache) DeleteFile(options internal.DeleteFileOptions) error

DeleteFile: Invalidate the file in local cache.

func (*BlockCache) FlushFile

func (bc *BlockCache) FlushFile(options internal.FlushFileOptions) error

FlushFile: Flush the local file to storage

func (*BlockCache) Name

func (bc *BlockCache) Name() string

func (*BlockCache) OpenFile

func (bc *BlockCache) OpenFile(options internal.OpenFileOptions) (*handlemap.Handle, error)

OpenFile: Create a handle for the file user has requested to open

func (*BlockCache) ReadInBuffer

func (bc *BlockCache) ReadInBuffer(options internal.ReadInBufferOptions) (int, error)

ReadInBuffer: Read the file into a buffer

func (*BlockCache) RenameDir

func (bc *BlockCache) RenameDir(options internal.RenameDirOptions) error

RenameDir: Recursively invalidate the source directory and its children

func (*BlockCache) RenameFile

func (bc *BlockCache) RenameFile(options internal.RenameFileOptions) error

RenameFile: Invalidate the file in local cache.

func (*BlockCache) SetName

func (bc *BlockCache) SetName(name string)

func (*BlockCache) SetNextComponent

func (bc *BlockCache) SetNextComponent(nc internal.Component)

func (*BlockCache) Start

func (bc *BlockCache) Start(ctx context.Context) error

Start : Pipeline calls this method to start the component functionality

this shall not Block the call otherwise pipeline will not start

func (*BlockCache) Stop

func (bc *BlockCache) Stop() error

Stop : Stop the component functionality and kill all threads started

func (*BlockCache) SyncFile

func (bc *BlockCache) SyncFile(options internal.SyncFileOptions) error

func (*BlockCache) TempCacheCleanup

func (bc *BlockCache) TempCacheCleanup() error

TempCacheCleanup cleans up the local cached contents

func (*BlockCache) WriteFile

func (bc *BlockCache) WriteFile(options internal.WriteFileOptions) (int, error)

WriteFile: Write to the local file

type BlockCacheOptions

type BlockCacheOptions struct {
	BlockSize      float64 `config:"block-size-mb" yaml:"block-size-mb,omitempty"`
	MemSize        uint64  `config:"mem-size-mb" yaml:"mem-size-mb,omitempty"`
	TmpPath        string  `config:"path" yaml:"path,omitempty"`
	DiskSize       uint64  `config:"disk-size-mb" yaml:"disk-size-mb,omitempty"`
	DiskTimeout    uint32  `config:"disk-timeout-sec" yaml:"timeout-sec,omitempty"`
	PrefetchCount  uint32  `config:"prefetch" yaml:"prefetch,omitempty"`
	Workers        uint32  `config:"parallelism" yaml:"parallelism,omitempty"`
	PrefetchOnOpen bool    `config:"prefetch-on-open" yaml:"prefetch-on-open,omitempty"`
}

Structure defining your config parameters

type BlockPool

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

BlockPool is a pool of Blocks

func NewBlockPool

func NewBlockPool(blockSize uint64, memSize uint64) *BlockPool

NewBlockPool allocates a new pool of blocks

func (*BlockPool) MustGet

func (pool *BlockPool) MustGet() *Block

MustGet a Block from the pool, wait until something is free

func (*BlockPool) Release

func (pool *BlockPool) Release(b *Block)

Release back the Block to the pool

func (*BlockPool) Terminate

func (pool *BlockPool) Terminate()

Terminate ends the block pool life

func (*BlockPool) TryGet

func (pool *BlockPool) TryGet() *Block

TryGet a Block from the pool, return back if nothing is available

func (*BlockPool) Usage

func (pool *BlockPool) Usage() uint32

Usage provides % usage of this block pool

type ThreadPool

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

ThreadPool is a group of workers that can be used to execute a task

func (*ThreadPool) Do

func (t *ThreadPool) Do(priority bool)

Do is the core task to be executed by each worker thread

func (*ThreadPool) Schedule

func (t *ThreadPool) Schedule(urgent bool, item *workItem)

Schedule the download of a block

func (*ThreadPool) Start

func (t *ThreadPool) Start()

Start all the workers and wait till they start receiving requests

func (*ThreadPool) Stop

func (t *ThreadPool) Stop()

Stop all the workers threads

Jump to

Keyboard shortcuts

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