rbf

package
v3.31.0 Latest Latest
Warning

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

Go to latest
Published: Feb 1, 2023 License: Apache-2.0, Apache-2.0 Imports: 25 Imported by: 0

README

Roaring B-tree Format

The RBF format represents a Roaring bitmap whose containers are stored in the leafs of a b-tree. This allows the bitmap to be efficiently queried & updated.

File Format

The RBF file is divided into equal 8KB pages. Each page after the meta page is numbered incrementally from 1 to 2^31.

Pages can be one of the following types:

  • Meta page: contains header information.
  • Branch page: contains pointers to lower branch & leaf pages.
  • Leaf page: contains array and RLE container data.
  • Bitmap page: contains bitmap container data.

All integer values are little endian encoded.

Page header

Every page type except the bitmap page contains the following header:

[4] page number
[4] flags (indicates the type of the page)
Meta page

The meta page contains the following header:

[4]  magic (\xFFRBF)
[4]  flags
[4]  page count
[8]  wal ID
[4]  root records pgno
[4]  freelist pgno
Root Records page

A list of all b-tree names & their respective root page numbers are stored in root record pages. Once a bitmap root is created, it is never moved so the root record pages only need to be rewritten when creating, renaming, or deleting a b-tree. If records exceed the size of a page then they are overflowed to additional pages.

[4] page number
[4] flags
[4] overflow pgno
[*] bitmap records

Each bitmap record is represented as:

[4] pgno
[2] name size
[*] name

All bitmap records are loaded into memory when the file is opened.

Branch page

The branch page contains the following header:

[4] page number
[4] flags
[2] cell count
[*] cell index (2 * cell count)
[*] padding for 4-byte alignment

Each cell is formatted as:

[8] highbits
[4] flags
[4] page number
Leaf page

The leaf page contains the following header:

[4] page number
[4] flags
[2] cell count
[*] cell index (2 * cell count)

The leaf page contains a series of cells with the header of:

[8] highbits
[4] flag
[4] child count
[*] array or RLE data or Handle (a pageno) to Bitmap Data
Bitmap Data page

The data for the bitmap data page takes up the entire 8KB.

Proof of Concept Notes

The following are notes made that are temporary for the RBF format. This will change as development progresses:

  • Transaction support is deferred
  • WAL support is deferred

Pattern of branch splits when adding data in ascending sorted order.

In this example, fan-out is restricted to 2 to make the drawings easy and the splits obvious. The data leaves are only allowed one roaring.Container key (ckey) in this example.

Each frame adds the next datum: A,B,C,D,E,... in order.

The letter represent data leaves, while numbers represent branch pages. The one exception is the first frame where the root is a leaf with data. Every frame after has normal branch at the root.

NB: there are only three places pages get written on addition: a) writeRoot b) putLeafCell c) putBranchCells


add A: root 3 A

add B: root 3 4 5 A B

add C: this sequence of updates occurs

  1. putLeafCell writes leaf B to page 5

  2. putLeafCell writes leaf C to page 6

  3. putBranchCells writes branch page 7 with children 4,5

  4. putBranchCells writes branch page 8 with child 6

  5. writeRoot writes branch cells to pgno 3, children: 7,8

    root 3 7 8 4 5 6 A B C


add D: root
3 7 8 4 5 6 9 A B C D


add E: root 3 12 13 7 8 11 4 5 6 9 10 A B C D E

add F: root 3 12 13 7 8 11 4 5 6 9 10 14 A B C D E F

add G: root 3 12 13 7 8 11 16 4 5 6 9 10 14 15 A B C D E F G

add H: root 3 12 13 7 8 11 16 4 5 6 9 10 14 15 17 A B C D E F G H

add I: root 3 21 22 12 13 20 7 8 11 16 19 4 5 6 9 10 14 15 17 18 A B C D E F G H I

Documentation

Overview

Copyright 2022 Molecula Corp. (DBA FeatureBase). SPDX-License-Identifier: Apache-2.0

