index

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Mar 20, 2022 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrColumnFamilyNameNil column family name is nil.
	ErrColumnFamilyNameNil = errors.New("column family name is nil")

	// ErrBucketNameNil bucket name is nil.
	ErrBucketNameNil = errors.New("bucket name is nil")

	// ErrDirPathNil indexer dir path is nil.
	ErrDirPathNil = errors.New("indexer dir path is nil")

	// ErrOptionsTypeNotMatch indexer options not match.
	ErrOptionsTypeNotMatch = errors.New("indexer options not match")
)

Functions

func EncodeMeta

func EncodeMeta(m *IndexerMeta) []byte

EncodeMeta encode IndexerMeta as byte array.

Types

type BPTree

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

BPTree is a standard b+tree used to store index data.

func NewBPTree

func NewBPTree(opt BPTreeOptions) (*BPTree, error)

NewBPTree create a boltdb instance. A file can only be opened once. if not, file lock competition will occur.

func (*BPTree) Close

func (b *BPTree) Close() error

Close close bolt db.

func (*BPTree) Delete

func (b *BPTree) Delete(key []byte) error

Delete a specified key from indexer.

func (*BPTree) DeleteBatch

func (b *BPTree) DeleteBatch(keys [][]byte, opts WriteOptions) error

DeleteBatch delete data in batch.

func (*BPTree) Get

func (b *BPTree) Get(key []byte) (*IndexerMeta, error)

Get reads the value from the bucket with key.

func (*BPTree) Put

func (b *BPTree) Put(key, value []byte) (err error)

Put method starts a transaction. This method writes kv according to the bucket, and creates it if the bucket name does not exist.

func (*BPTree) PutBatch

func (b *BPTree) PutBatch(nodes []*IndexerNode, opts WriteOptions) (offset int, err error)

PutBatch is used for batch writing scenarios. The offset marks the transaction write position of the current batch. If this function fails during execution, we can write again from the offset position. If offset == len(kv) - 1 , all writes are successful.

func (*BPTree) Sync

func (b *BPTree) Sync() error

Sync executes fdatasync() against the database file handle.

type BPTreeOptions

type BPTreeOptions struct {
	// DirPath path to store index data.
	DirPath string
	// IndexType bptree(bolt).
	IndexType IndexerType
	// ColumnFamilyName db column family name, must be unique.
	ColumnFamilyName string
	// BucketName usually the the same as column family name, must be unique.
	BucketName []byte
	// BatchSize flush batch size.
	BatchSize int
	// DiscardChn if values in indexer are changed, the older value will be send to the DiscardChn.
	// Values will be handled in discard.go/listenUpdates().
	DiscardChn chan [][]byte
}

BPTreeOptions options for creating a new bptree.

func (*BPTreeOptions) GetColumnFamilyName

func (bo *BPTreeOptions) GetColumnFamilyName() string

GetColumnFamilyName self-explanatory.

func (*BPTreeOptions) GetDirPath

func (bo *BPTreeOptions) GetDirPath() string

GetDirPath self-explanatory.

func (*BPTreeOptions) GetType

func (bo *BPTreeOptions) GetType() IndexerType

GetType self-explanatory.

func (*BPTreeOptions) SetColumnFamilyName

func (bo *BPTreeOptions) SetColumnFamilyName(cfName string)

SetColumnFamilyName self-explanatory.

func (*BPTreeOptions) SetDirPath

func (bo *BPTreeOptions) SetDirPath(dirPath string)

SetDirPath self-explanatory.

func (*BPTreeOptions) SetType

func (bo *BPTreeOptions) SetType(typ IndexerType)

SetType self-explanatory.

type Indexer

type Indexer interface {
	Put(key []byte, value []byte) (err error)

	PutBatch(kv []*IndexerNode, opts WriteOptions) (offset int, err error)

	Get(key []byte) (meta *IndexerMeta, err error)

	Delete(key []byte) error

	DeleteBatch(keys [][]byte, opts WriteOptions) error

	Sync() error

	Close() (err error)
}

Indexer index data are stored in indexer.

func NewIndexer

func NewIndexer(opts IndexerOptions) (Indexer, error)

NewIndexer create a new Indexer by the given options, return an error, if any.

type IndexerIter

type IndexerIter interface {
	// First moves the cursor to the first item in the bucket and returns its key and value.
	// If the bucket is empty then a nil key and value are returned.
	First() (key, value []byte)

	// Last moves the cursor to the last item in the bucket and returns its key and value.
	// If the bucket is empty then a nil key and value are returned.
	Last() (key, value []byte)

	// Seek moves the cursor to a given key and returns it.
	// If the key does not exist then the next key is used. If no keys follow, a nil key is returned.
	Seek(seek []byte) (key, value []byte)

	// Next moves the cursor to the next item in the bucket and returns its key and value.
	// If the cursor is at the end of the bucket then a nil key and value are returned.
	Next() (key, value []byte)

	// Prev moves the cursor to the previous item in the bucket and returns its key and value.
	// If the cursor is at the beginning of the bucket then a nil key and value are returned.
	Prev() (key, value []byte)

	// Close The close method must be called after the iterative behavior is over!
	Close() error
}

IndexerIter .

type IndexerMeta

type IndexerMeta struct {
	Value     []byte
	Fid       uint32
	Offset    int64
	EntrySize int
}

IndexerMeta meta info of a key. If value exists, it means both key and value will be stored in indexer. If not, we will store some info(Fid, Size, Offset) to find the value in value log.

func DecodeMeta

func DecodeMeta(buf []byte) *IndexerMeta

DecodeMeta decode meta byte as IndexerMeta.

type IndexerNode

type IndexerNode struct {
	Key  []byte
	Meta *IndexerMeta
}

IndexerNode represents the value stored in indexer, including Key and Meta info,

type IndexerOptions

type IndexerOptions interface {
	SetType(typ IndexerType)

	SetColumnFamilyName(cfName string)

	SetDirPath(dirPath string)

	GetType() IndexerType

	GetColumnFamilyName() string

	GetDirPath() string
}

IndexerOptions options of creating a new indexer.

type IndexerType

type IndexerType int8

IndexerType type of indexer.

const (
	// BptreeBoltDB represents indexer using bptree.
	BptreeBoltDB IndexerType = iota
)

type WriteOptions

type WriteOptions struct {
	SendDiscard bool
}

WriteOptions options for updates batch.

Jump to

Keyboard shortcuts

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