sqlite

package
v2.2.0-rc.2 Latest Latest
Warning

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

Go to latest
Published: Jan 8, 2026 License: Apache-2.0 Imports: 27 Imported by: 4

Documentation

Index

Constants

View Source
const StmtCreateLeafTables = `` /* 318-byte string literal not displayed */

NOTE: we need leaf_idx, so we cannot use `WITHOUT ROWID` because leaf_idx must store the full PRIMARY KEY as their row reference

View Source
const StmtCreateTreeBranchShardTableFormat = `
CREATE TABLE tree_%d (version int, sequence int, bytes blob, orphaned bool, PRIMARY KEY (version, sequence)) WITHOUT ROWID;
`

NOTE: tree_%d should be filled

View Source
const StmtCreateTreeTables = `` /* 245-byte string literal not displayed */

Tables (two databases: branches and leaves)

View Source
const StmtInsertBranchOrphan = `
INSERT OR REPLACE INTO branch_orphan (version, sequence, at) VALUES (?, ?, ?)
`
View Source
const StmtInsertBranchShardFormat = `
INSERT OR REPLACE INTO tree_%d (version, sequence, bytes) VALUES (?, ?, ?)
`

NOTE: Every time we mutate node during balance/set/remove, touched branch nodes always get new node key. But Test_Replay will try to ingest nodes so we should allow REPLACE here.

View Source
const StmtInsertLeaf = `
INSERT OR REPLACE INTO leaf (version, sequence, key_hash, bytes) VALUES (?, ?, ?, ?)
`
View Source
const StmtInsertLeafOrphan = `
INSERT OR REPLACE INTO leaf_orphan (version, sequence, at) VALUES (?, ?, ?)
`
View Source
const StmtInsertRoot = `
INSERT OR REPLACE INTO root(version, node_version, node_sequence, bytes) VALUES (?, ?, ?, ?)
`

Insert

Variables

View Source
var ErrorExportDone = errors.New("export done")

Functions

func FindDbsInPath

func FindDbsInPath(path string) ([]string, error)

func IngestSnapshot

func IngestSnapshot(conn *gosqlite.Conn, prefix string, version int64, nextFn func() (*SnapshotNode, error)) (*inode.Node, error)

func NewIngestSnapshotConnection

func NewIngestSnapshotConnection(snapshotDbPath string) (*gosqlite.Conn, error)

func ToShardID

func ToShardID(version int64) int64

Types

type BranchShardDelete

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

func PrepareBranchShardDelete

func PrepareBranchShardDelete(_ *WriteConn, _ *BranchShards) (*BranchShardDelete, error)

func (*BranchShardDelete) Close

func (sd *BranchShardDelete) Close() error

func (*BranchShardDelete) Exec

func (sd *BranchShardDelete) Exec(version int64, sequence int) error

func (*BranchShardDelete) PrepareVersion

func (sd *BranchShardDelete) PrepareVersion(sql *WriteConn, version int64) error

func (*BranchShardDelete) Reset

func (sd *BranchShardDelete) Reset() error

type BranchShardInsert

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

func PrepareBranchShardInsert

func PrepareBranchShardInsert(sql *WriteConn, shards *BranchShards) (*BranchShardInsert, error)

func (*BranchShardInsert) Close

func (ss *BranchShardInsert) Close() error

func (*BranchShardInsert) EnsureShardTable

func (ss *BranchShardInsert) EnsureShardTable(sql *WriteConn, shardID int64) error

func (*BranchShardInsert) Exec

func (ss *BranchShardInsert) Exec(version int64, sequence int, bz []byte) error

func (*BranchShardInsert) Reset

func (ss *BranchShardInsert) Reset() error

type BranchShardQuery

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

func PrepareBranchShardQuery

func PrepareBranchShardQuery(_ *ReadConn) *BranchShardQuery

func (*BranchShardQuery) Bind

func (sq *BranchShardQuery) Bind(version int64, sequence uint32) (*gosqlite.Stmt, error)

func (*BranchShardQuery) Close

func (sq *BranchShardQuery) Close() error

func (*BranchShardQuery) PrepareVersion

func (sq *BranchShardQuery) PrepareVersion(c *ReadConn, version int64) error

func (*BranchShardQuery) Reset

func (sq *BranchShardQuery) Reset() error

type BranchShards

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

func NewBranchShards

func NewBranchShards(sql *WriteConn) (*BranchShards, error)

type ConnPool

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

