base

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Nov 29, 2022 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNoSpace       = moerr.NewInternalError("buffer: no space left")
	ErrNotFound      = moerr.NewInternalError("buffer: node not found")
	ErrDuplicataNode = moerr.NewInternalError("buffer: duplicate node")
)

Functions

func NodeStateString

func NodeStateString(state NodeState) string

Types

type IEvictHandle

type IEvictHandle interface {
	sync.Locker
	IsClosed() bool
	TryClose() bool
	Unload()
	Unloadable() bool
	HardEvictable() bool
	Iteration() uint64
}

type IMemoryNode

type IMemoryNode interface {
	io.ReaderFrom
	io.WriterTo
	Marshal() ([]byte, error)
	Unmarshal([]byte) error
	FreeMemory()
	Reset()
	GetMemorySize() uint64
	GetMemoryCapacity() uint64
}

type INode

type INode interface {
	sync.Locker
	io.Closer
	common.IRef
	RLock()
	RUnlock()
	Key() any

	// unload the data return the size quota back
	Unload()
	// whether the node unloadable
	Unloadable() bool
	// whether the node is loaded
	IsLoaded() bool
	// load data into the node
	Load()

	// increase the node reference count and get a handle of the node
	MakeHandle() INodeHandle

	// true if the node can be destoryed and hard evicted from the node manager
	// false if the node can only be unloaded on evicted
	HardEvictable() bool

	// destory the node resources
	// node manager destoryes a node when Close a node
	Destroy()

	// the size of the node
	Size() uint64

	// the iteration of the node.
	// it is increased by 1 when the reference count is 0 during UnPin
	Iteration() uint64
	IncIteration() uint64

	// whether a node is closed
	IsClosed() bool
	// try to close a node. It cannot be closed when the reference count is not 0
	// true if closed and false otherwise
	TryClose() bool

	// the node state
	GetState() NodeState

	// expand a node size and execute the callback
	Expand(uint64, func() error) error
}

type INodeHandle

type INodeHandle interface {
	io.Closer
	Key() any
	GetNode() INode
}

type INodeManager

type INodeManager interface {
	ISizeLimiter
	sync.Locker
	RLock()
	RUnlock()
	String() string
	Count() int
	Add(INode) error
	RegisterNode(INode) error
	UnregisterNode(INode)
	Pin(INode) INodeHandle
	PinByKey(any) (INodeHandle, error)
	TryPin(INode, time.Duration) (INodeHandle, error)
	TryPinByKey(any, time.Duration) (INodeHandle, error)
	Unpin(INode)
	MakeRoom(uint64) bool
}

type ISizeLimiter

type ISizeLimiter interface {
	Total() uint64
	ApplyQuota(uint64) bool
	RetuernQuota(uint64) uint64
}

type MemoryFreeFunc

type MemoryFreeFunc func(IMemoryNode)

type NodeState

type NodeState = uint32
const (
	NodeUnload NodeState = iota
	NodeLoading
	NodeRollback
	NodeCommit
	NodeUnloadING
	NodeLoaded
)

Jump to

Keyboard shortcuts

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