Skip to content

Commit b7d5f00

Browse files
authored
Merge pull request #39 from tendermint/develop-pre-wire
Develop pre wire
2 parents 594cc0c + e31d74a commit b7d5f00

28 files changed

+1441
-627
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
vendor
22
.glide
3+
*.swp
4+
*.swo
35

46
# created in test code
57
test.db

CHANGELOG.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# Changelog
2+
3+
## 0.6.0 (March 2, 2018)
4+
5+
BREAKING CHANGES
6+
7+
- NewTree order of arguments swapped
8+
- int -> int64, uint64 -> int64
9+
- NewNode takes a version
10+
- Node serialization format changed so version is written right after size
11+
- SaveVersion takes no args (auto increments)
12+
- tree.Get -> tree.Get64
13+
- nodeDB.SaveBranch does not take a callback
14+
- orphaningTree.SaveVersion -> SaveAs
15+
- proofInnerNode includes Version
16+
- ReadKeyXxxProof consolidated into ReadKeyProof
17+
- KeyAbsentProof doesn't include Version
18+
- KeyRangeProof.Version -> Versions
19+
20+
FEATURES
21+
22+
- Implement chunking algorithm to serialize entire tree
23+
24+
## 0.5.0 (October 27, 2017)
25+
26+
First versioned release!
27+
(Originally accidentally released as v0.2.0)
28+

basic_test.go

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import (
1212
)
1313

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

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

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

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

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

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

104104
func TestUnit(t *testing.T) {
105105

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

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

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

191191
d := db.NewDB("test", "memdb", "")
192192
defer d.Close()
193-
t1 := NewVersionedTree(size, d)
193+
t1 := NewVersionedTree(d, size)
194194

195195
// insert a bunch of random nodes
196196
keys := make([][]byte, size)
@@ -208,7 +208,7 @@ func TestRemove(t *testing.T) {
208208
key := keys[mrand.Int31n(l)]
209209
t1.Remove(key)
210210
}
211-
t1.SaveVersion(uint64(i))
211+
t1.SaveVersion()
212212
}
213213
}
214214

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

222222
records := make([]*record, 400)
223-
var tree *Tree = NewTree(0, nil)
223+
var tree *Tree = NewTree(nil, 0)
224224

225225
randomRecord := func() *record {
226226
return &record{randstr(20), randstr(20)}
@@ -249,7 +249,7 @@ func TestIntegration(t *testing.T) {
249249
if has := tree.Has([]byte(randstr(12))); has {
250250
t.Error("Table has extra key")
251251
}
252-
if _, val := tree.Get([]byte(r.key)); string(val) != string(r.value) {
252+
if _, val := tree.Get64([]byte(r.key)); string(val) != string(r.value) {
253253
t.Error("wrong value")
254254
}
255255
}
@@ -267,7 +267,7 @@ func TestIntegration(t *testing.T) {
267267
if has := tree.Has([]byte(randstr(12))); has {
268268
t.Error("Table has extra key")
269269
}
270-
_, val := tree.Get([]byte(r.key))
270+
_, val := tree.Get64([]byte(r.key))
271271
if string(val) != string(r.value) {
272272
t.Error("wrong value")
273273
}
@@ -302,7 +302,7 @@ func TestIterateRange(t *testing.T) {
302302
}
303303
sort.Strings(keys)
304304

305-
var tree *Tree = NewTree(0, nil)
305+
var tree *Tree = NewTree(nil, 0)
306306

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

371371
// Construct some tree and save it
372-
t1 := NewVersionedTree(0, db)
372+
t1 := NewVersionedTree(db, 0)
373373
for key, value := range records {
374374
t1.Set([]byte(key), []byte(value))
375375
}
376-
t1.SaveVersion(1)
376+
t1.SaveVersion()
377377

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

392392
// Construct some random tree
393393
db := db.NewMemDB()
394-
var tree *VersionedTree = NewVersionedTree(100, db)
394+
var tree *VersionedTree = NewVersionedTree(db, 100)
395395
for i := 0; i < 1000; i++ {
396396
key, value := randstr(20), randstr(20)
397397
tree.Set([]byte(key), []byte(value))
398398
}
399399

400400
// Persist the items so far
401-
tree.SaveVersion(1)
401+
tree.SaveVersion()
402402

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

421421
func TestTreeProof(t *testing.T) {
422422
db := db.NewMemDB()
423-
var tree *Tree = NewTree(100, db)
423+
var tree *Tree = NewTree(db, 100)
424424

425425
// should get false for proof with nil root
426426
_, _, err := tree.GetWithProof([]byte("foo"))

benchmarks/bench_test.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ func randBytes(length int) []byte {
1919
}
2020

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

2525
for i := 0; i < size; i++ {
@@ -28,7 +28,7 @@ func prepareTree(db db.DB, size, keyLen, dataLen int) (*iavl.VersionedTree, [][]
2828
keys[i] = key
2929
}
3030
t.Hash()
31-
t.SaveVersion(t.LatestVersion() + 1)
31+
t.SaveVersion()
3232
runtime.GC()
3333
return t, keys
3434
}
@@ -53,7 +53,7 @@ func runInsert(b *testing.B, t *iavl.VersionedTree, keyLen, dataLen, blockSize i
5353
t.Set(randBytes(keyLen), randBytes(dataLen))
5454
if i%blockSize == 0 {
5555
t.Hash()
56-
t.SaveVersion(t.LatestVersion() + 1)
56+
t.SaveVersion()
5757
}
5858
}
5959
return t
@@ -66,7 +66,7 @@ func runUpdate(b *testing.B, t *iavl.VersionedTree, dataLen, blockSize int, keys
6666
t.Set(key, randBytes(dataLen))
6767
if i%blockSize == 0 {
6868
t.Hash()
69-
t.SaveVersion(t.LatestVersion() + 1)
69+
t.SaveVersion()
7070
}
7171
}
7272
return t
@@ -82,7 +82,7 @@ func runDelete(b *testing.B, t *iavl.VersionedTree, blockSize int, keys [][]byte
8282
t.Remove(key)
8383
if i%blockSize == 0 {
8484
t.Hash()
85-
t.SaveVersion(t.LatestVersion() + 1)
85+
t.SaveVersion()
8686
}
8787
}
8888
return t
@@ -118,7 +118,7 @@ func runBlock(b *testing.B, t *iavl.VersionedTree, keyLen, dataLen, blockSize in
118118

119119
// at the end of a block, move it all along....
120120
real.Hash()
121-
real.SaveVersion(real.LatestVersion() + 1)
121+
real.SaveVersion()
122122
lastCommit = real
123123
}
124124

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

145145
type benchmark struct {
146-
dbType string
146+
dbType db.DBBackendType
147147
initSize, blockSize int
148148
keyLen, dataLen int
149149
}

0 commit comments

Comments
 (0)