func NewConnPool

func NewConnPool(opts *Options, maxPoolSize int, logger logger.Logger) *ConnPool

type ConnectionType

type ConnectionType int
const (
	UseOption ConnectionType = iota
	ReadOnly
	Immutable
)

NOTE: Immutable requires reconnect to see new data

type DB

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

func NewDB

func NewDB(opts Options) (*DB, error)

func NewInMemoryDB

func NewInMemoryDB() (*DB, error)

func (*DB) Close

func (sql *DB) Close() error

func (*DB) DeleteVersionsTo

func (sql *DB) DeleteVersionsTo(toVersion int64) error

func (*DB) DeleteVersionsToSync

func (sql *DB) DeleteVersionsToSync(toVersion int64) error

func (*DB) FinishImport

func (sql *DB) FinishImport() error

func (*DB) GetConn

func (sql *DB) GetConn() (db.ReadConn, error)

func (*DB) GetHeightOneBranchesIteratorQuery

func (sql *DB) GetHeightOneBranchesIteratorQuery(start, end int64) (stmt *gosqlite.Stmt, err error)

func (*DB) GetLatestLeavesIterator

func (sql *DB) GetLatestLeavesIterator(version int64, limit int) (*KVIterator, error)

func (*DB) GetNode

func (sql *DB) GetNode(nodePool *nodepool.NodePool, nodekey inode.NodeKey) (*inode.Node, error)

func (*DB) GetValue

func (sql *DB) GetValue(key []byte, version int64) ([]byte, error)

func (*DB) HasRoot

func (sql *DB) HasRoot(version int64) (bool, error)

func (*DB) ImportMostRecentSnapshot

func (sql *DB) ImportMostRecentSnapshot(targetVersion int64, traverseOrder constants.TraverseOrderType, loadLeaves bool, nodePool *nodepool.NodePool) (*inode.Node, int64, error)

func (*DB) ImportSnapshotFromTable

func (sql *DB) ImportSnapshotFromTable(version int64, traverseOrder constants.TraverseOrderType, loadLeaves bool, nodePool *nodepool.NodePool) (*inode.Node, error)

func (*DB) LatestVersion

func (sql *DB) LatestVersion() (int64, error)

func (*DB) LoadRoot

func (sql *DB) LoadRoot(nodePool *nodepool.NodePool, version int64) (*inode.Node, error)

func (*DB) Path

func (sql *DB) Path() string

func (*DB) PausePruning

func (sql *DB) PausePruning(pause bool)

func (*DB) PrepareImport

func (sql *DB) PrepareImport() error

func (*DB) Readonly

func (sql *DB) Readonly() db.ReadonlyDB

func (*DB) Revert

func (sql *DB) Revert(toVersion int64) error

func (*DB) SaveTree

func (sql *DB) SaveTree(version int64, root *inode.Node, updates *db.DirtyNodes) error

func (*DB) Snapshot

func (sql *DB) Snapshot(ctx context.Context, tree ExpectedTree) error

func (*DB) Type

func (sql *DB) Type() db.Type

func (*DB) WarmLeaves

func (sql *DB) WarmLeaves() error

func (*DB) WriteBatch

func (sql *DB) WriteBatch(importedNodes *db.DirtyNodes) error

func (*DB) WriteSnapshot

func (sql *DB) WriteSnapshot(
	ctx context.Context, version int64, nextFn func() (*SnapshotNode, error), opts SnapshotOptions,
) (*inode.Node, error)

type ExpectedTree

type ExpectedTree interface {
	Version() int64
	Root() *inode.Node
	EnsureLeftNode(*inode.Node) *inode.Node
	EnsureRightNode(*inode.Node) *inode.Node
}

type IterPool

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

func NewIterPool

func NewIterPool(logger logger.Logger) *IterPool

type KVIterator

type KVIterator struct {
	IterPool *IterPool
	// contains filtered or unexported fields
}

func (*KVIterator) Close

func (i *KVIterator) Close() error

func (*KVIterator) Domain

func (i *KVIterator) Domain() (start []byte, end []byte)

func (*KVIterator) Error

func (i *KVIterator) Error() error

func (*KVIterator) Key

func (i *KVIterator) Key() (key []byte)

func (*KVIterator) Next

func (i *KVIterator) Next()

func (*KVIterator) Valid

func (i *KVIterator) Valid() bool

func (*KVIterator) Value

func (i *KVIterator) Value() (value []byte)