Copyright 2022 Molecula Corp. (DBA FeatureBase). SPDX-License-Identifier: Apache-2.0

Copyright 2022 Molecula Corp. (DBA FeatureBase). SPDX-License-Identifier: Apache-2.0

Copyright 2022 Molecula Corp. (DBA FeatureBase). SPDX-License-Identifier: Apache-2.0

Copyright 2022 Molecula Corp. (DBA FeatureBase). SPDX-License-Identifier: Apache-2.0

start with https://github.com/benbjohnson/immutable and specialize Map<uint32,int64>

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Copyright 2022 Molecula Corp. (DBA FeatureBase). SPDX-License-Identifier: Apache-2.0 Package rbf implements the roaring b-tree file format.

Copyright 2022 Molecula Corp. (DBA FeatureBase). SPDX-License-Identifier: Apache-2.0

Copyright 2022 Molecula Corp. (DBA FeatureBase). SPDX-License-Identifier: Apache-2.0

Index

Constants

View Source
const (
	// Magic is the first 4 bytes of the RBF file.
	Magic = "\xFFRBF"

	// PageSize is the fixed size for every database page.
	PageSize = 8192

	// ShardWidth represents the number of bits per shard.
	ShardWidth = 1 << shardwidth.Exponent

	// RowValueMask masks the low bits for a row.
	RowValueMask = ShardWidth - 1

	// ArrayMaxSize represents the maximum size of array containers.
	// This is sligtly less than roaring to accommodate the page header.
	ArrayMaxSize = 4079

	// RLEMaxSize represents the maximum size of run length encoded containers.
	RLEMaxSize = 2039
)
View Source
const (
	PageTypeRootRecord   = 1
	PageTypeLeaf         = 2
	PageTypeBranch       = 4
	PageTypeBitmapHeader = 8  // Only used by the WAL for marking next page
	PageTypeBitmap       = 16 // Only used internally when walking the b-tree
)

Page types.

View Source
const (
	MetaPageFlagCommit   = 1
	MetaPageFlagRollback = 2
)

Meta commit/rollback flags.

View Source
const (
	BitmapN = (1 << 16) / 64
)

Variables

View Source
var (
	ErrTxClosed           = errors.New("transaction closed")
	ErrTxNotWritable      = errors.New("transaction not writable")
	ErrBitmapNameRequired = errors.New("bitmap name required")
	ErrBitmapNotFound     = errors.New("bitmap not found")
	ErrBitmapExists       = errors.New("bitmap already exists")
	ErrTxTooLarge         = errors.New("rbf tx too large")
)
View Source
var Debug bool

Debug is just a temporary flag used for debugging.

View Source
var ErrClosed = errors.New("rbf: database closed")

Functions

func ConvertToLeafArgs

func ConvertToLeafArgs(key uint64, c *roaring.Container) (result leafCell)

func Dumpdot

func Dumpdot(tx *Tx, pgno uint32, parent string, writer io.Writer)

Dumpdot recursively writes the tree representation starting from a given page to STDERR.

func IsBitmapHeader

func IsBitmapHeader(page []byte) bool

func IsMetaPage

func IsMetaPage(page []byte) bool

IsMetaPage returns true if page is a meta page.

func Magic32

func Magic32() uint32

Magic32 returns the magic bytes as a big endian encoded uint32.

func Pagedump

func Pagedump(b []byte, indent string, writer io.Writer)

func RowValues

func RowValues(b []uint64) []uint64

RowValues returns a list of integer values from a row bitmap.

func Walk

func Walk(tx *Tx, pgno uint32, v func(uint32, []*RootRecord))

func WalkPage

func WalkPage(tx *Tx, pgno uint32, walker Walker)

func WalkRootRecordPages

func WalkRootRecordPages(page []byte) uint32

func WriteRootRecord

func WriteRootRecord(data []byte, rec *RootRecord) (remaining []byte, err error)

WriteRootRecord writes a root record with the pgno & name. Returns io.ErrShortBuffer if there is not enough space.

Types

type BitmapPage

