Giter Site home page Giter Site logo

rosedblabs / rosedb Goto Github PK

View Code? Open in Web Editor NEW
4.4K 4.4K 610.0 3.43 MB

Lightweight, fast and reliable key/value storage engine based on Bitcask.

Home Page: https://rosedblabs.github.io

License: Apache License 2.0

Go 100.00%
data-structures database embedded go golang key-value kv-store rosedb throughput

rosedb's People

Contributors

246859 avatar bigdaronlee163 avatar dxyinme avatar gozeloglu avatar guoyuanchao1202 avatar icemint0828 avatar itzmn avatar jaylzhou avatar jeremy-run avatar jimersylee avatar kebukeyi avatar loverhythm1990 avatar nanfeng1999 avatar nc-77 avatar qraffa avatar reid00 avatar rfyiamcool avatar ricardochou avatar roderland avatar roseduan avatar sora233 avatar taiyang-li avatar weijiew avatar wsyingang avatar wudong5 avatar wziww avatar xujiajiadexiaokeai avatar yukinomashiro avatar zaunist avatar zour-ma avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

rosedb's Issues

build problems

Hello,

Using: go version go1.16 windows/amd64

I just tried to build RoseDB, but have errors:

C:\goprojects\src\RoseDB\test>go build cmd\server\main.go
cmd\grpc_server.go:6:2: no required module provides package github.com/roseduan/rosedb/cmd/proto; to add it:
go get github.com/roseduan/rosedb/cmd/proto

C:\goprojects\src\RoseDB\test>go get github.com/roseduan/rosedb/cmd/proto
go get github.com/roseduan/rosedb/cmd/proto: no matching versions for query "upgrade"

mmap写文件,每个文件只有一个entry

bug现象:

使用mmap方式set一个kv,在0.data.str文件中会写入一个二进制entry;再次使用mmap set一个kv,该kv会写入1.data.str文件的开头,而不是继续在0.data.str中继续写入。
这导致16mb的0.data.str文件中,只有一个entry,剩余绝大部分空间都没有使用。并且每set一次不同的k,就会多一个文件。

bug原因:

文件offset数值错误。这发生在NewDBFile方法中的mmap逻辑中:
一开始我们让offset相当于文件的大小,但其实Truncate会将文件以'\0'填满,所以对于mmap来说,offset永远指的是文件固定大小,而不是实际entry要存储的位置。
由于存储逻辑中,会根据offset判断文件容量达到上限创建新文件存储entry,这就导致set新的k,会创建新的文件。

stat, err := file.Stat()
	if err != nil {
		return nil, err
	}

	df := &DBFile{Id: fileId, Path: path, Offset: stat.Size(), method: method}

	if method == FileIO {
		df.File = file
	} else {
		if err = file.Truncate(blockSize); err != nil {
			return nil, err
		}
		m, err := mmap.Map(file, os.O_RDWR, 0)
		if err != nil {
			return nil, err
		}
		df.mmap = m
	}

[feature] 关于支持 hint file

hint file 是 bitcask 中对于启动时,建立索引的一种优化手段。
如果 db 存在大量的数据文件,那么再次打开 db 时,必须重新扫描所有数据文件重建索引,这样的效率是十分低下的,因此 bitcask 提出了 hint file 保存索引文件来帮助 db 进行快速启动。

本人自告奋勇想为 rosedb 实现 hint file 这个 feature,故开此 issue 来听取大家意见,为 rosedb 略尽绵薄之力。

A milestone!

rosedb has reached 1k stars after first commit in 2020.12.06 👏
This is awesome, thanks for your support, I will continue to do it better.

How to contribute?

简体中文

Familiar with Pull Request

  • add Test Case
  • add example code

There are no Test methods for some API in rosedb, you can add test cases according to the existed.

And you can also add some example code to show users how to use rosedb(under examples dir).
https://github.com/flower-corp/rosedb/tree/main/examples

This kind PRs only aims to let you deep into rosedb and understand more about how it works.

Easy problems

  • add more Redis commands
  • good first issue
  • add Redis command

The commands in rosedb are most similar to Redis, our goal is to support the most frequently used commands in Redis, and make sure the command does not exist in rosedb before you add it.

Redis commands docs: https://redis.io/commands

If an issue is marked with good first issue, it is suitable for newcomers, you can pick one which you are interested in or good at.

Now rosedb has supported Redis protocol, but some commands are missed, so you can add the command:

  • find variable supportedCommands in cmd/cli.go, which lists all supported commands and its handler function
  • find a method in rosedb not listed here
  • add the command and its handler function

Fix bugs or add/enhance features

If an issue is marked with bug or enhancement, which means bug fix or add/enhance features, you might have to understand completely rosedb to solve it.

Note

every issue is marked with its difficulty(easy, medium, hard), you can pick them according to your understanding of rosedb, and if you have any problems, contact me as soon.

windows10 生成pb文件注意事项?

环境

protoc-gen-go v1.27.1
protoc        v3.19.1
go1.173

