Documentation
¶
Index ¶
- func BuntdbKeyExists(db *buntdb.DB, key string) (bool, error)
- func BuntdbKeysAllExists(db *buntdb.DB, keys []string) (bool, error)
- func NewBuntdb(dbName string, faster bool) (*buntdb.DB, error)
- func NewSqliteDb(ctx context.Context, dbPath string, customLogger logger.Interface) (*gorm.DB, error)
- func SyncMemToFile(memDb *buntdb.DB, fileDb *NutsdbInfo) error
- type NutsdbInfo
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NewBuntdb ¶
NewBuntdb 创建buntdb数据库,容量受内存大小限制 dbName: 数据库文件名,如果为空,则使用内存模式 faster: true 快速模式,长时间间隔写盘+手动写盘和压缩 faster: false 慢速模式,间隔一秒写盘+自动压缩 外部需要执行 db.Close()、db.Shrink()或db.Save()
func NewSqliteDb ¶
func NewSqliteDb(ctx context.Context, dbPath string, customLogger logger.Interface) (*gorm.DB, error)
NewSqliteDb 初始化数据库
func SyncMemToFile ¶
func SyncMemToFile(memDb *buntdb.DB, fileDb *NutsdbInfo) error
方案2:全量同步 操作缓慢且影响内存数据库的性能,需要在业务低峰期执行(比如:中午休息时间) 读性能无损:快照读取不影响主库写入速度 写性能损耗:仅来自版本树维护(约 3-5%) 假设数据库含 100 万条记录: 全量遍历耗时 ≈ 50ms~200ms 在此期间可能发生: 1. 已遍历的键被修改(数据版本不一致) 2. 新键插入(数据遗漏) 3. 未遍历的键被删除(数据丢失)
Types ¶
type NutsdbInfo ¶
func NewNutsdb ¶
func NewNutsdb(dbName string, bucketNumber int, faster bool) (*NutsdbInfo, error)
NewNutsdb 创建nutsdb数据库,容量受磁盘大小限制 bucketNumber 分片数,一旦定下来,不能修改,否则出现数据获取不到 外部需要执行 db.Close() 若对一个key频繁操作,择机执行db.Merge()
func (*NutsdbInfo) GetShardBucket ¶
func (n *NutsdbInfo) GetShardBucket(key []byte) string
推荐分片数 = (预估最大活跃连接数 × 2) / CPU核心数 其他hash库:"github.com/cespare/xxhash/v2"
func (*NutsdbInfo) GetShardBucket2 ¶
func (n *NutsdbInfo) GetShardBucket2(key []byte) string
Click to show internal directories.
Click to hide internal directories.