Exemple #1
0
// This program is used to compare two databases - one from server and the other one from client
func main() {

	ro := &opt.ReadOptions{}
	//wo := &opt.WriteOptions{}
	opts := &opt.Options{}

	ldb, err := leveldb.OpenFile(dbpath, opts)
	fmt.Println("started db from ", dbpath)
	if err != nil {
		fmt.Printf("db open failed %v\n", err)
		return
	}

	ldb2, err := leveldb.OpenFile(dbpath2, opts)
	fmt.Println("started db2 from ", dbpath2)
	if err != nil {
		fmt.Printf("db2 open failed %v\n", err)
		return
	}

	elice := make([]*tst, 0, 10)

	iter := ldb.NewIterator(&util.Range{Start: nil, Limit: nil}, ro)

	for iter.Next() {
		key := iter.Key()
		value := iter.Value()
		t := new(tst)

		value2, _ := ldb2.Get(key, ro)

		if value2 == nil {
			fmt.Printf("key:%v\n", common.EncodeBinary(&key))
		} else if bytes.Compare(value, value2) != 0 {
			fmt.Printf("Key with different values:%v\n", common.EncodeBinary(&key))
			fmt.Printf("value1:%v\n", common.EncodeBinary(&value))
			fmt.Printf("value2:%v\n", common.EncodeBinary(&value2))
		}

		elice = append(elice, t)

	}

	fmt.Printf("len(elice):%v", len(elice))
	fmt.Printf("completed\n")
	ldb.Close()
}
Exemple #2
0
func main() {

	ro := &opt.ReadOptions{}
	//wo := &opt.WriteOptions{}
	opts := &opt.Options{}

	ldb, err := leveldb.OpenFile(dbpath, opts)
	fmt.Println("started db from ", dbpath)
	if err != nil {
		fmt.Printf("db open failed %v\n", err)
		return
	}

	elice := make([]*tst, 0, 10)

	//var fromkey [] byte = []byte{byte(2)} 		  	// Table Name (4 bytes)
	//var tokey [] byte = []byte{byte(51)} 		  	// Table Name (4 bytes)
	iter := ldb.NewIterator(&util.Range{Start: nil, Limit: nil}, ro)

	for iter.Next() {
		key := iter.Key()
		fmt.Printf("key:%v", common.EncodeBinary(&key))
		value := iter.Value()
		fmt.Printf("  value:%v\n", common.EncodeBinary(&value))
		t := new(tst)

		//t.key = binary.BigEndian.Uint32(key[:4])
		//buf := bytes.NewBuffer(key)
		//binary.Read(buf, binary.BigEndian, &t.key)

		//fmt.Println("t.key:%v", t.key)
		elice = append(elice, t)

	}

	fmt.Printf("len(elice):%v", len(elice))
	fmt.Printf("completed\n")
	ldb.Close()
}