forked from mirror/ledisdb
remove DataDB
This commit is contained in:
parent
ee59af0062
commit
2972f57436
|
@ -90,11 +90,6 @@ func (l *Ledis) FlushAll() error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// very dangerous to use
|
|
||||||
func (l *Ledis) DataDB() *store.DB {
|
|
||||||
return l.ldb
|
|
||||||
}
|
|
||||||
|
|
||||||
func (l *Ledis) activeExpireCycle() {
|
func (l *Ledis) activeExpireCycle() {
|
||||||
var executors []*elimination = make([]*elimination, len(l.dbs))
|
var executors []*elimination = make([]*elimination, len(l.dbs))
|
||||||
for i, db := range l.dbs {
|
for i, db := range l.dbs {
|
||||||
|
|
|
@ -1,25 +1,32 @@
|
||||||
package server
|
package server
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/siddontang/ledisdb/config"
|
"github.com/siddontang/ledisdb/config"
|
||||||
"github.com/siddontang/ledisdb/store"
|
|
||||||
"os"
|
"os"
|
||||||
|
"reflect"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
func checkDataEqual(master *App, slave *App) error {
|
func checkDataEqual(master *App, slave *App) error {
|
||||||
it := master.ldb.DataDB().RangeLimitIterator(nil, nil, store.RangeClose, 0, -1)
|
mdb, _ := master.ldb.Select(0)
|
||||||
for ; it.Valid(); it.Next() {
|
sdb, _ := slave.ldb.Select(0)
|
||||||
key := it.Key()
|
|
||||||
value := it.Value()
|
|
||||||
|
|
||||||
if v, err := slave.ldb.DataDB().Get(key); err != nil {
|
mkeys, _ := mdb.Scan(nil, 100, true, "")
|
||||||
return err
|
skeys, _ := sdb.Scan(nil, 100, true, "")
|
||||||
} else if !bytes.Equal(v, value) {
|
|
||||||
return fmt.Errorf("replication error %d != %d", len(v), len(value))
|
if len(mkeys) != len(skeys) {
|
||||||
|
return fmt.Errorf("keys number not equal")
|
||||||
|
} else if !reflect.DeepEqual(mkeys, skeys) {
|
||||||
|
return fmt.Errorf("keys not equal")
|
||||||
|
} else {
|
||||||
|
for _, k := range mkeys {
|
||||||
|
v1, _ := mdb.Get(k)
|
||||||
|
v2, _ := sdb.Get(k)
|
||||||
|
if !reflect.DeepEqual(v1, v2) {
|
||||||
|
return fmt.Errorf("value not equal")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -64,8 +71,8 @@ func TestReplication(t *testing.T) {
|
||||||
|
|
||||||
db.Set([]byte("a"), value)
|
db.Set([]byte("a"), value)
|
||||||
db.Set([]byte("b"), value)
|
db.Set([]byte("b"), value)
|
||||||
db.HSet([]byte("a"), []byte("1"), value)
|
db.Set([]byte("c"), value)
|
||||||
db.HSet([]byte("b"), []byte("2"), value)
|
db.Set([]byte("d"), value)
|
||||||
|
|
||||||
go slave.Run()
|
go slave.Run()
|
||||||
|
|
||||||
|
@ -77,8 +84,8 @@ func TestReplication(t *testing.T) {
|
||||||
|
|
||||||
db.Set([]byte("a1"), value)
|
db.Set([]byte("a1"), value)
|
||||||
db.Set([]byte("b1"), value)
|
db.Set([]byte("b1"), value)
|
||||||
db.HSet([]byte("a1"), []byte("1"), value)
|
db.Set([]byte("c1"), value)
|
||||||
db.HSet([]byte("b1"), []byte("2"), value)
|
db.Set([]byte("d1"), value)
|
||||||
|
|
||||||
time.Sleep(1 * time.Second)
|
time.Sleep(1 * time.Second)
|
||||||
if err = checkDataEqual(master, slave); err != nil {
|
if err = checkDataEqual(master, slave); err != nil {
|
||||||
|
@ -89,13 +96,13 @@ func TestReplication(t *testing.T) {
|
||||||
|
|
||||||
db.Set([]byte("a2"), value)
|
db.Set([]byte("a2"), value)
|
||||||
db.Set([]byte("b2"), value)
|
db.Set([]byte("b2"), value)
|
||||||
db.HSet([]byte("a2"), []byte("1"), value)
|
db.Set([]byte("c2"), value)
|
||||||
db.HSet([]byte("b2"), []byte("2"), value)
|
db.Set([]byte("d2"), value)
|
||||||
|
|
||||||
db.Set([]byte("a3"), value)
|
db.Set([]byte("a3"), value)
|
||||||
db.Set([]byte("b3"), value)
|
db.Set([]byte("b3"), value)
|
||||||
db.HSet([]byte("a3"), []byte("1"), value)
|
db.Set([]byte("c3"), value)
|
||||||
db.HSet([]byte("b3"), []byte("2"), value)
|
db.Set([]byte("d3"), value)
|
||||||
|
|
||||||
if err = checkDataEqual(master, slave); err == nil {
|
if err = checkDataEqual(master, slave); err == nil {
|
||||||
t.Fatal("must error")
|
t.Fatal("must error")
|
||||||
|
|
Loading…
Reference in New Issue