Skip to content
This repository has been archived by the owner on Nov 22, 2018. It is now read-only.

Commit

Permalink
Use stable lldb. Updates cznic/ql#128.
Browse files Browse the repository at this point in the history
  • Loading branch information
Jan Mercl committed Jul 11, 2016
1 parent 120f703 commit 48b826e
Show file tree
Hide file tree
Showing 10 changed files with 87 additions and 74 deletions.
50 changes: 36 additions & 14 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,32 +2,54 @@
# Use of this source code is governed by a BSD-style
# license that can be found in the LICENSE file.

.PHONY: all editor todo clean nuke
.PHONY: all clean cover cpu editor internalError later mem nuke todo edit

grep=--include=*.go --include=*.run --include=*.y
grep=--include=*.go --include=*.l --include=*.y --include=*.yy
ngrep='TODOOK\|parser\.go\|scanner\.go\|.*_string\.go'

all: editor
go build
go vet
golint .
go install
go vet 2>&1 | grep -v $(ngrep) || true
golint 2>&1 | grep -v $(ngrep) || true
make todo
unused . || true
misspell *.go
gosimple || true

clean:
go clean
rm -f *~ _testdata/temp*
rm -f *~ *.test *.out _testdata/temp*

cover:
t=$(shell tempfile) ; go test -coverprofile $$t && go tool cover -html $$t && unlink $$t

cpu: clean
go test -run @ -bench . -cpuprofile cpu.out
go tool pprof -lines *.test cpu.out

edit:
gvim -p Makefile *.go

editor:
go fmt
go test -i
gofmt -l -s -w *.go
go test
go build

internalError:
egrep -ho '"internal error.*"' *.go | sort | cat -n

later:
@grep -n $(grep) LATER * || true
@grep -n $(grep) MAYBE * || true

mem: clean
go test -run @ -bench . -memprofile mem.out -memprofilerate 1 -timeout 24h
go tool pprof -lines -web -alloc_space *.test mem.out

nuke: clean
go clean -i

