flydb

package module
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: May 9, 2023 License: Apache-2.0 Imports: 14 Imported by: 0

README

FlyDB

English | 简体中文

FlyDB is a simple and lightweight kv-type database written in Go. It provides an easy-to-use API that allows users to store and retrieve data in their applications.

Note: This project is currently under iterative development and should not be used in production environments!

Introduction

FlyDB is a fast and easy-to-use kv-type database based on bitcask, designed to be lightweight and simple. With FlyDB, you can easily store and retrieve data in your Go applications. FlyDB is optimized for speed, making it ideal for applications that require fast data access.

Features

Some features of FlyDB include:

  • Easy to use: FlyDB provides a simple and intuitive API that makes storing and retrieving data very easy.

  • Lightweight: FlyDB is designed to be lightweight and efficient, making it ideal for use in resource-constrained environments.

  • Reliable: FlyDB supports transactional operations, ensuring that data is not lost or corrupted during the storage process.

  • Fast: FlyDB uses in-memory data structures, making it fast and responsive, especially for applications that require fast read/write speeds.

  • Scalable: FlyDB provides many configurable options that allow users to adjust its performance and features to suit different usage scenarios.

Installation

You can install FlyDB using the Go command line tool:

go get github.com/qishenonly/flydb

Or clone this project from GitHub:

git clone https://github.com/qishenonly/flydb

Usage

Here is a simple Linux usage example:

package main

import (
	"fmt"
	"github.com/qishenonly/flydb"
)

func main() {
	options := flydb.DefaultOptions
	options.DirPath = "/tmp/flydb"
	db, _ := flydb.NewFlyDB(options)

	db.Put([]byte("name"), []byte("flydb-example"))

	val, err := db.Get([]byte("name"))
	if err != nil {
		fmt.Println("name value => ", string(val))
	}

}

For more detailed usage, please refer to the flydb/examples directory.

Contact

If you have any questions or want to contact us, you can reach out to our development team and we will respond to your email promptly:

Team email: jiustudio@qq.com

Or add my wechat account and invite you to join the project community to exchange and learn with Daniu.

Note when adding wechat : Github

vx

Contributions

If you have any ideas or suggestions for FlyDB, please feel free to submit issues or pull requests on GitHub. We welcome your contributions!

For full contributing guidelines, please refer to CONTRIBUTING

License

FlyDB is released under the Apache license. For more information, please see the LICENSE file.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrKeyIsEmpty             = errors.New("KeyEmptyError : the key is empty")
	ErrIndexUpdateFailed      = errors.New("IndexUpdateFailError : failed to update index")
	ErrKeyNotFound            = errors.New("KeyNotFoundError : key is not found in database")
	ErrDataFailNotFound       = errors.New("DataFailNotFoundError : data file is not found")
	ErrDataDirectoryCorrupted = errors.New("DataDirectoryCorruptedError : the databases directory maybe corrupted")
	ErrExceedMaxBatchNum      = errors.New("ExceedMaxBatchNumError : exceed the max batch num")
	ErrMergeIsProgress        = errors.New("MergeIsProgressError : merge is in progress, try again later")

	ErrOptionDirPathIsEmpty          = errors.New("OptionDirPathError : database dir path is empty")
	ErrOptionDataFileSizeNotPositive = errors.New("OptionDataFileSizeError : database data file size must be greater than 0")
)
View Source
var DefaultIteratorOptions = IteratorOptions{
	Prefix:  nil,
	Reverse: false,
}
View Source
var DefaultOptions = Options{
	DirPath:      os.TempDir(),
	DataFileSize: 256 * 1024 * 1024,
	SyncWrite:    false,
	IndexType:    Btree,
}
View Source
var DefaultWriteBatchOptions = WriteBatchOptions{
	MaxBatchNum: 10000,
	SyncWrites:  true,
}

Functions

This section is empty.

Types

type DB

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

DB bitcask 存储引擎实例

func NewFlyDB

func NewFlyDB(options Options) (*DB, error)

NewFlyDB 打开 bitcask 存储引擎实例

func (*DB) Close

func (db *DB) Close() error

Close 关闭数据库

func (*DB) Delete

func (db *DB) Delete(key []byte) error

func (*DB) Fold

func (db *DB) Fold(f func(key []byte, value []byte) bool) error

Fold 获取所有的数据,并执行用户指定的操作,函数返回 false 退出

func (*DB) Get

func (db *DB) Get(key []byte) ([]byte, error)

Get 根据 key 读取数据

func (*DB) GetListKeys

func (db *DB) GetListKeys() [][]byte

GetListKeys 获取数据库中所有的 key

func (*DB) Merge

func (db *DB) Merge() error

Merge 清理无效数据,生成 hint 索引文件

func (*DB) NewIterator

func (db *DB) NewIterator(opt IteratorOptions) *Iterator

NewIterator 初始化迭代器

func (*DB) NewWriteBatch

func (db *DB) NewWriteBatch(opt WriteBatchOptions) *WriteBatch

NewWriteBatch 初始化 WriteBatch

func (*DB) Put

func (db *DB) Put(key []byte, value []byte) error

Put 写入key/value, key不能为空

func (*DB) Sync

func (db *DB) Sync() error

Sync 持久化数据文件

type IndexerType

type IndexerType = int8
const (
	// Btree 索引
	Btree IndexerType = iota + 1

	// ART (Adpative Radix Tree) 自适应基数树
	ART
)

type Iterator

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

Iterator 迭代器

func (*Iterator) Close

func (it *Iterator) Close()

func (*Iterator) Key

func (it *Iterator) Key() []byte

func (*Iterator) Next

func (it *Iterator) Next()

func (*Iterator) Rewind

func (it *Iterator) Rewind()

func (*Iterator) Seek

func (it *Iterator) Seek(key []byte)

func (*Iterator) Valid

func (it *Iterator) Valid() bool

func (*Iterator) Value

func (it *Iterator) Value() ([]byte, error)

type IteratorOptions

type IteratorOptions struct {
	// 遍历前缀为指定值的 Key,默认为空
	Prefix []byte
	// 是否反向遍历,默认 false 是正向
	Reverse bool
}

IteratorOptions 索引迭代器配置项

type Options

type Options struct {
	DirPath      string //数据库数据目录
	DataFileSize int64  //数据文件的大小
	SyncWrite    bool   // 每次写数据是否持久化
	IndexType    IndexerType
}

type WriteBatch

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

WriteBatch 原子批量写数据,保证操作原子性

func (*WriteBatch) Commit

func (wb *WriteBatch) Commit() error

Commit 事务提交,将暂存的数据写入数据文件,并更新内存索引

func (*WriteBatch) Delete

func (wb *WriteBatch) Delete(key []byte) error

Delete 数据批量删除

func (*WriteBatch) Put

func (wb *WriteBatch) Put(key []byte, value []byte) error

Put 数据批量写入

type WriteBatchOptions

type WriteBatchOptions struct {
	// 一个批次当中最大的数据量
	MaxBatchNum uint
	// 提交时是否 sync 持久化
	SyncWrites bool
}

WriteBatchOptions 批量写入配置项

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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