type BitmapPage struct {
	*BitmapPageInfo
	Values []uint16
}

type BitmapPageInfo

type BitmapPageInfo struct {
	Pgno   uint32
	Parent uint32
	Tree   string
}

type BranchCell

type BranchCell struct {
	Key   uint64
	Flags uint32
	Pgno  uint32
}

BranchCell represents a branch cell in the public API.

type BranchPage

type BranchPage struct {
	*BranchPageInfo
	Cells []*BranchCell
}

type BranchPageInfo

type BranchPageInfo struct {
	Pgno   uint32
	Parent uint32
	Tree   string
	Flags  uint32
	CellN  int
}

type ContainerType

type ContainerType int
const (
	ContainerTypeNone ContainerType = iota
	ContainerTypeArray
	ContainerTypeRLE
	ContainerTypeBitmap
	ContainerTypeBitmapPtr
)

Container types.

func (ContainerType) String

func (typ ContainerType) String() string

ContainerTypeString returns a string representation of the container type.

type Cursor

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

Cursor represents an object for traversing forward and backward in the keyspace. Users should initialize a cursor with either First(), Last(), or Seek() and then move forward or backward using Next() or Prev(), respectively.

If you mutate the b-tree that a cursor is attached to then you'll need to re-initialize the cursor. This may be changed in the future though.

Cursors can be reused in some cases; if you're keeping a cursor around, be sure to nil out the tx, or it will hold a reference to it.

func (*Cursor) Add

func (c *Cursor) Add(v uint64) (changed bool, err error)

Add sets a bit on the underlying bitmap. If changed is true, this cursor will need to be reinitialized before use.

func (*Cursor) AddRoaring

func (c *Cursor) AddRoaring(bm *roaring.Bitmap) (changed bool, err error)

func (*Cursor) Close

func (c *Cursor) Close()

Close closes a cursor out, invalidating it for future use, and puts it back in a pool to reduce allocations. Contrast with unpooledClose, which you probably shouldn't use.

func (*Cursor) Contains

func (c *Cursor) Contains(v uint64) (exists bool, err error)

Contains returns true if a bit is set on the underlying bitmap.

func (*Cursor) CurrentPageType

func (c *Cursor) CurrentPageType() ContainerType

CurrentPageType returns the type of the container currently pointed to by cursor used in testing sometimes the cursor needs to be positions prior to this call with First/Last etc.

func (*Cursor) Dump

func (c *Cursor) Dump(name string)

func (*Cursor) DumpKeys

func (c *Cursor) DumpKeys()

func (*Cursor) DumpStack

func (c *Cursor) DumpStack()

func (*Cursor) First

func (c *Cursor) First() error

First moves to the first element of the btree. Returns io.EOF if no elements exist. The first call to Next() will not move the position but subsequent calls will move the position forward until it reaches the end and return io.EOF.

func (*Cursor) Key

func (c *Cursor) Key() uint64

Key returns the key for the container the cursor is currently pointing to.

func (*Cursor) Last

func (c *Cursor) Last() error

Last moves to the last element of the btree.

func (*Cursor) Next

func (c *Cursor) Next() error

Next moves to the next element of the btree. Returns EOF if no more elements exist.

func (*Cursor) Prev

func (c *Cursor) Prev() error

Prev moves to the previous element of the btree. Returns io.EOF if at the beginning of the b-tree.

func (*Cursor) Remove

func (c *Cursor) Remove(v uint64) (changed bool, err error)

Remove unsets a bit on the underlying bitmap. If changed is true, the cursor will need to be reinitialized before use.

func (*Cursor) RemoveRoaring

func (c *Cursor) RemoveRoaring(bm *roaring.Bitmap) (changed bool, err error)

func (*Cursor) Row

func (c *Cursor) Row(shard, rowID uint64) (*roaring.Bitmap, error)

func (*Cursor) Rows

func (c *Cursor) Rows() ([]uint64, error)

probably should just implement the container interface but for now i'll do it

func (*Cursor) Seek

