block

package
v0.9.0 Latest Latest
Warning

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

Go to latest
Published: Sep 7, 2023 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNotEnoughSpace = errors.New("not enough space")
	ErrFull           = errors.New("full")
	ErrNotLeader      = errors.New("not leader")
	ErrExceeded       = errors.New("the offset exceeded")
	ErrOnEnd          = errors.New("the offset on end")
	ErrNotSupported   = errors.New("not supported")
)
View Source
var ErrSnapshotOutOfOrder = errors.New("the snapshot is out of order")

Functions

func MarshalFragment

func MarshalFragment(frag Fragment) ([]byte, error)

Types

type AppendCallback

type AppendCallback = func(seqs []int64, err error)

type AppendContext

type AppendContext interface {
	WriteOffset() int64
	Archived() bool
}

type Appender

type Appender interface {
	Append(ctx context.Context, entries []Entry, cb AppendCallback)
}

type ArchivedCallback

type ArchivedCallback func(stat Statistics)

func (ArchivedCallback) OnArchived

func (f ArchivedCallback) OnArchived(stat Statistics)

type ArchivedListener

type ArchivedListener interface {
	OnArchived(stat Statistics)
}

type Block

type Block interface {
	Seeker
	Reader
	Appender

	ID() vanus.ID
}

type BytesValue

type BytesValue []byte

func (BytesValue) Size

func (bv BytesValue) Size() int

func (BytesValue) Value

func (bv BytesValue) Value() []byte

type CommitAppendCallback

type CommitAppendCallback = func()

type EmptyEntry

type EmptyEntry struct{}

func (*EmptyEntry) Get

func (e *EmptyEntry) Get(ordinal int) interface{}

func (*EmptyEntry) GetBytes

func (e *EmptyEntry) GetBytes(ordinal int) []byte

func (*EmptyEntry) GetExtensionAttribute

func (e *EmptyEntry) GetExtensionAttribute([]byte) []byte

func (*EmptyEntry) GetInt64

func (e *EmptyEntry) GetInt64(ordinal int) int64

func (*EmptyEntry) GetString

func (e *EmptyEntry) GetString(ordinal int) string

func (*EmptyEntry) GetTime

func (e *EmptyEntry) GetTime(ordinal int) time.Time

func (*EmptyEntry) GetUint16

func (e *EmptyEntry) GetUint16(ordinal int) uint16

func (*EmptyEntry) GetUint64

func (e *EmptyEntry) GetUint64(ordinal int) uint64

func (*EmptyEntry) RangeExtensionAttributes

func (e *EmptyEntry) RangeExtensionAttributes(ordinal ExtensionAttributeCallback)

type EmptyEntryExt

type EmptyEntryExt struct {
	EmptyEntry
}

func (*EmptyEntryExt) ExtensionAttributeCount

func (e *EmptyEntryExt) ExtensionAttributeCount() int

func (*EmptyEntryExt) OptionalAttributeCount

func (e *EmptyEntryExt) OptionalAttributeCount() int

func (*EmptyEntryExt) RangeOptionalAttributes

func (e *EmptyEntryExt) RangeOptionalAttributes(ordinal OptionalAttributeCallback)

type Entry

type Entry interface {
	Get(ordinal int) interface{}
	GetBytes(ordinal int) []byte
	GetString(ordinal int) string
	GetUint16(ordinal int) uint16
	GetUint64(ordinal int) uint64
	GetInt64(ordinal int) int64
	GetTime(ordinal int) time.Time

	GetExtensionAttribute([]byte) []byte
	RangeExtensionAttributes(cb ExtensionAttributeCallback)
}

Entry is a record of data stored in a Block. An Entry has some optional attributes and arbitrary extension attributes.

type EntryExt

type EntryExt interface {
	Entry

	OptionalAttributeCount() int
	ExtensionAttributeCount() int

	RangeOptionalAttributes(cb OptionalAttributeCallback)
}

type EntryExtWrapper

type EntryExtWrapper struct {
	E EntryExt
}

func (*EntryExtWrapper) ExtensionAttributeCount

func (w *EntryExtWrapper) ExtensionAttributeCount() int

func (*EntryExtWrapper) Get

func (w *EntryExtWrapper) Get(ordinal int) interface{}

func (*EntryExtWrapper) GetBytes

func (w *EntryExtWrapper) GetBytes(ordinal int) []byte

func (*EntryExtWrapper) GetExtensionAttribute

func (w *EntryExtWrapper) GetExtensionAttribute(attr []byte) []byte

func (*EntryExtWrapper) GetInt64

func (w *EntryExtWrapper) GetInt64(ordinal int) int64

func (*EntryExtWrapper) GetString

func (w *EntryExtWrapper) GetString(ordinal int) string

func (*EntryExtWrapper) GetTime

func (w *EntryExtWrapper) GetTime(ordinal int) time.Time

func (*EntryExtWrapper) GetUint16

func (w *EntryExtWrapper) GetUint16(ordinal int) uint16

func (*EntryExtWrapper) GetUint64

func (w *EntryExtWrapper) GetUint64(ordinal int) uint64

