Table upload
This commit is contained in:
parent
dc9b3abe9e
commit
779d60a533
62
rocksdb.go
62
rocksdb.go
|
@ -4,11 +4,16 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
|
"sync/atomic"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/tecbot/gorocksdb"
|
"github.com/tecbot/gorocksdb"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// EDB 全局操作的edb对象
|
||||||
|
var EDB *EasyDataBase
|
||||||
|
|
||||||
|
// OpenLog 初始化日志设置
|
||||||
func OpenLog() {
|
func OpenLog() {
|
||||||
f, err := os.OpenFile("./rocksdb.log", os.O_CREATE|os.O_RDWR|os.O_TRUNC, 0660)
|
f, err := os.OpenFile("./rocksdb.log", os.O_CREATE|os.O_RDWR|os.O_TRUNC, 0660)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -19,8 +24,65 @@ func OpenLog() {
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
OpenLog()
|
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) {
|
func OpenDataBase() (*gorocksdb.DB, []*gorocksdb.ColumnFamilyHandle) {
|
||||||
|
|
||||||
bbto := gorocksdb.NewDefaultBlockBasedTableOptions()
|
bbto := gorocksdb.NewDefaultBlockBasedTableOptions()
|
||||||
|
|
Loading…
Reference in New Issue
Block a user