windows生成pb文件命令

protoc --go-grpc_out=.  cmd/proto/rosedb.proto
protoc --go-grpc_out=.  cmd/proto/pb_set.proto
protoc --go-grpc_out=.  cmd/proto/pb_hash.proto
protoc --go-grpc_out=. cmd/proto/pb_zset.proto
protoc --go-grpc_out=.  cmd/proto/pb_str.proto
protoc --go-grpc_out=.  cmd/proto/pb_list.proto

高版本可能会遇到下面错误
image
参考文章
grpc with mustEmbedUnimplemented*** method
mustEmbedUnimplemented*** method appear in grpc-server
protoc-gen-go-grpc: program not found or is not executable

因此解决方案

protoc  --go-grpc_opt=require_unimplemented_servers=false --go-grpc_out=. cmd/proto/rosedb.proto
protoc --go-grpc_out=.  cmd/proto/rosedb.proto
protoc --go-grpc_out=.  cmd/proto/pb_set.proto
protoc --go-grpc_out=.  cmd/proto/pb_hash.proto
protoc --go-grpc_out=. cmd/proto/pb_zset.proto
protoc --go-grpc_out=.  cmd/proto/pb_str.proto
protoc --go-grpc_out=.  cmd/proto/pb_list.proto

image

space bug

for example,if I print the command : "set hello world",When the number of spaces between 'hello' and 'world' exceeds one, an error occurs。This is because spaces occupy the length of a parameter, and the number of parameters in the code is limited to two. In order to solve this problem, you should remove spaces from the input parameters before judging

希望志同道合的朋友参与 rosedb

rosedb 目前还非常的不完善,因此我希望有更多的人可以参与进来,不管你是 DB 的爱好者,或者是专家,甚至刚入门的小白,其实都能够对 rosedb 进行相关的贡献。

目前项目还比较缺人,如果有意愿的话,欢迎加我 vx:kiss_duan 进行交流!

我应该怎么获取 grpc.ClientConnInterface

我想尝试一下 grpc 方式操作 rosedb,但是 grpc.ClientConnInterface 这个应该怎么通过 grpc 获取到。

        // 这个 conn 是 grpc.ClientConn()
	conn ,err := grpc.Dial("127.0.0.1:5300", grpc.WithInsecure)
	if err !=nil{
		return 
	}
	defer conn.Close()
        // 这里 NewRosedbClient() 需要传入 grpc.ClientConnInterface 
	cli := proto.NewRosedbClient()

求该项目的参考论文

我在B站上刷到你的视频,对这个项目非常感兴趣,能不能在readme里面添加上你这个项目的参考论文,我挺想拜读一下源论文的,万分感谢。

关于将list、set、hash、zset 接口支持interface的问题

如果希望list、set、hash、zset 接口支持interface, 那么是否需要在编码函数即EncodeValue函数中,支持多类型的编码,同时在list、set、hash、zset 的结构体内将支持String的结构 修改为 interface{} 结构 ?

redis-cli command error

redis-cli connection success, but command exec fail. rosedb-cli success.

image

image

image

redis-cli version: 6.2.6

db_str的bug

func TestRoseDB_GetSet(t *testing.T) {
	t.Run("1", func(t *testing.T) {
		err := roseDB.Set(123, 456)
		assert.Empty(t, err)

		var res int
		err = roseDB.GetSet(123, 567, &res)
		assert.Empty(t, err)
		assert.Equal(t, res, 456)

		var r2 int
		err = roseDB.Get(123, &r2)
		assert.Empty(t, err)
		assert.Equal(t, r2, 567) // will raise a bug r2 = 456 not 567
	})

	t.Run("2", func(t *testing.T) {
		var res interface{}
		err := roseDB.GetSet(123, 222, &res)
		assert.Equal(t, err, nil)
	})
}
beacause for r2 get. it get data from cache. but 567 not write into cache
this bug i can fit it.

Is RoseDB embeddable?

Do I understand correctly in that RoseDB is embeddable for key-value systems?

Do you have any simple examples?

If so, then I think that I might like to try it in m current P2P Cord code system to see how it performs across a number of nodes.

Thanks.

The todo list and problems of rosedb, create your first PR from here!

This is a todo list that we are doing or prepare to do, you can pick a few yuo are interested in, and create a new issue, tell what you think, and receive some advices from other people.
Then you can give us a PR!

Urgent and have to do:

  1. When there are a lage of data files, open the db may be slow. Because redundant entries may be exist, and we have to load them all. Solutions we have think:
  • create hint file that not contains redundant entry to help creating the indexes while opening a db.
  • five different data structures will be written to different db files, and load them concurrently.(Has done by @roseduan, is it a good idea? :)
  1. Reclaim(merge the data files) operation will block the read of String in KeyOnlyRam mode, because the values are in data file, not in memory. And we think the reclaim operation will not block any read/write, do you have any good solutions?
  2. For the List data structure, maybe very slow while reclaiming or opening, because we have to iterate all keys to judge whether a single entry is valid.
  3. Support TTL of all data structures(Only string now).

