remove DataDB

This commit is contained in:
siddontang 2014-09-18 22:20:18 +08:00
parent ee59af0062
commit 2972f57436
2 changed files with 25 additions and 23 deletions

View File

@ -90,11 +90,6 @@ func (l *Ledis) FlushAll() error {
return nil
}
// very dangerous to use
func (l *Ledis) DataDB() *store.DB {
return l.ldb
}
func (l *Ledis) activeExpireCycle() {
var executors []*elimination = make([]*elimination, len(l.dbs))
for i, db := range l.dbs {

View File

@ -1,25 +1,32 @@
package server
import (
"bytes"
"fmt"
"github.com/siddontang/ledisdb/config"
"github.com/siddontang/ledisdb/store"
"os"
"reflect"
"testing"
"time"
)
func checkDataEqual(master *App, slave *App) error {
it := master.ldb.DataDB().RangeLimitIterator(nil, nil, store.RangeClose, 0, -1)
for ; it.Valid(); it.Next() {
key := it.Key()
value := it.Value()
mdb, _ := master.ldb.Select(0)
sdb, _ := slave.ldb.Select(0)
if v, err := slave.ldb.DataDB().Get(key); err != nil {
return err
} else if !bytes.Equal(v, value) {
return fmt.Errorf("replication error %d != %d", len(v), len(value))
mkeys, _ := mdb.Scan(nil, 100, true, "")
skeys, _ := sdb.Scan(nil, 100, true, "")
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("b"), value)
db.HSet([]byte("a"), []byte("1"), value)
db.HSet([]byte("b"), []byte("2"), value)
db.Set([]byte("c"), value)
db.Set([]byte("d"), value)
go slave.Run()
@ -77,8 +84,8 @@ func TestReplication(t *testing.T) {
db.Set([]byte("a1"), value)
db.Set([]byte("b1"), value)
db.HSet([]byte("a1"), []byte("1"), value)
db.HSet([]byte("b1"), []byte("2"), value)
db.Set([]byte("c1"), value)
db.Set([]byte("d1"), value)
time.Sleep(1 * time.Second)
if err = checkDataEqual(master, slave); err != nil {
@ -89,13 +96,13 @@ func TestReplication(t *testing.T) {
db.Set([]byte("a2"), value)
db.Set([]byte("b2"), value)
db.HSet([]byte("a2"), []byte("1"), value)
db.HSet([]byte("b2"), []byte("2"), value)
db.Set([]byte("c2"), value)
db.Set([]byte("d2"), value)
db.Set([]byte("a3"), value)
db.Set([]byte("b3"), value)
db.HSet([]byte("a3"), []byte("1"), value)
db.HSet([]byte("b3"), []byte("2"), value)
db.Set([]byte("c3"), value)
db.Set([]byte("d3"), value)
if err = checkDataEqual(master, slave); err == nil {
t.Fatal("must error")