Skip to content

Commit

Permalink
Merge pull request #39 from tendermint/develop-pre-wire
Browse files Browse the repository at this point in the history
Develop pre wire
  • Loading branch information
ebuchman authored Mar 2, 2018
2 parents 594cc0c + e31d74a commit b7d5f00
Show file tree
Hide file tree
Showing 28 changed files with 1,441 additions and 627 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
vendor
.glide
*.swp
*.swo

# created in test code
test.db
Expand Down
28 changes: 28 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Changelog

## 0.6.0 (March 2, 2018)

BREAKING CHANGES

- NewTree order of arguments swapped
- int -> int64, uint64 -> int64
- NewNode takes a version
- Node serialization format changed so version is written right after size
- SaveVersion takes no args (auto increments)
- tree.Get -> tree.Get64
- nodeDB.SaveBranch does not take a callback
- orphaningTree.SaveVersion -> SaveAs
- proofInnerNode includes Version
- ReadKeyXxxProof consolidated into ReadKeyProof
- KeyAbsentProof doesn't include Version
- KeyRangeProof.Version -> Versions

FEATURES

- Implement chunking algorithm to serialize entire tree

## 0.5.0 (October 27, 2017)

First versioned release!
(Originally accidentally released as v0.2.0)

44 changes: 22 additions & 22 deletions basic_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
)

