zdb

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Oct 14, 2025 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Overview

Package zdb implements a client to 0-db: https://github.com/threefoldtech/0-DB

Index

Constants

View Source
const (
	Prefix = "zdb"
)

Prefix is a string used as prefix in the filesystem volume used to storge 0-db namespaces

Variables

This section is empty.

Functions

func IsZDBVersion1

func IsZDBVersion1(ctx context.Context, root string) (bool, error)

Types

type Client

type Client interface {
	Connect() error
	Close() error
	CreateNamespace(name string) error
	Exist(name string) (bool, error)
	DeleteNamespace(name string) error
	Namespaces() ([]string, error)
	Namespace(name string) (Namespace, error)
	NamespaceSetSize(name string, size uint64) error
	NamespaceSetPassword(name, password string) error
	NamespaceSetMode(name, mode string) error
	NamespaceSetPublic(name string, public bool) error
	NamespaceSetLock(name string, lock bool) error
	DBSize() (uint64, error)
}

Client interface

func New

func New(addr string) Client

New creates a client to 0-db pointed by addr addr format: TODO:

type Header struct {
	Version  uint32
	Name     string
	Password string
	MaxSize  gridtypes.Unit
}

Header is the namespace header

func ReadHeaderV2

func ReadHeaderV2(r io.Reader) (header Header, err error)

ReadHeaderV1 reads namespace header (V1)

type Index

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

Index represent a part of a disk that is reserved to store 0-db data

func NewIndex

func NewIndex(root string) Index

NewIndex creates an Index with root. the root is a directory which has both 'index' and 'data' folders under.

func (*Index) Delete

func (p *Index) Delete(name string) error

Delete both the data and an index of a namespace

func (*Index) Exists

func (p *Index) Exists(name string) bool

Exists checks if a namespace exists in the pool or not this method is way faster then using Namespaces cause it doesn't have to read any data

func (*Index) IndexMode

func (p *Index) IndexMode(name string) (mode IndexMode, err error)

IndexMode return the mode of the index of the namespace called name

func (*Index) Namespace

func (p *Index) Namespace(name string) (info NSInfo, err error)

Namespace gets a namespace info from pool

func (*Index) Namespaces

func (p *Index) Namespaces() ([]NSInfo, error)

Namespaces returns a list of NSinfo of all the namespace present in the pool

func (*Index) Reserved

func (p *Index) Reserved() (uint64, error)

Reserved return the amount of storage that has been reserved by all the namespace in the pool

type IndexHeader

type IndexHeader struct {
	Magic   [4]byte   // four bytes magic bytes to recognize the file
	Version uint32    // file version, for possible upgrade compatibility
	Created uint64    // unix timestamp of creation time
	Opened  uint64    // unix timestamp of last opened time
	Fileid  uint16    // current index file id (sync with dataid)
	Mode    IndexMode // running mode when index was create
}

IndexHeader is the structure contains information about an index adapted from https://github.com/threefoldtech/0-db/blob/development/libzdb/index.h#L31

func ReadIndex

func ReadIndex(r io.Reader) (header IndexHeader, err error)

ReadIndex reads index header

type IndexMode

type IndexMode uint8

IndexMode represens the mode in which the 0-db is running Adapted from https://github.com/threefoldtech/0-db/blob/development/libzdb/index.h#L4

const (
	IndexModeKeyValue    IndexMode = 0
	IndexModeSequential  IndexMode = 1
	IndexModeDirectKey   IndexMode = 2
	IndexModeDirectBlock IndexMode = 3
)

Enum values for IndexMode

func (IndexMode) String

func (i IndexMode) String() string

type NSInfo

type NSInfo struct {
	Name string
	Size gridtypes.Unit
}

NSInfo is a struct containing information about a 0-db namespace

type Namespace

type Namespace struct {
	Name              string         `yaml:"name"`
	DataLimit         gridtypes.Unit `yaml:"data_limits_bytes"`
	DataDiskFreespace gridtypes.Unit `yaml:"data_disk_freespace_bytes"`
	Mode              string         `yaml:"mode"`
	PasswordProtected bool           `yaml:"password"`
	Public            bool           `yaml:"public"`
}

Jump to

Keyboard shortcuts

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