common

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Apr 12, 2023 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	BranchPageFlag   = 0x01
	LeafPageFlag     = 0x02
	MetaPageFlag     = 0x04
	FreelistPageFlag = 0x10
)
View Source
const (
	DefaultMaxBatchSize  int = 1000
	DefaultMaxBatchDelay     = 10 * time.Millisecond
	DefaultAllocSize         = 16 * 1024 * 1024
)

Default values if not set in a DB instance.

View Source
const (
	// FreelistArrayType indicates backend freelist type is array
	FreelistArrayType = FreelistType("array")
	// FreelistMapType indicates backend freelist type is hashmap
	FreelistMapType = FreelistType("hashmap")
)
View Source
const BranchPageElementSize = unsafe.Sizeof(branchPageElement{})
View Source
const BucketHeaderSize = int(unsafe.Sizeof(InBucket{}))
View Source
const (
	BucketLeafFlag = 0x01
)
View Source
const IgnoreNoSync = runtime.GOOS == "openbsd"

IgnoreNoSync specifies whether the NoSync field of a DB is ignored when syncing changes to a file. This is required as some operating systems, such as OpenBSD, do not have a unified buffer cache (UBC) and writes must be synchronized using the msync(2) syscall.

View Source
const LeafPageElementSize = unsafe.Sizeof(leafPageElement{})
View Source
const Magic uint32 = 0xED0CDAED

Magic represents a marker value to indicate that a file is a Bolt DB.

View Source
const MaxMmapStep = 1 << 30 // 1GB

MaxMmapStep is the largest step that can be taken when remapping the mmap.

View Source
const MinKeysPerPage = 2
View Source
const PageHeaderSize = unsafe.Sizeof(Page{})
View Source
const Version = 2

Version represents the data file format version.

Variables

View Source
var DefaultPageSize = os.Getpagesize()

DefaultPageSize is the default page size for db which is set to the OS page size.

Functions

func Assert

func Assert(condition bool, msg string, v ...interface{})

Assert will panic with a given formatted message if the given condition is false.

func CopyFile

func CopyFile(srcPath, dstPath string) error

func Mergepgids

func Mergepgids(dst, a, b Pgids)

Mergepgids copies the sorted union of a and b into dst. If dst is too small, it panics.

func NewLeafPageElement

func NewLeafPageElement(flags, pos, ksize, vsize uint32) *leafPageElement

func UnsafeAdd

func UnsafeAdd(base unsafe.Pointer, offset uintptr) unsafe.Pointer

func UnsafeByteSlice

func UnsafeByteSlice(base unsafe.Pointer, offset uintptr, i, j int) []byte

func UnsafeIndex

func UnsafeIndex(base unsafe.Pointer, offset uintptr, elemsz uintptr, n int) unsafe.Pointer

func UnsafeSlice

func UnsafeSlice(slice, data unsafe.Pointer, len int)

UnsafeSlice modifies the data, len, and cap of a slice variable pointed to by the slice parameter. This helper should be used over other direct manipulation of reflect.SliceHeader to prevent misuse, namely, converting from reflect.SliceHeader to a Go slice type.

func UsedSpaceInPage

func UsedSpaceInPage(inodes Inodes, p *Page) uint32

func WriteInodeToPage

func WriteInodeToPage(inodes Inodes, p *Page) uint32

Types

type FreelistType

type FreelistType string

FreelistType is the type of the freelist backend

type InBucket

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

InBucket represents the on-file representation of a bucket. This is stored as the "value" of a bucket key. If the bucket is small enough, then its root page can be stored inline in the "value", after the bucket header. In the case of inline buckets, the "root" will be 0.

func LoadBucket

func LoadBucket(buf []byte) *InBucket

func NewInBucket

func NewInBucket(root Pgid, seq uint64) InBucket

func (*InBucket) InSequence

func (b *InBucket) InSequence() uint64

InSequence returns the sequence. The reason why not naming it `Sequence` is to avoid duplicated name as `(*Bucket) Sequence()`

func (*InBucket) IncSequence

func (b *InBucket) IncSequence()

func (*InBucket) InlinePage

func (b *InBucket) InlinePage(v []byte) *Page

func (*InBucket) RootPage

func (b *InBucket) RootPage() Pgid

func (*InBucket) SetInSequence

func (b *InBucket) SetInSequence(v uint64)

func (*InBucket) SetRootPage

func (b *InBucket) SetRootPage(id Pgid)

func (*InBucket) String

func (b *InBucket) String() string

type Inode

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

Inode represents an internal node inside of a node. It can be used to point to elements in a page or point to an element which hasn't been added to a page yet.

func (*Inode) Flags

func (in *Inode) Flags() uint32

func (*Inode) Key

func (in *Inode) Key() []byte

func (*Inode) Pgid

func (in *Inode) Pgid() Pgid

func (*Inode) SetFlags

func (in *Inode) SetFlags(flags uint32)

func (*Inode) SetKey

func (in *Inode) SetKey(key []byte)

func (*Inode) SetPgid

func (in *Inode) SetPgid(id Pgid)

func (*Inode) SetValue

func (in *Inode) SetValue(value []byte)

func (*Inode) Value

func (in *Inode) Value() []byte

type Inodes

type Inodes []Inode

func ReadInodeFromPage

func ReadInodeFromPage(p *Page) Inodes

type Meta

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

