Talent Plan KV学习营
对于Talent Plan KV训练营
我想我有必要介绍一下,这是PingCAP
公司推出的一套开源分布式KV
存储实战课程,这课程一共蕴含了4
子项目:
Project 1
须要参与者独立实现一个单机的KV Server
Project 2
须要基于Raft
算法实现分布式键值数据库服务端Project 3
须要在Project 2
的根底上反对多个Raft
集群Project 4
须要Project 3
的根底上反对分布式事务
难度都是阶梯式的,如果能实现tinykv
所有子项目,产出一个分布式kv
数据库,置信这也是一个很大的播种,据我所知目前也就麻省理工学院
有一套MIT 6.824
课程,Ping Cap
推出这套tinykv
课程也是相当于补救了国内这块课程的空白了。
我以后加入的本次我的项目要求的是Go
语言去实现这些Lab
,或者读者你看到这篇文章的时候可能换到其余语言上了比如说Rust
,当然至于用什么编程语言
去实现,都是不重要的问题,重要的是在论文
浏览局部,这就好比你看懂了一栋大楼的设计图纸,而后语言就是一个堆砖头的工具。
- 论文地址:https://github.com/kvbase/raft-thesis-zh_cn
因为举办方要求参赛者不得以任何形式间接贴每个我的项目的答案代码,当然我认为这么做是对的,然而举办方激励参赛者写一些对于实现lab
的解题思路分享,早晨抽时间把第一个lab
实现了,本文这篇将写写Project 1
的怎么入坑的。
Standalone KV Server
第一个lab
是一个典型的TDD
开发的例子,什么是TDD
如果读者不理解本人去Google
吧。Project 1
是要基于BadgerDB
作为存储引擎的去实现出题者预留的API
接口的,而后官网在我的项目根目录建了一个makefile
文件,参与者只须要make project1
即可查看Project 1
实现状况。
BadgerDB
是dgraph.io
开发的一款基于Log Structured Merge (LSM) Tree
的key-value
本地数据库, 应用Go
开发。
开发这个我的项目你得须要有Go mod
根底,没有本人去补吧。
执行了make project1
能够看到抛出了一大堆异样,这些异样起因就是官网工程师给你写的单元测试没有跑通过,你要做的只须要把/tinykv/kv/server/server_test.go
下的所有的单元测试用例调用的api
外面的性能实现即可。
- 第一个你要实现的
package standalone_storageimport ( "github.com/pingcap-incubator/tinykv/kv/config" "github.com/pingcap-incubator/tinykv/kv/storage" "github.com/pingcap-incubator/tinykv/proto/pkg/kvrpcpb")// StandAloneStorage is an implementation of `Storage` for a single-node TinyKV instance. It does not// communicate with other nodes and all data is stored locally.type StandAloneStorage struct { // Your Data Here (1).}func NewStandAloneStorage(conf *config.Config) *StandAloneStorage { // Your Code Here (1). return nil}func (s *StandAloneStorage) Start() error { // Your Code Here (1). return nil}func (s *StandAloneStorage) Stop() error { // Your Code Here (1). return nil}func (s *StandAloneStorage) Reader(ctx *kvrpcpb.Context) (storage.StorageReader, error) { // Your Code Here (1). return nil, nil}func (s *StandAloneStorage) Write(ctx *kvrpcpb.Context, batch []storage.Modify) error { // Your Code Here (1). return nil}
- 第二个你要实现的
package serverimport ( "context" "github.com/pingcap-incubator/tinykv/proto/pkg/kvrpcpb")// The functions below are Server's Raw API. (implements TinyKvServer).// Some helper methods can be found in sever.go in the current directory// RawGet return the corresponding Get response based on RawGetRequest's CF and Key fieldsfunc (server *Server) RawGet(_ context.Context, req *kvrpcpb.RawGetRequest) (*kvrpcpb.RawGetResponse, error) { // Your Code Here (1). return nil, nil}// RawPut puts the target data into storage and returns the corresponding responsefunc (server *Server) RawPut(_ context.Context, req *kvrpcpb.RawPutRequest) (*kvrpcpb.RawPutResponse, error) { // Your Code Here (1). // Hint: Consider using Storage.Modify to store data to be modified return nil, nil}// RawDelete delete the target data from storage and returns the corresponding responsefunc (server *Server) RawDelete(_ context.Context, req *kvrpcpb.RawDeleteRequest) (*kvrpcpb.RawDeleteResponse, error) { // Your Code Here (1). // Hint: Consider using Storage.Modify to store data to be deleted return nil, nil}// RawScan scan the data starting from the start key up to limit. and return the corresponding resultfunc (server *Server) RawScan(_ context.Context, req *kvrpcpb.RawScanRequest) (*kvrpcpb.RawScanResponse, error) { // Your Code Here (1). // Hint: Consider using reader.IterCF return nil, nil}
对应的单元测试文件是tinykv/kv/server/server_test.go
,测试用例官网工程师曾经写好了,你只须要把底层代码实现,跑通单元测试即可实现Project 1
,我这里提醒一下Project 1
能够看成一个适配器模式,只是进行了一层封装,写实现的或者测试单元测试的时候能够一个一个测试来测试,先把单元测试全副正文掉,而后实现一个解正文一个,跑一个,good luck!
。