func (c *Cursor) Seek(key uint64) (exact bool, err error)

Seek moves to the specified container of the btree. If the container does not exist then it moves to the next container after the key. TODO: what happens if there are no more containers?!?!

func (*Cursor) Values

func (c *Cursor) Values() []uint16

Values returns the values for the container the cursor is currently pointing to.

type DB

type DB struct {

	// Path represents the path to the database file.
	Path string
	// contains filtered or unexported fields
}

DB options like MaxSize, FsyncEnabled, DoAllocZero can be set before calling DB.Open().

func NewDB

func NewDB(path string, cfg *rbfcfg.Config) *DB

NewDB returns a new instance of DB. If cfg is nil we will use the rbfcfg.DefaultConfig().

func (*DB) Begin

func (db *DB) Begin(writable bool) (_ *Tx, err error)

Begin starts a new transaction.

func (*DB) Check

func (db *DB) Check() error

Check performs an integrity check.

func (*DB) Checkpoint

func (db *DB) Checkpoint() error

Checkpoint performs a manual checkpoint. This is not necessary except for tests.

func (*DB) Close

func (db *DB) Close() (err error)

Close closes the database.

func (*DB) DataPath

func (db *DB) DataPath() string

DataPath returns the path to the data file for the DB.

func (*DB) DebugInfo

func (db *DB) DebugInfo() *DebugInfo

func (*DB) HasData

func (db *DB) HasData(requireOneHotBit bool) (hasAnyRecords bool, err error)

HasData with requireOneHotBit=false returns hasAnyRecords true if any record has been stored, even if the value for that bitmap record turned out to have no bits hot (be all zeroes).

In this case, we are taking the attempted storage of any named bitmap into the database as evidence that the db is in use, and we return hasAnyRecords true.

Conversely, if requireOneHotBit is true, then a database consisting of only a named bitmap with an all zeroes (no bits hot) will return hasAnyRecords false. We must find at least a single hot bit inside the db in order to return hasAnyRecords true.

HasData is used by backend migration.

If there is a disk error we return (false, error), so always check the error before deciding if hasAnyRecords is valid.

We will internally create and rollback a read-only transaction to answer this query.

func (*DB) Open

func (db *DB) Open() (err error)

Open opens a database with the file specified in Path. Creates a new file if one does not already exist.

func (*DB) Size

func (db *DB) Size() (int64, error)

Size returns the size of the database & WAL, in bytes.

func (*DB) TxN

func (db *DB) TxN() int

TxN returns the number of active transactions.

func (*DB) WALPath

func (db *DB) WALPath() string

WALPath returns the path to the WAL file.

func (*DB) WALSize

func (db *DB) WALSize() int64

WALSize returns the size of the WAL, in bytes.

type DebugInfo

type DebugInfo struct {
	Path string         `json:"path"`
	Txs  []*TxDebugInfo `json:"txs"`
}

type ErrorList

type ErrorList []error

ErrorList represents a list of errors.

func (*ErrorList) Append

func (a *ErrorList) Append(err error)

Append appends an error to the list. If err is an ErrorList then all errors are appended.

func (ErrorList) Err

func (a ErrorList) Err() error

Err returns the list if it contains errors. Otherwise returns nil.

func (ErrorList) Error

func (a ErrorList) Error() string

func (ErrorList) FullError

func (a ErrorList) FullError() string

type FreePage

type FreePage struct {
	*FreePageInfo
}

type FreePageInfo

type FreePageInfo struct {
	Pgno uint32
}

type LeafCell

type LeafCell struct {
	Key    uint64
	Type   ContainerType
	Pgno   uint32   // bitmap pointer only
	Values []uint16 // array & rle containers only
}

LeafCell represents a leaf cell in the public API.

type LeafPage

type LeafPage struct {
	*LeafPageInfo
	Cells []*LeafCell
}

type LeafPageInfo

type LeafPageInfo struct {
	Pgno   uint32
	Parent uint32
	Tree   string
	Flags  uint32
	CellN  int
}

type MetaPage

