datafile

package
v1.6.1 Latest Latest
Warning

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

Go to latest
Published: May 12, 2023 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const (
	FileIDByteSize int = 8 + 8
)

Variables

View Source
var (
	// ErrChecksumFailed is the error returned if a key/value retrieved does
	// not match its CRC checksum
	ErrChecksumFailed = errors.New("error: checksum failed")
)

Functions

func CopyTempThreshold

func CopyTempThreshold(threshold int64) datafileOptFunc

func FileMode

func FileMode(mode os.FileMode) datafileOptFunc

func IsDatafile added in v1.4.0

func IsDatafile(fileName string) bool

func Open

func Open(id FileID, dir string, funcs ...datafileOptFunc) (*defaultDatafile, error)

func OpenReadonly

func OpenReadonly(id FileID, dir string, funcs ...datafileOptFunc) (*defaultDatafile, error)

func RuntimeContext

func RuntimeContext(ctx runtime.Context) datafileOptFunc

func TempDir

func TempDir(dir string) datafileOptFunc

Types

type Datafile

type Datafile interface {
	FileID() FileID
	Name() string
	Close() error
	Sync() error
	Size() int64
	Read() (*Entry, error)
	ReadAt(index, size int64) (*Entry, error)
	ReadAtHeader(index int64) (*Header, EOFType, error)
	Write(key []byte, value io.Reader, expiry time.Time) (int64, int64, error)
}

Datafile is an interface that represents a readable and writeable datafile

type EOFType added in v1.4.0

type EOFType bool
const (
	IsEOF    EOFType = true
	IsNotEOF EOFType = false
)

type Entry

type Entry struct {
	Key       []byte
	Value     io.Reader
	TotalSize int64
	ValueSize int64
	Checksum  uint32
	Expiry    time.Time
	// contains filtered or unexported fields
}

Entry represents a key/value in the database

func (*Entry) Close

func (e *Entry) Close() error

func (*Entry) Read

func (e *Entry) Read(p []byte) (int, error)

func (*Entry) Validate

func (e *Entry) Validate(ctx runtime.Context) error

type FileID

type FileID struct {
	Time int64
	Rand int64
}

func CreateFileID added in v1.4.0

func CreateFileID(t, r int64) FileID

func GrepFileIds added in v1.4.0

func GrepFileIds(fileNames []string) []FileID

func GrepFileIdsFromDatafilePath added in v1.4.0

func GrepFileIdsFromDatafilePath(path string) ([]FileID, error)

func NextFileID added in v1.4.0

func NextFileID() FileID

func (FileID) Equal added in v1.4.0

func (f FileID) Equal(target FileID) bool

func (FileID) IsZero added in v1.4.0

func (f FileID) IsZero() bool

func (FileID) Newer added in v1.4.0

func (f FileID) Newer(target FileID) bool

func (FileID) String added in v1.4.0

func (f FileID) String() string
type Header struct {
	KeySize   int32
	ValueSize int64
	Checksum  uint32
	Expiry    time.Time
	TotalSize int64
}

Jump to

Keyboard shortcuts

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