Update dependencies (fixes #692)

This commit is contained in:
Jakob Borg 2014-09-15 18:15:16 +02:00
parent 55ea207a55
commit d17d80747e
10 changed files with 84 additions and 63 deletions

4
Godeps/Godeps.json generated
View File

@ -37,7 +37,7 @@
}, },
{ {
"ImportPath": "github.com/bkaradzic/go-lz4", "ImportPath": "github.com/bkaradzic/go-lz4",
"Rev": "77e2ba877bde9da31213bec75dbbe197fa507c21" "Rev": "93a831dcee242be64a9cc9803dda84af25932de7"
}, },
{ {
"ImportPath": "github.com/calmh/xdr", "ImportPath": "github.com/calmh/xdr",
@ -49,7 +49,7 @@
}, },
{ {
"ImportPath": "github.com/syndtr/goleveldb/leveldb", "ImportPath": "github.com/syndtr/goleveldb/leveldb",
"Rev": "457e6f75905f7c1316afd8c43ad323f4c32b31c2" "Rev": "9bca75c48d6c31becfbb127702b425e7226052e3"
}, },
{ {
"ImportPath": "github.com/vitrun/qart/coding", "ImportPath": "github.com/vitrun/qart/coding",

View File

@ -72,10 +72,18 @@ func main() {
if *decompress { if *decompress {
data, _ = ioutil.ReadAll(input) data, _ = ioutil.ReadAll(input)
data, _ = lz4.Decode(nil, data) data, err = lz4.Decode(nil, data)
if err != nil {
fmt.Println("Failed to decode:", err)
return
}
} else { } else {
data, _ = ioutil.ReadAll(input) data, _ = ioutil.ReadAll(input)
data, _ = lz4.Encode(nil, data) data, err = lz4.Encode(nil, data)
if err != nil {
fmt.Println("Failed to encode:", err)
return
}
} }
err = ioutil.WriteFile(args[1], data, 0644) err = ioutil.WriteFile(args[1], data, 0644)

View File

@ -121,7 +121,7 @@ func Encode(dst, src []byte) ([]byte, error) {
) )
for { for {
if int(e.pos)+4 >= len(e.src) { if int(e.pos)+12 >= len(e.src) {
e.writeLiterals(uint32(len(e.src))-e.anchor, 0, e.anchor) e.writeLiterals(uint32(len(e.src))-e.anchor, 0, e.anchor)
return e.dst[:e.dpos], nil return e.dst[:e.dpos], nil
} }
@ -158,7 +158,7 @@ func Encode(dst, src []byte) ([]byte, error) {
ref += minMatch ref += minMatch
e.anchor = e.pos e.anchor = e.pos
for int(e.pos) < len(e.src) && e.src[e.pos] == e.src[ref] { for int(e.pos) < len(e.src)-5 && e.src[e.pos] == e.src[ref] {
e.pos++ e.pos++
ref++ ref++
} }

View File

@ -13,8 +13,8 @@ import (
"github.com/syndtr/goleveldb/leveldb/util" "github.com/syndtr/goleveldb/leveldb/util"
) )
// The LLRB implementation were taken from https://github.com/petar/GoLLRB, // The LLRB implementation were taken from https://github.com/petar/GoLLRB.
// which conatins the following header: // Which contains the following header:
// //
// Copyright 2010 Petar Maymounkov. All rights reserved. // Copyright 2010 Petar Maymounkov. All rights reserved.
// Use of this source code is governed by a BSD-style // Use of this source code is governed by a BSD-style

View File

@ -1579,8 +1579,8 @@ func TestDb_BloomFilter(t *testing.T) {
const ( const (
n = 10000 n = 10000
indexOverheat = 19898 indexOverhead = 19898
filterOverheat = 19799 filterOverhead = 19799
) )
// Populate multiple layers // Populate multiple layers
@ -1605,7 +1605,7 @@ func TestDb_BloomFilter(t *testing.T) {
cnt := int(h.stor.ReadCounter()) cnt := int(h.stor.ReadCounter())
t.Logf("lookup of %d present keys yield %d sstable I/O reads", n, cnt) t.Logf("lookup of %d present keys yield %d sstable I/O reads", n, cnt)
if min, max := n+indexOverheat+filterOverheat, n+indexOverheat+filterOverheat+2*n/100; cnt < min || cnt > max { if min, max := n+indexOverhead+filterOverhead, n+indexOverhead+filterOverhead+2*n/100; cnt < min || cnt > max {
t.Errorf("num of sstable I/O reads of present keys not in range of %d - %d, got %d", min, max, cnt) t.Errorf("num of sstable I/O reads of present keys not in range of %d - %d, got %d", min, max, cnt)
} }
@ -1616,7 +1616,7 @@ func TestDb_BloomFilter(t *testing.T) {
} }
cnt = int(h.stor.ReadCounter()) cnt = int(h.stor.ReadCounter())
t.Logf("lookup of %d missing keys yield %d sstable I/O reads", n, cnt) t.Logf("lookup of %d missing keys yield %d sstable I/O reads", n, cnt)
if max := 3*n/100 + indexOverheat + filterOverheat; cnt > max { if max := 3*n/100 + indexOverhead + filterOverhead; cnt > max {
t.Errorf("num of sstable I/O reads of missing keys was more than %d, got %d", max, cnt) t.Errorf("num of sstable I/O reads of missing keys was more than %d, got %d", max, cnt)
} }

View File

@ -40,18 +40,17 @@ var _ = testutil.Defer(func() {
}) })
Describe("read test", func() { Describe("read test", func() {
testutil.AllKeyValueTesting(nil, func(kv testutil.KeyValue) testutil.DB { testutil.AllKeyValueTesting(nil, nil, func(kv testutil.KeyValue) testutil.DB {
// Building the DB. // Building the DB.
db := newTestingDB(o, nil, nil) db := newTestingDB(o, nil, nil)
kv.IterateShuffled(nil, func(i int, key, value []byte) { kv.IterateShuffled(nil, func(i int, key, value []byte) {
err := db.TestPut(key, value) err := db.TestPut(key, value)
Expect(err).NotTo(HaveOccurred()) Expect(err).NotTo(HaveOccurred())
}) })
testutil.Defer("teardown", func() {
db.TestClose()
})
return db return db
}, func(db testutil.DB) {
db.(*testingDB).TestClose()
}) })
}) })
}) })