type MetaPage struct {
	*MetaPageInfo
}

type MetaPageInfo

type MetaPageInfo struct {
	Pgno             uint32
	Magic            []byte
	PageN            uint32
	WALID            int64
	RootRecordPageNo uint32
	FreelistPageNo   uint32
}

type Metric

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

Metric is a simple, internal metric for check duration of operations.

func NewMetric

func NewMetric(name string, interval int) Metric

func (*Metric) Inc

func (m *Metric) Inc(d time.Duration)

type Nodetype

type Nodetype int
const (
	Branch Nodetype = iota
	Leaf
	Bitmap
)

type Page

type Page interface {
	// contains filtered or unexported methods
}

type PageInfo

type PageInfo interface {
	// contains filtered or unexported methods
}

type PageMap

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

PageMap represents an immutable hash map implementation. The map uses a Hasher to generate hashes and check for equality of key values.

It is implemented as an Hash Array Mapped Trie.

func NewPageMap

func NewPageMap() *PageMap

NewPageMap returns a new instance of PageMap. If hasher is nil, a default hasher implementation will automatically be chosen based on the first key added. Default hasher implementations only exist for int, string, and byte slice types.

func (*PageMap) Delete

func (m *PageMap) Delete(key uint32) *PageMap

Delete returns a map with the given key removed. Removing a non-existent key will cause this method to return the same map.

func (*PageMap) Get

func (m *PageMap) Get(key uint32) (value int64, ok bool)

Get returns the value for a given key and a flag indicating whether the key exists. This flag distinguishes a zero value set on a key versus a non-existent key in the map.

func (*PageMap) Iterator

func (m *PageMap) Iterator() *PageMapIterator

Iterator returns a new iterator for the map.

func (*PageMap) Len

func (m *PageMap) Len() int

Len returns the number of elements in the map.

func (*PageMap) Set

func (m *PageMap) Set(key uint32, value int64) *PageMap

Set returns a map with the key set to the new value. A nil value is allowed.

This function will return a new map even if the updated value is the same as the existing value because PageMap does not track value equality.

type PageMapBuilder

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

PageMapBuilder represents an efficient builder for creating PageMaps.

func NewPageMapBuilder

func NewPageMapBuilder() *PageMapBuilder

NewPageMapBuilder returns a new instance of PageMapBuilder.

func (*PageMapBuilder) Delete

func (b *PageMapBuilder) Delete(key uint32)

Delete removes the given key. See PageMap.Delete() for additional details.

func (*PageMapBuilder) Get

func (b *PageMapBuilder) Get(key uint32) (value int64, ok bool)

Get returns the value for the given key.

func (*PageMapBuilder) Iterator

func (b *PageMapBuilder) Iterator() *PageMapIterator

Iterator returns a new iterator for the underlying map.

func (*PageMapBuilder) Len

func (b *PageMapBuilder) Len() int

Len returns the number of elements in the underlying map.

func (*PageMapBuilder) Map

func (b *PageMapBuilder) Map() *PageMap

Map returns the underlying map. Only call once. Builder is invalid after call. Will panic on second invocation.

func (*PageMapBuilder) Set

func (b *PageMapBuilder) Set(key uint32, value int64)

Set sets the value of the given key. See PageMap.Set() for additional details.

type PageMapIterator

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

PageMapIterator represents an iterator over a map's key/value pairs. Although map keys are not sorted, the iterator's order is deterministic.

func (*PageMapIterator) Done

func (itr *PageMapIterator) Done() bool

Done returns true if no more elements remain in the iterator.

func (*PageMapIterator) First

func (itr *PageMapIterator) First()

First resets the iterator to the first key/value pair.

func (*PageMapIterator) Next

func (itr *PageMapIterator) Next() (key uint32, value int64, ok bool)

Next returns the next key/value pair. Returns a nil key when no elements remain.

type RootRecord

type RootRecord struct {
	Name string
	Pgno uint32
}

func ReadRootRecord

func ReadRootRecord(data []byte) (rec *RootRecord, remaining []byte, err error)