type KVStore

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

KVStore is a generic KV store which uses sqlite as the backend and be used by applications to store and retrieve generic key-value pairs, probably for metadata.

func NewSqliteKVStore

func NewSqliteKVStore(opts Options) (kv *KVStore, err error)

func (*KVStore) Delete

func (kv *KVStore) Delete(key []byte) error

func (*KVStore) Get

func (kv *KVStore) Get(key []byte) (value []byte, err error)

func (*KVStore) Set

func (kv *KVStore) Set(key []byte, value []byte) error

type Options

type Options struct {
	Path          string
	Mode          int
	MmapSize      uint64
	WalSize       int
	CacheSize     int
	ConnArgs      string
	TempStoreSize int
	ShardTrees    bool
	MaxPoolSize   int

	BusyTimeout    int
	ThreadsCount   int
	StatementCache int

	Logger  logger.Logger
	Metrics metrics.Proxy

	OptimizeOnStart bool
	// DisableOSThreadLocking disables OS thread locking for write loops
	// Useful in CI environments where thread priority setting may not be available
	DisableOSThreadLocking bool
	// contains filtered or unexported fields
}

func DefaultOptions

func DefaultOptions(opts Options) Options

func (Options) EstimateMmapSize

func (opts Options) EstimateMmapSize() (uint64, error)

type ReadConn

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

func NewMainReadConn

func NewMainReadConn(opts *Options, logger logger.Logger) (*ReadConn, error)

func NewReadConn

func NewReadConn(opts *Options, logger logger.Logger) (*ReadConn, error)

func (*ReadConn) Close

func (c *ReadConn) Close() error

func (*ReadConn) Exec

func (c *ReadConn) Exec(stmt string, args ...any) error

func (*ReadConn) GetNode

func (c *ReadConn) GetNode(pool *nodepool.NodePool, nodekey inode.NodeKey) (*inode.Node, error)

func (*ReadConn) GetValue

func (c *ReadConn) GetValue(version int64, key []byte) ([]byte, error)

func (*ReadConn) IsBusy

func (c *ReadConn) IsBusy() bool

func (*ReadConn) Prepare

func (c *ReadConn) Prepare(statement string, args ...any) (*gosqlite.Stmt, error)

func (*ReadConn) Refresh

func (c *ReadConn) Refresh() error

func (*ReadConn) Release

func (c *ReadConn) Release() error

func (*ReadConn) SetBusy

func (c *ReadConn) SetBusy()

type ReadConnPool

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

func NewReadConnPool

func NewReadConnPool(opts *Options, maxPoolSize int) (*ReadConnPool, error)

NOTE: This pool is primary used for rpc query

func (*ReadConnPool) Close

func (pool *ReadConnPool) Close() error

Close closes all connections in the pool

func (*ReadConnPool) CloseHangingIterators

func (pool *ReadConnPool) CloseHangingIterators() error

func (*ReadConnPool) CloseKVIterstor

func (pool *ReadConnPool) CloseKVIterstor(idx int) error

func (*ReadConnPool) GetConn

func (pool *ReadConnPool) GetConn() (*ReadConn, error)

func (*ReadConnPool) SetSavingTree

func (pool *ReadConnPool) SetSavingTree()

func (*ReadConnPool) UnsetSavingTree

func (pool *ReadConnPool) UnsetSavingTree()

type SnapshotNode

type SnapshotNode struct {
	Key     []byte
	Value   []byte
	Version int64
	Height  int8
}

type SnapshotOptions

type SnapshotOptions struct {
	DontWriteSnapshot bool
	TraverseOrder     constants.TraverseOrderType
}

type WriteBatch

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

type WriteConn

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

func NewWriteConn

func NewWriteConn(opts Options) (*WriteConn, error)

func (*WriteConn) Close

func (conn *WriteConn) Close() error

func (*WriteConn) Revert

func (conn *WriteConn) Revert(version int64) error

func (*WriteConn) SaveRoot

func (conn *WriteConn) SaveRoot(version int64, node *inode.Node) error

type WriteEventLoop

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

func NewWriteEventLoop

func NewWriteEventLoop(sql *WriteConn, logger logger.Logger, metrics metrics.Proxy) (*WriteEventLoop, context.CancelFunc)

func (*WriteEventLoop) SaveTree

func (w *WriteEventLoop) SaveTree(root *inode.Node, version int64, updates *db.DirtyNodes) error

Jump to

Keyboard shortcuts

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