diskv

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Nov 29, 2022 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const (
	RefData int8 = iota
	RefLink
)

Variables

View Source
var (
	ErrNotFound        = xerrors.New("diskv: not found")
	ErrUnknowOperation = xerrors.New("diskv: unknow operation")
)

Functions

func DefaultShardFun

func DefaultShardFun(key string) (parent, path string, err error)

Types

type Config

type Config struct {
	Dir            string
	MaxLinkDagSize int
	Shard          ShardFun
	MaxRead        int
	MaxWrite       int
	MaxCacheDags   int
}

type DagRef

type DagRef struct {
	Code uint32 // crc32 checksum
	Size int
	Type int8
	Data []byte
}

func (*DagRef) Bytes

func (d *DagRef) Bytes() ([]byte, error)

func (*DagRef) FromBytes

func (d *DagRef) FromBytes(data []byte) error

type DisKV

type DisKV struct {
	Cfg *Config
	Ref *Refdb
	// contains filtered or unexported fields
}

func NewDisKV

func NewDisKV(opts ...Option) (*DisKV, error)

func (*DisKV) AllKeysChan

func (di *DisKV) AllKeysChan(ctx context.Context) (<-chan string, error)

func (*DisKV) Close

func (di *DisKV) Close() error

func (*DisKV) Delete

func (di *DisKV) Delete(key string) error

func (*DisKV) Get

func (di *DisKV) Get(key string) ([]byte, error)

func (*DisKV) Put

func (di *DisKV) Put(key string, value []byte) error

Put - write dag node into repo

we use MaxLinkDagSize to divide dag nodes into two categories:

  • link-dag which size is smaller than or equal to MaxLinkDagSize
  • data-dag which size is bigger than MaxLinkDagSize

we store link-dag into leveldb only, store data-dag into disk and keep an ref whith leveldb

func (*DisKV) Size

func (di *DisKV) Size(key string) (int, error)

type Option

type Option func(cfg *Config)

func DirConf

func DirConf(dir string) Option

func MaxCacheDagsConf

func MaxCacheDagsConf(n int) Option

func MaxLinkDagSizeConf

func MaxLinkDagSizeConf(size int) Option

func MaxReadConf

func MaxReadConf(n int) Option

func MaxWriteConf

func MaxWriteConf(n int) Option

func ShardFunConf

func ShardFunConf(sha ShardFun) Option

type Refdb

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

func NewRefdb

func NewRefdb(dir string) (*Refdb, error)

func (*Refdb) AllKeysChan

func (ref *Refdb) AllKeysChan(ctx context.Context) (chan string, error)

func (*Refdb) Close

func (ref *Refdb) Close() error

func (*Refdb) Delete

func (ref *Refdb) Delete(key string) error

func (*Refdb) Get

func (ref *Refdb) Get(key string) ([]byte, error)

func (*Refdb) Put

func (ref *Refdb) Put(key string, value []byte) error

type ShardFun

type ShardFun func(key string) (parent, path string, err error)

Jump to

Keyboard shortcuts

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