ReadRootRecord reads the page number & name for a root record. If there is not enough space or the pgno is zero then a nil record is returned. Returns the remaining buffer.

type RootRecordPage

type RootRecordPage struct {
	*RootRecordPageInfo
	Records []*RootRecord
}

type RootRecordPageInfo

type RootRecordPageInfo struct {
	Pgno uint32
	Next uint32
}

type Tx

type Tx struct {

	// DeleteEmptyContainer lets us by default match the roaring
	// behavior where an existing container has all its bits cleared
	// but still sticks around in the database.
	DeleteEmptyContainer bool
	// contains filtered or unexported fields
}

Tx represents an RBF transaction. Transactions provide guarantees such as atomicity for all writes that occur as well as serializable isolation. Transactions can be obtained by calling DB.Begin() and provide a snapshot view at the point-in-time they are started.

func (*Tx) Add

func (tx *Tx) Add(name string, a ...uint64) (changeCount int, err error)

Add sets a given bit on the bitmap.

func (*Tx) AddRoaring

func (tx *Tx) AddRoaring(name string, bm *roaring.Bitmap) (changed bool, err error)

func (*Tx) ApplyFilter

func (tx *Tx) ApplyFilter(name string, key uint64, filter roaring.BitmapFilter) (err error)

func (*Tx) ApplyRewriter

func (tx *Tx) ApplyRewriter(name string, key uint64, rewriter roaring.BitmapRewriter) (err error)

func (*Tx) BitmapExists

func (tx *Tx) BitmapExists(name string) (bool, error)

BitmapExist returns true if bitmap exists. Returns an error if name is empty.

func (*Tx) BitmapNames

func (tx *Tx) BitmapNames() ([]string, error)

BitmapNames returns a list of all bitmap names.

func (*Tx) Check

func (tx *Tx) Check() error

Check verifies the integrity of the database.

func (*Tx) Commit

func (tx *Tx) Commit() error

Commit completes the transaction and persists data changes. If this method fails, changes may or may not have been persisted to disk. If no changes have been made during the transaction, this functions the same as a rollback.

Attempting to commit an already committed or rolled back transaction will return an ErrTxClosed error.

func (*Tx) Container

func (tx *Tx) Container(name string, key uint64) (*roaring.Container, error)

Container returns a Roaring container by key.

func (*Tx) ContainerIterator

func (tx *Tx) ContainerIterator(name string, key uint64) (citer roaring.ContainerIterator, found bool, err error)

func (*Tx) Contains

func (tx *Tx) Contains(name string, v uint64) (bool, error)

Contains returns true if the given bit is set on the bitmap.

func (*Tx) Count

func (tx *Tx) Count(name string) (uint64, error)

func (*Tx) CountRange

func (tx *Tx) CountRange(name string, start, end uint64) (uint64, error)

roaring.countRange counts the number of bits set between [start, end).

func (*Tx) CreateBitmap

func (tx *Tx) CreateBitmap(name string) error

CreateBitmap creates a new empty bitmap with the given name. Returns an error if the bitmap already exists.

func (*Tx) CreateBitmapIfNotExists

func (tx *Tx) CreateBitmapIfNotExists(name string) error

CreateBitmapIfNotExists creates a new empty bitmap with the given name. This is a no-op if the bitmap already exists.

func (*Tx) Cursor

func (tx *Tx) Cursor(name string) (*Cursor, error)

Cursor returns an instance of a cursor this bitmap.

func (*Tx) DBPath

func (tx *Tx) DBPath() string

DBPath returns the path to the directory that holds the parent database.

func (*Tx) DebugInfo

func (tx *Tx) DebugInfo() *TxDebugInfo

func (*Tx) DeleteBitmap

func (tx *Tx) DeleteBitmap(name string) error

DeleteBitmap removes a bitmap with the given name. Returns an error if the bitmap does not exist.

func (*Tx) DeleteBitmapsWithPrefix

func (tx *Tx) DeleteBitmapsWithPrefix(prefix string) error