View File

@ -129,7 +129,7 @@ var _ = testutil.Defer(func() {
} }
return db return db
}) }, nil, nil)
}) })
}) })
}) })

View File

@ -59,7 +59,7 @@ var _ = testutil.Defer(func() {
// Make block. // Make block.
br := Build(kv, restartInterval) br := Build(kv, restartInterval)
// Do testing. // Do testing.
testutil.KeyValueTesting(nil, br, kv.Clone()) testutil.KeyValueTesting(nil, kv.Clone(), br, nil, nil)
} }
Describe(Text(), Test) Describe(Text(), Test)

View File

@ -104,11 +104,11 @@ var _ = testutil.Defer(func() {
if body != nil { if body != nil {
body(db.(tableWrapper).Reader) body(db.(tableWrapper).Reader)
} }
testutil.KeyValueTesting(nil, db, *kv) testutil.KeyValueTesting(nil, *kv, db, nil, nil)
} }
} }
testutil.AllKeyValueTesting(nil, Build) testutil.AllKeyValueTesting(nil, Build, nil, nil)
Describe("with one key per block", Test(testutil.KeyValue_Generate(nil, 9, 1, 10, 512, 512), func(r *Reader) { Describe("with one key per block", Test(testutil.KeyValue_Generate(nil, 9, 1, 10, 512, 512), func(r *Reader) {
It("should have correct blocks number", func() { It("should have correct blocks number", func() {
indexBlock, err := r.readBlock(r.indexBH, true) indexBlock, err := r.readBlock(r.indexBH, true)

View File

@ -16,13 +16,22 @@ import (
"github.com/syndtr/goleveldb/leveldb/util" "github.com/syndtr/goleveldb/leveldb/util"
) )
func KeyValueTesting(rnd *rand.Rand, p DB, kv KeyValue) { func KeyValueTesting(rnd *rand.Rand, kv KeyValue, p DB, setup func(KeyValue) DB, teardown func(DB)) {
if rnd == nil { if rnd == nil {
rnd = NewRand() rnd = NewRand()
} }
if db, ok := p.(Find); ok { if p == nil {
It("Should find all keys with Find", func() { BeforeEach(func() {
p = setup(kv)
})
AfterEach(func() {
teardown(p)
})
}
It("Should find all keys with Find", func() {
if db, ok := p.(Find); ok {
ShuffledIndex(nil, kv.Len(), 1, func(i int) { ShuffledIndex(nil, kv.Len(), 1, func(i int) {
key_, key, value := kv.IndexInexact(i) key_, key, value := kv.IndexInexact(i)
@ -38,9 +47,11 @@ func KeyValueTesting(rnd *rand.Rand, p DB, kv KeyValue) {
Expect(rkey).Should(Equal(key)) Expect(rkey).Should(Equal(key))
Expect(rvalue).Should(Equal(value), "Value for key %q (%q)", key_, key) Expect(rvalue).Should(Equal(value), "Value for key %q (%q)", key_, key)
}) })
}) }
})
It("Should return error if the key is not present", func() { It("Should return error if the key is not present", func() {
if db, ok := p.(Find); ok {
var key []byte var key []byte
if kv.Len() > 0 { if kv.Len() > 0 {
key_, _ := kv.Index(kv.Len() - 1) key_, _ := kv.Index(kv.Len() - 1)
@ -49,11 +60,11 @@ func KeyValueTesting(rnd *rand.Rand, p DB, kv KeyValue) {
rkey, _, err := db.TestFind(key) rkey, _, err := db.TestFind(key)
Expect(err).Should(HaveOccurred(), "Find for key %q yield key %q", key, rkey) Expect(err).Should(HaveOccurred(), "Find for key %q yield key %q", key, rkey)
Expect(err).Should(Equal(util.ErrNotFound)) Expect(err).Should(Equal(util.ErrNotFound))
}) }
} })
if db, ok := p.(Get); ok { It("Should only find exact key with Get", func() {
It("Should only find exact key with Get", func() { if db, ok := p.(Get); ok {
ShuffledIndex(nil, kv.Len(), 1, func(i int) { ShuffledIndex(nil, kv.Len(), 1, func(i int) {
key_, key, value := kv.IndexInexact(i) key_, key, value := kv.IndexInexact(i)
@ -69,11 +80,11 @@ func KeyValueTesting(rnd *rand.Rand, p DB, kv KeyValue) {
Expect(err).Should(Equal(util.ErrNotFound)) Expect(err).Should(Equal(util.ErrNotFound))
} }
}) })
}) }
} })
if db, ok := p.(NewIterator); ok { TestIter := func(r *util.Range, _kv KeyValue) {
TestIter := func(r *util.Range, _kv KeyValue) { if db, ok := p.(NewIterator); ok {
iter := db.TestNewIterator(r) iter := db.TestNewIterator(r)
Expect(iter.Error()).ShouldNot(HaveOccurred()) Expect(iter.Error()).ShouldNot(HaveOccurred())
@ -84,45 +95,48 @@ func KeyValueTesting(rnd *rand.Rand, p DB, kv KeyValue) {
DoIteratorTesting(&t) DoIteratorTesting(&t)
} }
}
It("Should iterates and seeks correctly", func(done Done) { It("Should iterates and seeks correctly", func(done Done) {
TestIter(nil, kv.Clone()) TestIter(nil, kv.Clone())
done <- true done <- true
}, 3.0) }, 3.0)
RandomIndex(rnd, kv.Len(), kv.Len(), func(i int) { RandomIndex(rnd, kv.Len(), kv.Len(), func(i int) {
type slice struct { type slice struct {
r *util.Range r *util.Range
start, limit int start, limit int
} }
key_, _, _ := kv.IndexInexact(i) key_, _, _ := kv.IndexInexact(i)
for _, x := range []slice{ for _, x := range []slice{
{&util.Range{Start: key_, Limit: nil}, i, kv.Len()}, {&util.Range{Start: key_, Limit: nil}, i, kv.Len()},
{&util.Range{Start: nil, Limit: key_}, 0, i}, {&util.Range{Start: nil, Limit: key_}, 0, i},
} { } {
It(fmt.Sprintf("Should iterates and seeks correctly of a slice %d .. %d", x.start, x.limit), func(done Done) { It(fmt.Sprintf("Should iterates and seeks correctly of a slice %d .. %d", x.start, x.limit), func(done Done) {
TestIter(x.r, kv.Slice(x.start, x.limit)) TestIter(x.r, kv.Slice(x.start, x.limit))
done <- true
}, 3.0)
}
})
RandomRange(rnd, kv.Len(), kv.Len(), func(start, limit int) {
It(fmt.Sprintf("Should iterates and seeks correctly of a slice %d .. %d", start, limit), func(done Done) {
r := kv.Range(start, limit)
TestIter(&r, kv.Slice(start, limit))
done <- true done <- true
}, 3.0) }, 3.0)
}) }
} })
RandomRange(rnd, kv.Len(), kv.Len(), func(start, limit int) {
It(fmt.Sprintf("Should iterates and seeks correctly of a slice %d .. %d", start, limit), func(done Done) {
r := kv.Range(start, limit)
TestIter(&r, kv.Slice(start, limit))
done <- true
}, 3.0)
})
} }
func AllKeyValueTesting(rnd *rand.Rand, body func(kv KeyValue) DB) { func AllKeyValueTesting(rnd *rand.Rand, body, setup func(KeyValue) DB, teardown func(DB)) {
Test := func(kv *KeyValue) func() { Test := func(kv *KeyValue) func() {
return func() { return func() {
db := body(*kv) var p DB
KeyValueTesting(rnd, db, *kv) if body != nil {
p = body(*kv)
}
KeyValueTesting(rnd, *kv, p, setup, teardown)
} }
} }