Not urgent do it selectively:

  1. Batch write, avoid lock/unlock every time.
  2. Support interface{} instead of byte array for the methods.
  3. Transaction, ACID features.
  4. Cache the frequently accessed key.

如何参与 rosedb ?

熟悉 Pr 流程

  • 添加 test 方法
  • 添加 example 代码

目前 rosedb 当中的一些方法是没有对应的 Test 方法的,你可以按照已有的 Test,来为方法添加单元测测试。rosedb 下有一个 examples 目录,向用户展示 rosedb 的使用方法,你可以往其中添加一个方法。

这类 Pr 没有太多的技巧可言,只是为了让你熟悉整个 Pr 的流程,并且能够对 rosedb 中的一些方法有所认识,对 rosedb 的数据读写流程有更进一步的理解。

简单问题

  • 为 rosedb 添加更多 redis 相关的命令
  • good first issue
  • 添加 redis 协议中的方法

rosedb 支持的命令目前大致是按照 redis 来添加的,我们做到能够支持 redis 大多数常用的命令即可,做之前要确认一下这个命令在 rosedb 当中是不存在的。

尽量选择 redis 一些常用的命令,不常用的可以暂时不支持。

如果一个 issue 被标识为了 good first issue,则说明这个 issue 也很适合新手参与,你可以按照自己的情况选择自己感兴趣或擅长的。

目前 rosedb 支持了 redis 协议,但是对应的方法并不完整,你可以为 rosedb 添加一个对应的 redis 协议的方法,具体做法是:

  • 找到 cmd/server.go 中的 supportedCommands 变量,这里是所有支持的命令及其对应的处理方法
  • 选择一个在 rosedb 当中已经实现了而在这里又没有的方法
  • supportedCommands 中增加这个方法的名称,并添加对应的处理方法

说明:redis 协议的方法的输出尽量和原生 redis 保持一致

bug 修改或功能完善/增强

  • bug
  • enhancement

如果有一些 bug 或者新的功能,或是对已有功能进行完善,这类 issue 会被标识为 bugenhancement,这类问题可能稍微复杂点,需要你对 rosedb 整体的流程更加熟悉。

最后

每个 issue 都标识了该问题的难易程度(easy、medium、hard),你可以根据自己对 rosedb 的了解程度,选择适合自己的,对于任何问题或者 issue,在做之前,或者做的过程当中有问题的话,都可以提出来和我交流。

我想试用一下 rosedb 的 grpc 接口,有可用的例子吗?

我的代码如下:

import (
	"context"
	"fmt"

	"github.com/roseduan/rosedb/cmd/proto"
	"google.golang.org/grpc"
)

func run() {
	ctx := context.Background()
	conn, err := grpc.DialContext(ctx, "127.0.0.1:5300", grpc.WithInsecure())
	if err != nil {
		return
	}
	defer conn.Close()
	cli := proto.NewRosedbClient(conn)

	var s proto.GetReq
	s.Key = []byte("myk")
	var opt grpc.CallOption
        // 这里会报空指针错误。
	test, err := cli.Get(ctx, &s, opt)
	if err != nil {
		return
	}
	fmt.Println(test.Dest)

}

范围查询性能太差了吧

bitdask模型应该只是时候用于大value,或者value存小文件的场景吧,而且就算用跳表做了索引,但是范围查询的时候,还是每个value的读取都是一次随机磁盘读,比mysql的“一次读一个页”到内存差很多啊,这样实现性能太差了,这样实现的话,感觉还不如退化成b+树的mysql呢

Adding GitHub Actions

What do you think about adding GitHub Actions to the repository? At least, it can be basic like only builds and tests. GitHub provides the templates for the Go language.

Sharding for P2P model?

Hello,

I have just come across RoseDB and think that it might be what I need for a project that I am working on.

One thing that I am needing is to develop for a P2P solution for the database with high number of nodes and am wondering about what it might take to have simple sharding added to RoseDB so that it can do high node clustering and spread out the data across all nodes as needed?

关于 redis-cli 命令实现的问题

是否可以罗列一下现在已经实现的 redis-cli 命令,和未实现的命令。

我想尝试实现一些 redis-cli 命令,不知道这个项目是否有规划。

a type use error./golangci-lint

cmd/cmd_str.go:159:38: cannot use uint32(seconds) (value of type uint32) as int64 value in argument to db.Expire

建议使用golangci-lint去避免简单错误。

性能有点差

image

作为无序hashtable storage engine,速度应该可以更快的

事务id重复问题

重启项目时事务id将会从最后一次成功的事务id开始递增,如果最后一次成功事务之后存在失败的事务,则会造成id重复

Crash resilience

请问,有测试过在各平台上(Linux/Windows)突然断电或者程序突然结束的情况下的表现吗?

现在手上有个项目在用badgerdb,但是在Windows下突然断电或者退出程序会导致数据库损坏无法启动,正在找一个替换的方案。

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.