2020-03-03 10:31:48 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2020-03-03 19:32:07 +00:00
|
|
|
"encoding/binary"
|
2020-03-03 10:31:48 +00:00
|
|
|
"log"
|
|
|
|
"sync"
|
|
|
|
|
|
|
|
"github.com/tecbot/gorocksdb"
|
|
|
|
)
|
|
|
|
|
|
|
|
func CreateData() {
|
|
|
|
|
|
|
|
db, cfs := OpenDataBase()
|
|
|
|
|
2020-03-03 12:51:18 +00:00
|
|
|
GCOUNT := 10
|
2020-03-03 10:31:48 +00:00
|
|
|
|
|
|
|
wg := &sync.WaitGroup{}
|
|
|
|
wg.Add(GCOUNT)
|
|
|
|
|
|
|
|
for i := 0; i < GCOUNT; i++ {
|
|
|
|
go putData(wg, db, cfs)
|
|
|
|
}
|
|
|
|
|
|
|
|
wg.Wait()
|
|
|
|
}
|
|
|
|
|
|
|
|
func queryData(wg *sync.WaitGroup, db *gorocksdb.DB, cfs []*gorocksdb.ColumnFamilyHandle) {
|
|
|
|
defer wg.Done()
|
|
|
|
|
|
|
|
// now := time.Now().Unix()
|
|
|
|
|
|
|
|
ro := gorocksdb.NewDefaultReadOptions()
|
|
|
|
|
2020-03-03 19:32:07 +00:00
|
|
|
COUNT := 100
|
2020-03-03 10:31:48 +00:00
|
|
|
|
2020-03-03 19:32:07 +00:00
|
|
|
cf := cfs[len(cfs)-1]
|
|
|
|
iter := db.NewIteratorCF(ro, cf)
|
2020-03-03 10:31:48 +00:00
|
|
|
|
2020-03-03 19:32:07 +00:00
|
|
|
temp := make([]byte, 8)
|
|
|
|
binary.BigEndian.PutUint64(temp, 10)
|
|
|
|
iter.Seek(temp)
|
|
|
|
|
|
|
|
log.Println(iter.Valid())
|
|
|
|
|
|
|
|
for i := 0; i < COUNT && iter.Valid(); i++ {
|
|
|
|
bkey := iter.Key().Data()
|
|
|
|
key := string(bkey)
|
2020-03-03 10:31:48 +00:00
|
|
|
value := string(iter.Value().Data())
|
2020-03-03 19:32:07 +00:00
|
|
|
|
|
|
|
log.Println(binary.BigEndian.Uint64(bkey[0:8]), "\nkey:", key, "\n", "value:", value)
|
|
|
|
|
2020-03-03 10:31:48 +00:00
|
|
|
iter.Next()
|
|
|
|
}
|
|
|
|
|
|
|
|
// log.Println(int64(COUNT) / (time.Now().Unix() - now))
|
|
|
|
}
|
|
|
|
|
|
|
|
func QueryData() {
|
|
|
|
db, cfs := OpenDataBase()
|
|
|
|
|
|
|
|
GCOUNT := 1
|
|
|
|
|
|
|
|
wg := &sync.WaitGroup{}
|
|
|
|
wg.Add(GCOUNT)
|
|
|
|
|
|
|
|
for i := 0; i < GCOUNT; i++ {
|
|
|
|
go queryData(wg, db, cfs)
|
|
|
|
}
|
|
|
|
|
|
|
|
wg.Wait()
|
|
|
|
}
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
|
2020-03-03 19:32:07 +00:00
|
|
|
QueryData()
|
|
|
|
// CreateData()
|
2020-03-03 10:31:48 +00:00
|
|
|
|
|
|
|
// db.Put(wo, []byte("foo"), []byte("bar"))
|
|
|
|
|
|
|
|
// ro := gorocksdb.NewDefaultReadOptions()
|
|
|
|
// db, err := gorocksdb.OpenDb(opts, "./.rocksdb")
|
|
|
|
// if err != nil {
|
|
|
|
// panic(err)
|
|
|
|
// }
|
|
|
|
// s, err := db.Get(ro, []byte("foo"))
|
|
|
|
// if err != nil {
|
|
|
|
// panic(err)
|
|
|
|
// }
|
|
|
|
// log.Println(string(s.Data()))
|
|
|
|
|
|
|
|
}
|