Table upload

This commit is contained in:
huangsimin 2020-03-06 09:55:58 +08:00
parent dc9b3abe9e
commit 779d60a533

View File

@ -4,11 +4,16 @@ import (
"fmt"
"log"
"os"
"sync/atomic"
"time"
"github.com/tecbot/gorocksdb"
)
// EDB 全局操作的edb对象
var EDB *EasyDataBase
// OpenLog 初始化日志设置
func OpenLog() {
f, err := os.OpenFile("./rocksdb.log", os.O_CREATE|os.O_RDWR|os.O_TRUNC, 0660)
if err != nil {
@ -19,8 +24,65 @@ func OpenLog() {
func init() {
OpenLog()
EDB = NewEasyDataBase()
}
func NewEasyDataBase() *EasyDataBase {
edb := &EasyDataBase{}
db, cfs := OpenDataBase()
edb.DB = db
edb.CFS = cfs
return edb
}
type EasyDataBase struct {
DB *gorocksdb.DB
CFS gorocksdb.ColumnFamilyHandles
Tables map[uint32]*Table
TableDict map[string]uint32
Metadata
}
type Metadata struct {
tidCount uint32 // int16
}
type Field struct {
Name string
Type int
ID int
IsIndex bool
IsUnique bool
}
type Table struct {
Name string
Type int
ID uint32 // uint16
IsAllKey bool
Fields []*Field
fidCount uint16 // uint16
idxCount uint64
rawCount uint64
delCount uint64
}
func CreateTable(name string, field []*Field) {
if _, ok := EDB.TableDict[name]; !ok {
ntid := atomic.AddUint32(&EDB.Metadata.tidCount, 1)
table := &Table{Name: name, ID: ntid, Type: 1}
} else {
log.Println("table name is exists")
}
}
// {tableid(2)}{fieldid(2)}{value}{indexid(8)} = {rowid(8)} {rowid} = {values}
func OpenDataBase() (*gorocksdb.DB, []*gorocksdb.ColumnFamilyHandle) {
bbto := gorocksdb.NewDefaultBlockBasedTableOptions()