func (*EntryExtWrapper) OptionalAttributeCount

func (w *EntryExtWrapper) OptionalAttributeCount() int

func (*EntryExtWrapper) RangeExtensionAttributes

func (w *EntryExtWrapper) RangeExtensionAttributes(cb ExtensionAttributeCallback)

func (*EntryExtWrapper) RangeOptionalAttributes

func (w *EntryExtWrapper) RangeOptionalAttributes(cb OptionalAttributeCallback)

type ExtensionAttributeCallback

type ExtensionAttributeCallback interface {
	OnAttribute(attr []byte, val Value)
}

type Fragment

type Fragment interface {
	Payload() []byte
	Size() int
	StartOffset() int64
	EndOffset() int64
}

Fragment is a fragment of a block.

The layout of `Fragment` is:

┌───────────────────────────────────┬───────────────────────────────────┐
│             Offset(8)             │              Payload ...          │
└───────────────────────────────────┴───────────────────────────────────┘

All values little-endian

+00 8B Offset
+08    Payload

func NewFragment

func NewFragment(data []byte) Fragment

type FragmentMarshaler

type FragmentMarshaler interface {
	MarshalFragment() ([]byte, error)
}

type OnExtensionAttributeFunc

type OnExtensionAttributeFunc func(attr []byte, val Value)

func (OnExtensionAttributeFunc) OnAttribute

func (f OnExtensionAttributeFunc) OnAttribute(attr []byte, val Value)

type OnOptionalAttributeFunc

type OnOptionalAttributeFunc func(ordinal int, val interface{})

func (OnOptionalAttributeFunc) OnAttribute

func (f OnOptionalAttributeFunc) OnAttribute(ordinal int, val interface{})

func (OnOptionalAttributeFunc) OnBytes

func (f OnOptionalAttributeFunc) OnBytes(ordinal int, val []byte)

func (OnOptionalAttributeFunc) OnInt64

func (f OnOptionalAttributeFunc) OnInt64(ordinal int, val int64)

func (OnOptionalAttributeFunc) OnString

func (f OnOptionalAttributeFunc) OnString(ordinal int, val string)

func (OnOptionalAttributeFunc) OnTime

func (f OnOptionalAttributeFunc) OnTime(ordinal int, val time.Time)

func (OnOptionalAttributeFunc) OnUint16

func (f OnOptionalAttributeFunc) OnUint16(ordinal int, val uint16)

func (OnOptionalAttributeFunc) OnUint64

func (f OnOptionalAttributeFunc) OnUint64(ordinal int, val uint64)

type OptionalAttributeCallback

type OptionalAttributeCallback interface {
	OnBytes(ordinal int, val []byte)
	OnString(ordinal int, val string)
	OnUint16(ordinal int, val uint16)
	OnUint64(ordinal int, val uint64)
	OnInt64(ordinal int, val int64)
	OnTime(ordinal int, val time.Time)
	// TODO(james.yin): more types
	OnAttribute(ordinal int, val interface{})
}

type Raw

type Raw interface {
	Seeker
	Reader
	TwoPCAppender
	Snapshoter

	ID() vanus.ID

	Open(context.Context) error
	Close(context.Context) error
	Delete(context.Context) error
	Status() Statistics
}

type Reader

type Reader interface {
	Read(ctx context.Context, seq int64, num int) ([]Entry, error)
}

type SeekKeyFlag

type SeekKeyFlag uint64
const (
	SeekKeyExact SeekKeyFlag = iota
	SeekKeyOrNext
	SeekKeyOrPrev
	SeekAfterKey
	SeekBeforeKey
	SeekPrefix
	SeekPrefixLast
	SeekPrefixLastOrPrev
)

type Seeker

type Seeker interface {
	Seek(ctx context.Context, index int64, key Entry, flag SeekKeyFlag) (int64, error)
}

type Snapshoter

type Snapshoter interface {
	Snapshot(ctx context.Context) (Fragment, error)
	ApplySnapshot(ctx context.Context, snap Fragment) error
}

type Statistics

type Statistics struct {
	ID        vanus.ID
	Capacity  uint64
	Archived  bool
	EntryNum  uint32
	EntrySize uint64
	// FirstEntryStime is the millisecond timestamp when the first Entry will be written to Block.
	FirstEntryStime int64
	// LastEntryStime is the millisecond timestamp when the last Entry will be written to Block.
	LastEntryStime int64
}

type TwoPCAppender

type TwoPCAppender interface {
	NewAppendContext(last Fragment) AppendContext
	PrepareAppend(ctx context.Context, appendCtx AppendContext, entries ...Entry) ([]int64, Fragment, bool, error)
	PrepareArchive(ctx context.Context, appendCtx AppendContext) (Fragment, error)
	CommitAppend(ctx context.Context, frag Fragment, cb CommitAppendCallback)
}

type Value

type Value interface {
	Size() int
	Value() []byte
}

type ValueMarshaler

type ValueMarshaler interface {
	Value

	MarshalTo(buf []byte) int
}

Directories

Path Synopsis
Package testing is a generated GoMock package.
Package testing is a generated GoMock package.

Jump to

Keyboard shortcuts

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