func LoadPageMeta

func LoadPageMeta(buf []byte) *Meta

func (*Meta) Copy

func (m *Meta) Copy(dest *Meta)

Copy copies one meta object to another.

func (*Meta) DecTxid

func (m *Meta) DecTxid()

func (*Meta) Flags

func (m *Meta) Flags() uint32

func (*Meta) Freelist

func (m *Meta) Freelist() Pgid

func (*Meta) IncTxid

func (m *Meta) IncTxid()

func (*Meta) Magic

func (m *Meta) Magic() uint32

func (*Meta) PageSize

func (m *Meta) PageSize() uint32

func (*Meta) Pgid

func (m *Meta) Pgid() Pgid

func (*Meta) Print

func (m *Meta) Print(w io.Writer)

func (*Meta) RootBucket

func (m *Meta) RootBucket() *InBucket

func (*Meta) SetChecksum

func (m *Meta) SetChecksum(v uint64)

func (*Meta) SetFlags

func (m *Meta) SetFlags(v uint32)

func (*Meta) SetFreelist

func (m *Meta) SetFreelist(v Pgid)

func (*Meta) SetMagic

func (m *Meta) SetMagic(v uint32)

func (*Meta) SetPageSize

func (m *Meta) SetPageSize(v uint32)

func (*Meta) SetPgid

func (m *Meta) SetPgid(id Pgid)

func (*Meta) SetRootBucket

func (m *Meta) SetRootBucket(b InBucket)

func (*Meta) SetTxid

func (m *Meta) SetTxid(id Txid)

func (*Meta) SetVersion

func (m *Meta) SetVersion(v uint32)

func (*Meta) Sum64

func (m *Meta) Sum64() uint64

Sum64 generates the checksum for the meta.

func (*Meta) Txid

func (m *Meta) Txid() Txid

func (*Meta) Validate

func (m *Meta) Validate() error

Validate checks the marker bytes and version of the meta page to ensure it matches this binary.

func (*Meta) Write

func (m *Meta) Write(p *Page)

Write writes the meta onto a page.

type Page

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

func LoadPage

func LoadPage(buf []byte) *Page

func NewPage

func NewPage(id Pgid, flags, count uint16, overflow uint32) *Page

func (*Page) BranchPageElement

func (p *Page) BranchPageElement(index uint16) *branchPageElement

BranchPageElement retrieves the branch node by index

func (*Page) BranchPageElements

func (p *Page) BranchPageElements() []branchPageElement

BranchPageElements retrieves a list of branch nodes.

func (*Page) Count

func (p *Page) Count() uint16

func (*Page) FastCheck

func (p *Page) FastCheck(id Pgid)

func (*Page) Flags

func (p *Page) Flags() uint16

func (*Page) FlagsXOR

func (p *Page) FlagsXOR(v uint16)

func (*Page) FreelistPageCount

func (p *Page) FreelistPageCount() (int, int)

func (*Page) FreelistPageIds

func (p *Page) FreelistPageIds() []Pgid

func (*Page) Id

func (p *Page) Id() Pgid

func (*Page) IsBranchPage

func (p *Page) IsBranchPage() bool

func (*Page) IsFreelistPage

func (p *Page) IsFreelistPage() bool

func (*Page) IsLeafPage

func (p *Page) IsLeafPage() bool

func (*Page) IsMetaPage

func (p *Page) IsMetaPage() bool

func (*Page) LeafPageElement

func (p *Page) LeafPageElement(index uint16) *leafPageElement

LeafPageElement retrieves the leaf node by index

func (*Page) LeafPageElements

func (p *Page) LeafPageElements() []leafPageElement

LeafPageElements retrieves a list of leaf nodes.

func (*Page) Meta

func (p *Page) Meta() *Meta

Meta returns a pointer to the metadata section of the page.

func (*Page) Overflow

func (p *Page) Overflow() uint32

func (*Page) PageElementSize

func (p *Page) PageElementSize() uintptr

func (*Page) SetCount

func (p *Page) SetCount(target uint16)

func (*Page) SetFlags

func (p *Page) SetFlags(v uint16)

func (*Page) SetId

func (p *Page) SetId(target Pgid)

func (*Page) SetOverflow

func (p *Page) SetOverflow(target uint32)

func (*Page) String

func (p *Page) String() string

func (*Page) Typ

func (p *Page) Typ() string

Typ returns a human-readable page type string used for debugging.

type PageInfo

type PageInfo struct {
	ID            int
	Type          string
	Count         int
	OverflowCount int
}

PageInfo represents human readable information about a page.

type Pages

type Pages []*Page

func (Pages) Len

func (s Pages) Len() int

func (Pages) Less

func (s Pages) Less(i, j int) bool

func (Pages) Swap

func (s Pages) Swap(i, j int)

type Pgid

type Pgid uint64
const PgidNoFreelist Pgid = 0xffffffffffffffff

type Pgids

type Pgids []Pgid

func (Pgids) Len

func (s Pgids) Len() int

func (Pgids) Less

func (s Pgids) Less(i, j int) bool

func (Pgids) Merge

func (a Pgids) Merge(b Pgids) Pgids

Merge returns the sorted union of a and b.

func (Pgids) Swap

func (s Pgids) Swap(i, j int)

type Txid

type Txid uint64

Txid represents the internal transaction identifier.

Jump to

Keyboard shortcuts

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