DeleteBitmapsWithPrefix removes all bitmaps with a given prefix.

func (*Tx) Depth

func (tx *Tx) Depth(name string) (int, error)

Depth returns the depth of the b-tree for a bitmap.

func (*Tx) FieldViews

func (tx *Tx) FieldViews() []string

func (*Tx) GetSizeBytesWithPrefix

func (tx *Tx) GetSizeBytesWithPrefix(prefix string) (n uint64, err error)

GetSizeBytesWithPrefix returns the size of bitmaps with a given key prefix.

func (*Tx) GetSortedFieldViewList

func (tx *Tx) GetSortedFieldViewList() (fvs []txkey.FieldView, _ error)

func (*Tx) ImportRoaringBits

func (tx *Tx) ImportRoaringBits(name string, itr roaring.RoaringIterator, clear bool, log bool, rowSize uint64) (changed int, rowSet map[uint64]int, err error)

func (*Tx) Max

func (tx *Tx) Max(name string) (uint64, error)

func (*Tx) Min

func (tx *Tx) Min(name string) (uint64, bool, error)

func (*Tx) OffsetRange

func (tx *Tx) OffsetRange(name string, offset, start, endx uint64) (*roaring.Bitmap, error)

func (*Tx) PageData

func (tx *Tx) PageData(pgno uint32) ([]byte, error)

PageData returns the raw page data for a single page.

func (*Tx) PageInfos

func (tx *Tx) PageInfos() ([]PageInfo, error)

PageInfos returns meta data about all pages in the database.

func (*Tx) PageN

func (tx *Tx) PageN() int

PageN returns the number of pages in the database as seen by this transaction.

func (*Tx) Pages

func (tx *Tx) Pages(pgnos []uint32) ([]Page, error)

Pages returns meta & record data for a list of pages.

func (*Tx) PutContainer

func (tx *Tx) PutContainer(name string, key uint64, ct *roaring.Container) error

PutContainer inserts a container into a bitmap. Overwrites if key already exists.

func (*Tx) Remove

func (tx *Tx) Remove(name string, a ...uint64) (changeCount int, err error)

Remove unsets a given bit on the bitmap.

func (*Tx) RemoveContainer

func (tx *Tx) RemoveContainer(name string, key uint64) error

RemoveContainer removes a container from the bitmap by key.

func (*Tx) RenameBitmap

func (tx *Tx) RenameBitmap(oldname, newname string) error

RenameBitmap updates the name of an existing bitmap. Returns an error if the bitmap does not exist.

func (*Tx) RoaringBitmap

func (tx *Tx) RoaringBitmap(name string) (*roaring.Bitmap, error)

RoaringBitmap returns a bitmap as a Roaring bitmap.

func (*Tx) Rollback

func (tx *Tx) Rollback()

Rollback discards any changes that have been made by the transaction. A commit or rollback must always be called after a transaction finishes. If this is a writable transaction, the write lock will be released on the DB.

func (*Tx) Root

func (tx *Tx) Root(name string) (uint32, error)

Root returns the root page number for a bitmap. Returns 0 if the bitmap does not exist.

func (*Tx) RootRecords

func (tx *Tx) RootRecords() (records *immutable.SortedMap[string, uint32], err error)

RootRecords returns a list of root records.

func (*Tx) SnapshotReader

func (tx *Tx) SnapshotReader() (io.Reader, error)

SnapshotReader returns a reader that provides a snapshot for the current database state.

func (*Tx) Writable

func (tx *Tx) Writable() bool

Writable returns true if the transaction can mutate data. Using transaction methods that attempt to write will return ErrTxNotWritable.

type TxDebugInfo

type TxDebugInfo struct {
	Ptr      string `json:"ptr"`
	Writable bool   `json:"writable"`
	Stack    string `json:"stack,omitempty"`
}

type Walker

type Walker interface {
	Visitor(pgno uint32, records []*RootRecord)
	VisitRoot(pgno uint32, name string)
	Visit(pgno uint32, n Nodetype)
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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