todo: create table
This commit is contained in:
parent
5bcadb8bb8
commit
dc9b3abe9e
6
api.go
6
api.go
|
@ -14,12 +14,12 @@ type server struct{}
|
|||
|
||||
// SayHello implements
|
||||
func (s *server) SayHello(ctx context.Context, in *goproto.Request) (*goproto.Reply, error) {
|
||||
return &goproto.Reply{Msg: "Hello " + in.GetWhat()}, nil
|
||||
return &goproto.Reply{Msg: "Hello " + in.What, Status: 1, Content: []string{"dasasdasdas"}}, nil
|
||||
}
|
||||
|
||||
// SayHello implements
|
||||
func (s *server) CreateTable(ctx context.Context, in *goproto.TableRequest) (*goproto.TableReply, error) {
|
||||
return &goproto.TableReply{Msg: "Hello " + in.Name}, nil
|
||||
func (s *server) CreateTable(ctx context.Context, in *goproto.TableRequest) (*goproto.Reply, error) {
|
||||
return &goproto.Reply{Msg: "Create Table " + in.Name, Status: 1, Content: []string{"dasasdasdas"}}, nil
|
||||
}
|
||||
|
||||
func createTestServer() {
|
||||
|
|
|
@ -4,13 +4,24 @@ package goproto;
|
|||
// 服务端定义
|
||||
service EasyData {
|
||||
// 服务端返馈信息方法
|
||||
rpc CreateTable(TableRequest) returns (TableReply) {}
|
||||
rpc CreateTable(TableRequest) returns (Reply) {}
|
||||
}
|
||||
// 包含用户名的请求信息
|
||||
|
||||
message Field {
|
||||
string name = 1;
|
||||
string type = 2;
|
||||
int64 size = 3;
|
||||
}
|
||||
|
||||
message TableRequest {
|
||||
string name = 1;
|
||||
repeated Field field = 2;
|
||||
|
||||
}
|
||||
// 服务端响应信息
|
||||
message TableReply {
|
||||
string msg = 1;
|
||||
message Reply {
|
||||
int64 status = 1;
|
||||
string msg = 2;
|
||||
repeated string content = 3;
|
||||
}
|
||||
|
|
|
@ -1,6 +1,9 @@
|
|||
syntax = "proto3";
|
||||
|
||||
package goproto;
|
||||
|
||||
import "api.proto";
|
||||
|
||||
// 服务端定义
|
||||
service Test {
|
||||
// 服务端返馈信息方法
|
||||
|
@ -10,7 +13,3 @@ service Test {
|
|||
message Request {
|
||||
string what = 1;
|
||||
}
|
||||
// 服务端响应信息
|
||||
message Reply {
|
||||
string msg = 1;
|
||||
}
|
||||
|
|
73
rocksdb.go
Normal file
73
rocksdb.go
Normal file
|
@ -0,0 +1,73 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
"os"
|
||||
"time"
|
||||
|
||||
"github.com/tecbot/gorocksdb"
|
||||
)
|
||||
|
||||
func OpenLog() {
|
||||
f, err := os.OpenFile("./rocksdb.log", os.O_CREATE|os.O_RDWR|os.O_TRUNC, 0660)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
log.SetOutput(f)
|
||||
}
|
||||
|
||||
func init() {
|
||||
OpenLog()
|
||||
}
|
||||
|
||||
func OpenDataBase() (*gorocksdb.DB, []*gorocksdb.ColumnFamilyHandle) {
|
||||
|
||||
bbto := gorocksdb.NewDefaultBlockBasedTableOptions()
|
||||
|
||||
bbto.SetBlockCache(gorocksdb.NewLRUCache(3 << 30))
|
||||
bbto.SetCacheIndexAndFilterBlocksWithHighPriority(true)
|
||||
|
||||
opts := gorocksdb.NewDefaultOptions()
|
||||
|
||||
bbto.SetFilterPolicy(gorocksdb.NewBloomFilter(16))
|
||||
|
||||
opts.SetBlockBasedTableFactory(bbto)
|
||||
opts.SetCreateIfMissing(true)
|
||||
opts.SetCreateIfMissingColumnFamilies(true)
|
||||
opts.SetCompression(gorocksdb.LZ4Compression)
|
||||
|
||||
year, month, day := time.Now().Date()
|
||||
|
||||
timeCFStr := fmt.Sprintf("%d-%d-%d", year, int64(month), day)
|
||||
log.Println(timeCFStr)
|
||||
names, err := gorocksdb.ListColumnFamilies(opts, ".rocksdb")
|
||||
if err != nil {
|
||||
log.Println(".rocksdb 文件不存在")
|
||||
names = append(names, "default")
|
||||
}
|
||||
|
||||
isadd := true
|
||||
|
||||
var opslist []*gorocksdb.Options
|
||||
for _, name := range names {
|
||||
opslist = append(opslist, opts)
|
||||
if timeCFStr == name {
|
||||
isadd = false
|
||||
}
|
||||
}
|
||||
|
||||
if isadd {
|
||||
names = append(names, timeCFStr)
|
||||
opslist = append(opslist, opts)
|
||||
}
|
||||
|
||||
log.Println("ListColumnFamilies:", names)
|
||||
|
||||
db, cfs, err := gorocksdb.OpenDbColumnFamilies(opts, ".rocksdb", names, opslist)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
return db, cfs
|
||||
}
|
Loading…
Reference in New Issue
Block a user