todo:
@grep -nr $(grep) ^[[:space:]]*_[[:space:]]*=[[:space:]][[:alpha:]][[:alnum:]]* * || true
@grep -nrw $(grep) BUG * || true
@grep -nrw $(grep) LATER * || true
@grep -nrw $(grep) MAYBE * || true
@grep -nrw $(grep) TODO * || true
@grep -nrw $(grep) println * || true
@grep -nr $(grep) TODO * || true
@grep -nr $(grep) BUG * || true
@grep -nr $(grep) [^[:alpha:]]println * || true
14 changes: 1 addition & 13 deletions all_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ package kv
import (
"encoding/binary"
"flag"
"fmt"
"io"
"io/ioutil"
"math"
Expand All @@ -27,20 +26,9 @@ import (
const sz0 = 144 // size of an empty KV DB

var (
oDB = flag.String("db", "", "DB to use in BenchmarkEnumerateDB")
oKeep = flag.Bool("keep", false, "do not delete test DB (some tests)")
oDB = flag.String("db", "", "DB to use in BenchmarkEnumerateDB")
)

func dbg(s string, va ...interface{}) {
if s == "" {
s = strings.Repeat("%v ", len(va))
}
_, fn, fl, _ := runtime.Caller(1)
fmt.Printf("%s:%d: ", path.Base(fn), fl)
fmt.Printf(s, va...)
fmt.Println()
}

func opts() *Options {
return &Options{
noClone: true,
Expand Down
6 changes: 5 additions & 1 deletion doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@
Package kv implements a simple and easy to use persistent key/value (KV) store.
Changelog
2016-07-11: KV now uses the stable version of lldb. (github.com/cznic/lldb).
The stored KV pairs are sorted in the key collation order defined by an user
supplied 'compare' function (passed as a field in Options).
Expand Down Expand Up @@ -76,7 +80,7 @@ Referenced from above:
[1]: http://en.wikipedia.org/wiki/ACID
[2]: http://en.wikipedia.org/wiki/2PC
[3]: http://en.wikipedia.org/wiki/Write_ahead_logging
[4]: http://godoc.org/github.com/cznic/exp/lldb#Allocator
[4]: http://godoc.org/github.com/cznic/lldb#Allocator
*/
package kv
27 changes: 1 addition & 26 deletions etc.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ package kv
import (
"bytes"
"fmt"

"github.com/cznic/fileutil"
)

type header struct {
Expand All @@ -22,7 +20,7 @@ func (h *header) rd(b []byte) error {
panic("internal error")
}

if h.magic = b[:4]; bytes.Compare(h.magic, []byte(magic)) != 0 {
if h.magic = b[:4]; !bytes.Equal(h.magic, []byte(magic)) {
return fmt.Errorf("Unknown file format")
}

Expand All @@ -31,26 +29,3 @@ func (h *header) rd(b []byte) error {
h.reserved = b[1:]
return nil
}

// Get a 7B int64 from b
func b2h(b []byte) (h int64) {
for _, v := range b[:7] {
h = h<<8 | int64(v)
}
return
}

// Put a 7B int64 into b
func h2b(b []byte, h int64) []byte {
for i := range b[:7] {
b[i], h = byte(h>>48), h<<8
}
return b
}

func noEof(e error) (err error) {
if !fileutil.IsEOF(e) {
err = e
}
return
}
4 changes: 2 additions & 2 deletions kv.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ import (
"time"

"github.com/cznic/bufs"
"github.com/cznic/exp/lldb"
"github.com/cznic/fileutil"
"github.com/cznic/lldb"
)

const (
Expand Down Expand Up @@ -335,7 +335,7 @@ func (db *DB) Close() (err error) {
}

func (db *DB) close() (err error) {
// We are safe to close due to locked db.closeMu, but not safe aginst
// We are safe to close due to locked db.closeMu, but not safe against
// any other goroutine concurrently calling other exported db methods,
// causing a race[0] in the db.enter() mechanism. So we must lock
// db.bkl.
Expand Down
46 changes: 35 additions & 11 deletions kvaudit/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,54 @@
# Use of this source code is governed by a BSD-style
# license that can be found in the LICENSE file.

.PHONY: all editor todo clean nuke
.PHONY: all clean cover cpu editor internalError later mem nuke todo edit

grep=--include=*.go --include=*.run --include=*.y
grep=--include=*.go --include=*.l --include=*.y --include=*.yy
ngrep='TODOOK\|parser\.go\|scanner\.go\|.*_string\.go'

all: editor
go vet
go install
go clean
go vet 2>&1 | grep -v $(ngrep) || true
golint 2>&1 | grep -v $(ngrep) || true
make todo
unused . || true
misspell *.go
gosimple || true

clean:
go clean
rm -f *~ *.test *.out

cover:
t=$(shell tempfile) ; go test -coverprofile $$t && go tool cover -html $$t && unlink $$t

cpu: clean
go test -run @ -bench . -cpuprofile cpu.out
go tool pprof -lines *.test cpu.out

edit:
gvim -p Makefile *.go

editor:
go fmt
go test -i
gofmt -l -s -w *.go
go test
go build

nuke:
internalError:
egrep -ho '"internal error.*"' *.go | sort | cat -n

later:
@grep -n $(grep) LATER * || true
@grep -n $(grep) MAYBE * || true

mem: clean
go test -run @ -bench . -memprofile mem.out -memprofilerate 1 -timeout 24h
go tool pprof -lines -web -alloc_space *.test mem.out

nuke: clean
go clean -i

todo:
@grep -nr $(grep) ^[[:space:]]*_[[:space:]]*=[[:space:]][[:alpha:]][[:alnum:]]* * || true
@grep -nrw $(grep) TODO * || true
@grep -nrw $(grep) BUG * || true
@grep -nrw $(grep) println * || true
@grep -nr $(grep) TODO * || true
@grep -nr $(grep) BUG * || true
@grep -nr $(grep) [^[:alpha:]]println * || true
6 changes: 3 additions & 3 deletions kvaudit/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
Command kvaudit verifies kv databases.
Instalation:
Installation:
$ go get github.com/cznic/kv/kvaudit
Expand Down Expand Up @@ -55,7 +55,7 @@ Links
Referenced from above:
[0]: http://godoc.org/github.com/cznic/exp/lldb#Allocator.Verify
[0]: http://godoc.org/github.com/cznic/lldb#Allocator.Verify
[1]: https://code.google.com/p/camlistore/issues/detail?id=216
[2]: http://cr.yp.to/cdb/cdbmake.html
Expand All @@ -71,7 +71,7 @@ import (
"io/ioutil"
"os"

"github.com/cznic/exp/lldb"
"github.com/cznic/lldb"
)

func rep(s string, a ...interface{}) {
Expand Down
4 changes: 2 additions & 2 deletions options.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
"path/filepath"
"time"

"github.com/cznic/exp/lldb"
"github.com/cznic/lldb"
)

const (
Expand All @@ -36,7 +36,7 @@ const (
// WAL. Updates to the DB will be first made permanent in a WAL and
// only after that reflected in the DB. A DB will automatically recover
// from crashes and/or any other non clean DB shutdown. Only last
// uncommited transaction (transaction in progress ATM of a crash) can
// uncommitted transaction (transaction in progress ATM of a crash) can
// get lost.
//
// NOTE: Options.GracePeriod may extend the span of a single
Expand Down
2 changes: 1 addition & 1 deletion v0.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ package kv
import (
"os"

"github.com/cznic/exp/lldb"
"github.com/cznic/lldb"
)

func open00(name string, in *DB) (db *DB, err error) {
Expand Down
2 changes: 1 addition & 1 deletion verify.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"io/ioutil"
"os"

"github.com/cznic/exp/lldb"
"github.com/cznic/lldb"
)

func verifyAllocator(a *lldb.Allocator) error {
Expand Down

0 comments on commit 48b826e

Please sign in to comment.