package
0.0.0-20231224052254-3c905e5ef12b
Repository: https://github.com/assetcloud/chain.git
Documentation: pkg.go.dev

# Packages

No description provided by the author
No description provided by the author

# README

数据库配置选项说明

目前支持 leveldbbadger(测试阶段) 两种可选数据库做为 KV 数据存储,默认为 leveldb
参考性能测试:https://github.com/suyanlong/dbcompare 总结出:

  • 优点:
    • badger 在机械硬盘环境下,读写速度和 leveldb 相差不大,但在 SSD 固态硬盘环境下,读写速度都快于 leveldb
    • badger 的 KV 分离存储,所以相同数据情况下 LSM 会更小,可以全部加载到 RAM,提高读写速度
  • 缺点:
    • badger 的 value 是存储在 valuelog 中的,默认超过 1KB 的 value 才会压缩存储,会导致 valuelog 有很多冗余信息(可通过 DB.RunValueLogGC()进行回收),占用磁盘空间会比 leveldb 多

leveldb

选用 leveldb 做为 KV 数据存储
修改 chain.toml 文件中,[blockchain]、[store]、[wallet] 标签中 driver 的值为 leveldb

{
    "driver": "leveldb"
}

badger

选用 badger 做为 KV 数据存储
修改 chain.toml 文件中,[blockchain]、[store]、[wallet] 标签中 driver 的值为 gobadgerdb

{
    "driver": "gobadgerdb"
}
  • 已知 bugs:
    • 在 windows 环境下,系统重启后会因 LOCK 文件已存在,不能启动,需要手动删除 通过修改 vendor/github.com/dgraph-io/badger/dir_windows.go 72 行暂时解决
    • 在 0xff 的情况下,边界测试有问题,详见 db_test.go

实现自定义数据库接口说明

type DB interface {
	Get([]byte) []byte)		// 读
	Set([]byte, []byte)		// 写
	SetSync([]byte, []byte)		// 同步写
	Delete([]byte)			// 同步删除
	DeleteSync([]byte)		// 同步删除
	Close()				// 关闭数据库
	NewBatch(sync bool) Batch 	// 批量操作
	//迭代prefix 范围的所有key value, 支持正反顺序迭代
	Iterator(prefix []byte, key []byte, count int32, reserver bool) Iterator
	// For debugging
	Print()				// 调试打印
	Stats() map[string]string	// 数据库状态
}

type Batch interface {
	Set(key, value []byte)	// 写
	Delete(key []byte)	// 删除
	Write()			// 事务提交
}