func TestBasic(t *testing.T) {
var tree *Tree = NewTree(0, nil)
var tree *Tree = NewTree(nil, 0)
up := tree.Set([]byte("1"), []byte("one"))
if up {
t.Error("Did not expect an update (should have been create)")
Expand All @@ -32,7 +32,7 @@ func TestBasic(t *testing.T) {

// Test 0x00
{
idx, val := tree.Get([]byte{0x00})
idx, val := tree.Get64([]byte{0x00})
if val != nil {
t.Errorf("Expected no value to exist")
}
Expand All @@ -46,7 +46,7 @@ func TestBasic(t *testing.T) {

// Test "1"
{
idx, val := tree.Get([]byte("1"))
idx, val := tree.Get64([]byte("1"))
if val == nil {
t.Errorf("Expected value to exist")
}
Expand All @@ -60,7 +60,7 @@ func TestBasic(t *testing.T) {

// Test "2"
{
idx, val := tree.Get([]byte("2"))
idx, val := tree.Get64([]byte("2"))
if val == nil {
t.Errorf("Expected value to exist")
}
Expand All @@ -74,7 +74,7 @@ func TestBasic(t *testing.T) {

// Test "4"
{
idx, val := tree.Get([]byte("4"))
idx, val := tree.Get64([]byte("4"))
if val != nil {
t.Errorf("Expected no value to exist")
}
Expand All @@ -88,7 +88,7 @@ func TestBasic(t *testing.T) {

// Test "6"
{
idx, val := tree.Get([]byte("6"))
idx, val := tree.Get64([]byte("6"))
if val != nil {
t.Errorf("Expected no value to exist")
}
Expand All @@ -103,7 +103,7 @@ func TestBasic(t *testing.T) {

func TestUnit(t *testing.T) {

expectHash := func(tree *Tree, hashCount int) {
expectHash := func(tree *Tree, hashCount int64) {
// ensure number of new hash calculations is as expected.
hash, count := tree.hashWithCount()
if count != hashCount {
Expand All @@ -121,7 +121,7 @@ func TestUnit(t *testing.T) {
}
}

expectSet := func(tree *Tree, i int, repr string, hashCount int) {
expectSet := func(tree *Tree, i int, repr string, hashCount int64) {
origNode := tree.root
updated := tree.Set(i2b(i), []byte{})
// ensure node was added & structure is as expected.
Expand All @@ -134,7 +134,7 @@ func TestUnit(t *testing.T) {
tree.root = origNode
}

expectRemove := func(tree *Tree, i int, repr string, hashCount int) {
expectRemove := func(tree *Tree, i int, repr string, hashCount int64) {
origNode := tree.root
value, removed := tree.Remove(i2b(i))
// ensure node was added & structure is as expected.
Expand Down Expand Up @@ -190,7 +190,7 @@ func TestRemove(t *testing.T) {

d := db.NewDB("test", "memdb", "")
defer d.Close()
t1 := NewVersionedTree(size, d)
t1 := NewVersionedTree(d, size)

// insert a bunch of random nodes
keys := make([][]byte, size)
Expand All @@ -208,7 +208,7 @@ func TestRemove(t *testing.T) {
key := keys[mrand.Int31n(l)]
t1.Remove(key)
}
t1.SaveVersion(uint64(i))
t1.SaveVersion()
}
}

Expand All @@ -220,7 +220,7 @@ func TestIntegration(t *testing.T) {
}

records := make([]*record, 400)
var tree *Tree = NewTree(0, nil)
var tree *Tree = NewTree(nil, 0)

randomRecord := func() *record {
return &record{randstr(20), randstr(20)}
Expand Down Expand Up @@ -249,7 +249,7 @@ func TestIntegration(t *testing.T) {
if has := tree.Has([]byte(randstr(12))); has {
t.Error("Table has extra key")
}
if _, val := tree.Get([]byte(r.key)); string(val) != string(r.value) {
if _, val := tree.Get64([]byte(r.key)); string(val) != string(r.value) {
t.Error("wrong value")
}
}
Expand All @@ -267,7 +267,7 @@ func TestIntegration(t *testing.T) {
if has := tree.Has([]byte(randstr(12))); has {
t.Error("Table has extra key")
}
_, val := tree.Get([]byte(r.key))
_, val := tree.Get64([]byte(r.key))
if string(val) != string(r.value) {
t.Error("wrong value")
}
Expand Down Expand Up @@ -302,7 +302,7 @@ func TestIterateRange(t *testing.T) {
}
sort.Strings(keys)

var tree *Tree = NewTree(0, nil)
var tree *Tree = NewTree(nil, 0)

// insert all the data
for _, r := range records {
Expand Down Expand Up @@ -369,17 +369,17 @@ func TestPersistence(t *testing.T) {
}

// Construct some tree and save it
t1 := NewVersionedTree(0, db)
t1 := NewVersionedTree(db, 0)
for key, value := range records {
t1.Set([]byte(key), []byte(value))
}
t1.SaveVersion(1)
t1.SaveVersion()

// Load a tree
t2 := NewVersionedTree(0, db)
t2 := NewVersionedTree(db, 0)
t2.Load()
for key, value := range records {
_, t2value := t2.Get([]byte(key))
_, t2value := t2.Get64([]byte(key))
if string(t2value) != value {
t.Fatalf("Invalid value. Expected %v, got %v", value, t2value)
}
Expand All @@ -391,14 +391,14 @@ func TestProof(t *testing.T) {

// Construct some random tree
db := db.NewMemDB()
var tree *VersionedTree = NewVersionedTree(100, db)
var tree *VersionedTree = NewVersionedTree(db, 100)
for i := 0; i < 1000; i++ {
key, value := randstr(20), randstr(20)
tree.Set([]byte(key), []byte(value))
}

// Persist the items so far
tree.SaveVersion(1)
tree.SaveVersion()

// Add more items so it's not all persisted
for i := 0; i < 100; i++ {
Expand All @@ -420,7 +420,7 @@ func TestProof(t *testing.T) {

func TestTreeProof(t *testing.T) {
db := db.NewMemDB()
var tree *Tree = NewTree(100, db)
var tree *Tree = NewTree(db, 100)

// should get false for proof with nil root
_, _, err := tree.GetWithProof([]byte("foo"))
Expand Down
14 changes: 7 additions & 7 deletions benchmarks/bench_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ func randBytes(length int) []byte {
}

func prepareTree(db db.DB, size, keyLen, dataLen int) (*iavl.VersionedTree, [][]byte) {
t := iavl.NewVersionedTree(size, db)
t := iavl.NewVersionedTree(db, size)
keys := make([][]byte, size)

for i := 0; i < size; i++ {
Expand All @@ -28,7 +28,7 @@ func prepareTree(db db.DB, size, keyLen, dataLen int) (*iavl.VersionedTree, [][]
keys[i] = key
}
t.Hash()
t.SaveVersion(t.LatestVersion() + 1)
t.SaveVersion()
runtime.GC()
return t, keys
}
Expand All @@ -53,7 +53,7 @@ func runInsert(b *testing.B, t *iavl.VersionedTree, keyLen, dataLen, blockSize i
t.Set(randBytes(keyLen), randBytes(dataLen))
if i%blockSize == 0 {
t.Hash()
t.SaveVersion(t.LatestVersion() + 1)
t.SaveVersion()
}
}
return t
Expand All @@ -66,7 +66,7 @@ func runUpdate(b *testing.B, t *iavl.VersionedTree, dataLen, blockSize int, keys
t.Set(key, randBytes(dataLen))
if i%blockSize == 0 {
t.Hash()
t.SaveVersion(t.LatestVersion() + 1)
t.SaveVersion()
}
}
return t
Expand All @@ -82,7 +82,7 @@ func runDelete(b *testing.B, t *iavl.VersionedTree, blockSize int, keys [][]byte
t.Remove(key)
if i%blockSize == 0 {
t.Hash()
t.SaveVersion(t.LatestVersion() + 1)
t.SaveVersion()
}
}
return t
Expand Down Expand Up @@ -118,7 +118,7 @@ func runBlock(b *testing.B, t *iavl.VersionedTree, keyLen, dataLen, blockSize in

// at the end of a block, move it all along....
real.Hash()
real.SaveVersion(real.LatestVersion() + 1)
real.SaveVersion()
lastCommit = real
}

Expand All @@ -143,7 +143,7 @@ func BenchmarkRandomBytes(b *testing.B) {
}

type benchmark struct {
dbType string
dbType db.DBBackendType
initSize, blockSize int
keyLen, dataLen int
}
Expand Down
Loading

0 comments on commit b7d5f00

Please sign in to comment.