common

package
v1.0.0-test.2 Latest Latest
Warning

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

Go to latest
Published: Sep 11, 2025 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	BranchPageFlag   = 0x01
	LeafPageFlag     = 0x02
	MetaPageFlag     = 0x04
	FreelistPageFlag = 0x10
)
View Source
const (
	NormalTreeFlag = 0x01
	SubTreeFlag    = 0x02
)
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 BranchPageElementSize = unsafe.Sizeof(branchPageElement{})
View Source
const BucketHeaderSize = int(unsafe.Sizeof(InBTree{}))
View Source
const EnvVerify = "TSMM_VERIFY"
View Source
const HashSize = 20
View Source
const IgnoreNoSync = runtime.GOOS == "openbsd"
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 MetaSize = int(unsafe.Sizeof(Meta{}))
View Source
const MinKeysPerPage = 2
View Source
const PageHeaderSize = unsafe.Sizeof(Page{})
View Source
const Version uint32 = 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 ...any)

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

func DisableVerifications

func DisableVerifications() func()

DisableVerifications unsets `ENV_VERIFY` and returns a function that can be used to bring the original settings.

func EnableAllVerifications

func EnableAllVerifications() func()

EnableAllVerifications enables verification and returns a function that can be used to bring the original settings.

func EnableVerifications

func EnableVerifications(verification VerificationType) func()

EnableVerifications sets `ENV_VERIFY` and returns a function that can be used to bring the original settings.

func IsVerificationEnabled

func IsVerificationEnabled(verification VerificationType) bool

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, hsize 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 UsedSpaceInPage

func UsedSpaceInPage(inodes Inodes, p *Page) uint32

func Verify

func Verify(f func())

Verify performs verification if the assertions are enabled. In the default setup running in tests and skipped in the production code.

func WriteInodeToPage

func WriteInodeToPage(inodes Inodes, p *Page) uint32

Types

type InBTree

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

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

func NewInBTree

func NewInBTree(root Pgid, overflow uint32, name string, seq uint64) *InBTree

func (*InBTree) InSequence

func (b *InBTree) InSequence() uint64

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

func (*InBTree) IncSequence

func (b *InBTree) IncSequence()

func (*InBTree) InlinePage

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

func (*InBTree) Name

func (b *InBTree) Name() string

func (*InBTree) Overflow

func (b *InBTree) Overflow() uint32

func (*InBTree) RootPage

func (b *InBTree) RootPage() Pgid

func (*InBTree) SetInSequence

func (b *InBTree) SetInSequence(v uint64)

func (*InBTree) SetName

func (b *InBTree) SetName(name string)

func (*InBTree) SetOverflow

func (b *InBTree) SetOverflow(overflow uint32)

func (*InBTree) SetRootPage

func (b *InBTree) SetRootPage(id Pgid)

func (*InBTree) String

func (b *InBTree) 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) Hash

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

func (*Inode) Key

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

func (*Inode) Overflow

func (in *Inode) Overflow() uint32

func (*Inode) Pgid

func (in *Inode) Pgid() Pgid

func (*Inode) SetFlags

func (in *Inode) SetFlags(flags uint32)

func (*Inode) SetHash

func (in *Inode) SetHash(hash []byte)

func (*Inode) SetKey

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

func (*Inode) SetOverflow

func (in *Inode) SetOverflow(overflow uint32)

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 KV

type KV struct {
	Key   []byte
	Value []byte
}

type KVS

type KVS []*KV

type Meta

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

Meta 版本信息

func (*Meta) Checksum

func (m *Meta) Checksum() uint64

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) Encode

func (m *Meta) Encode() []byte

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) IsFreelistPersisted

func (m *Meta) IsFreelistPersisted() bool

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() *InBTree

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 InBTree)

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) Version

func (m *Meta) Version() uint32

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 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) FreelistPageCount

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

func (*Page) FreelistPageIds

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

func (*Page) GetHash

func (p *Page) GetHash() [20]byte

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) SetHash

func (p *Page) SetHash(hash []byte)

func (*Page) SetId

func (p *Page) SetId(target Pgid)

func (*Page) SetOverflow

func (p *Page) SetOverflow(target uint32)

func (*Page) SetSize

func (p *Page) SetSize(target uint32)

func (*Page) Size

func (p *Page) Size() 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 PageVersion

type PageVersion uint32
const (
	Version0 PageVersion = iota
)

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.

type VerificationType

type VerificationType string
const (
	EnvVerifyValueAll    VerificationType = "all"
	EnvVerifyValueAssert VerificationType = "assert"
)

Jump to

Keyboard shortcuts

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