diff --git a/.circleci/config.yml b/.circleci/config.yml index fcc525e35..4cd482e53 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -2,7 +2,7 @@ version: 2 jobs: build: docker: - - image: circleci/golang + - image: tendermintdev/docker-tm-db-testing steps: - checkout diff --git a/README.md b/README.md index b864ccc3a..f729f54b6 100644 --- a/README.md +++ b/README.md @@ -2,3 +2,49 @@ Data Base abstractions to be used in applications. These abstractions are not only meant to be used in applications built on [Tendermint](https://github.com/tendermint/tendermint), but can be used in a variety of applications. + +### Minimum Go Version + +Go 1.13+ + +## Supported Databases + +- [GolevelDB](https://github.com/syndtr/goleveldb) +- [ClevelDB](https://github.com/google/leveldb) +- [BoltDB](https://github.com/etcd-io/bbolt) +- [GoRocksDB](https://github.com/tecbot/gorocksdb) +- [MemDB](#memdb) +- [RemoteDB](#remotedb) + + +## Using Databases + +### GolevelDB + +To use goleveldb there is no need to install anything and you can run the tests by simply running `make test` + +### ClevelDB + +To use cleveldb leveldb must be installed on your machine. Please use you local package manager (brew, snap) to install the db. Once you have installed it you can run tests with `make test-cleveldb`. + +### BoltDB + +The BoltDB implementation uses bbolt from etcd. + +You can test boltdb by running `make test-boltdb` + +### RocksDB + +To use RocksDB, you must have it installed on your machine. You can install rocksdb by using your machines package manager (brew, snap). Once you have it installed you can run tests using `make test-rocksdb`. + +### MemDB + +MemDB is a go implementation of a in memory database. It is mainly used for testing purposes but can be used for other purposes as well. To test the database you can run `make test`. + +### RemoteDB + +RemoteDB is a database meant for connecting to distributed Tendermint db instances. This can help with detaching difficult deployments such as cleveldb, it can also ease +the burden and cost of deployment of dependencies for databases +to be used by Tendermint developers. It is built with [gRPC](https://grpc.io/). To test this data base you can run `make test`. + +If you have all the databases installed on your machine then you can run tests with `make test-all` diff --git a/boltdb.go b/boltdb.go index 5b9d22027..0c28bf291 100644 --- a/boltdb.go +++ b/boltdb.go @@ -225,12 +225,12 @@ func (bdb *BoltDB) Iterator(start, end []byte) (Iterator, error) { // WARNING: Any concurrent writes or reads will block until the iterator is // closed. -func (bdb *BoltDB) ReverseIterator(start, end []byte) Iterator { +func (bdb *BoltDB) ReverseIterator(start, end []byte) (Iterator, error) { tx, err := bdb.db.Begin(false) if err != nil { - panic(err) + return nil, err } - return newBoltDBIterator(tx, start, end, true) + return newBoltDBIterator(tx, start, end, true), nil } // boltDBIterator allows you to iterate on range of keys/values given some diff --git a/c_level_db_test.go b/c_level_db_test.go index 259f78945..57f3ebb4f 100644 --- a/c_level_db_test.go +++ b/c_level_db_test.go @@ -48,7 +48,10 @@ func BenchmarkRandomReadsWrites2(b *testing.B) { idx := (int64(rand.Int()) % numItems) val := internal[idx] idxBytes := int642Bytes(int64(idx)) - valBytes := db.Get(idxBytes) + valBytes, err := db.Get(idxBytes) + if err != nil { + b.Error(err) + } //fmt.Printf("Get %X -> %X\n", idxBytes, valBytes) if val == 0 { if !bytes.Equal(valBytes, nil) { diff --git a/go.mod b/go.mod index 47bb9fe74..ada3a7e93 100644 --- a/go.mod +++ b/go.mod @@ -13,7 +13,7 @@ require ( github.com/pkg/errors v0.9.1 github.com/stretchr/testify v1.4.0 github.com/syndtr/goleveldb v1.0.1-0.20190923125748-758128399b1d - github.com/tecbot/gorocksdb v0.0.0-20191017175515-d217d93fd4c5 + github.com/tecbot/gorocksdb v0.0.0-20191217155057-f0fad39f321c go.etcd.io/bbolt v1.3.3 // indirect golang.org/x/net v0.0.0-20190628185345-da137c7871d7 // indirect google.golang.org/grpc v1.26.0 diff --git a/go.sum b/go.sum index b2000edd8..e771b902c 100644 --- a/go.sum +++ b/go.sum @@ -6,7 +6,6 @@ github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8 github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/envoyproxy/go-control-plane v0.9.0/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4= github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4= github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c= github.com/etcd-io/bbolt v1.3.3 h1:gSJmxrs37LgTqR/oyJBWok6k6SvXEUerFTbltIhXkBM= @@ -29,6 +28,7 @@ github.com/golang/protobuf v1.3.2 h1:6nsPYzhq5kReh6QImI3k5qWzO4PEbvbIW2cwSfR/6xs github.com/golang/protobuf v1.3.2/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= github.com/golang/snappy v0.0.1 h1:Qgr9rKW7uDUkrbSmQeiDsGa8SjGyCOGtuasMWwvp2P4= github.com/golang/snappy v0.0.1/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q= +github.com/google/go-cmp v0.2.0 h1:+dTQ8DZQJz0Mb/HjFlkptS1FeQ4cWSnN941F8aEG4SQ= github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M= github.com/hpcloud/tail v1.0.0 h1:nfCOvKYfkgYP8hkirhJocXT2+zOD8yUNjXaWfTlyFKI= github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU= @@ -41,8 +41,6 @@ github.com/onsi/ginkgo v1.7.0 h1:WSHQ+IS43OoUrWtD1/bbclrwK8TTH5hzp+umCiuxHgs= github.com/onsi/ginkgo v1.7.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= github.com/onsi/gomega v1.4.3 h1:RE1xgDvH7imwFD45h+u2SgIfERHlS2yNG4DObb5BSKU= github.com/onsi/gomega v1.4.3/go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1CpauHY= -github.com/pkg/errors v0.8.1 h1:iURUrRGxPUNPdy5/HRSm+Yj6okJ6UtLINN0Q9M4+h3I= -github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= @@ -54,8 +52,8 @@ github.com/stretchr/testify v1.4.0 h1:2E4SXV/wtOkTonXsotYi4li6zVWxYlZuYNCXe9XRJy github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= github.com/syndtr/goleveldb v1.0.1-0.20190923125748-758128399b1d h1:gZZadD8H+fF+n9CmNhYL1Y0dJB+kLOmKd7FbPJLeGHs= github.com/syndtr/goleveldb v1.0.1-0.20190923125748-758128399b1d/go.mod h1:9OrXJhf154huy1nPWmuSrkgjPUtUNhA+Zmy+6AESzuA= -github.com/tecbot/gorocksdb v0.0.0-20191017175515-d217d93fd4c5 h1:gVwAW5OwaZlDB5/CfqcGFM9p9C+KxvQKyNOltQ8orj0= -github.com/tecbot/gorocksdb v0.0.0-20191017175515-d217d93fd4c5/go.mod h1:ahpPrc7HpcfEWDQRZEmnXMzHY03mLDYMCxeDzy46i+8= +github.com/tecbot/gorocksdb v0.0.0-20191217155057-f0fad39f321c h1:g+WoO5jjkqGAzHWCjJB1zZfXPIAaDpzXIEJ0eS6B5Ok= +github.com/tecbot/gorocksdb v0.0.0-20191217155057-f0fad39f321c/go.mod h1:ahpPrc7HpcfEWDQRZEmnXMzHY03mLDYMCxeDzy46i+8= go.etcd.io/bbolt v1.3.3 h1:MUGmc65QhB3pIlaQ5bB4LwqSj6GIonVJXpZiaKNyaKk= go.etcd.io/bbolt v1.3.3/go.mod h1:IbVyRI1SCnLcuJnV2u8VeU0CEYM7e686BmAb1XKL+uU= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= @@ -93,8 +91,6 @@ google.golang.org/genproto v0.0.0-20190819201941-24fa4b261c55 h1:gSJIx1SDwno+2El google.golang.org/genproto v0.0.0-20190819201941-24fa4b261c55/go.mod h1:DMBHOl98Agz4BDEuKkezgsaosCRResVns1a3J2ZsMNc= google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c= google.golang.org/grpc v1.23.0/go.mod h1:Y5yQAOtifL1yxbo5wqy6BxZv8vAUGQwXBOALyacEbxg= -google.golang.org/grpc v1.25.1 h1:wdKvqQk7IttEw92GoRyKG2IDrUIpgpj6H6m81yfeMW0= -google.golang.org/grpc v1.25.1/go.mod h1:c3i+UQWmh7LiEpx4sFZnkU36qjEYZ0imhYfXVyQciAY= google.golang.org/grpc v1.26.0 h1:2dTRdpdFEEhJYQD8EMLB61nnrzSCTbG38PhqdhvOltg= google.golang.org/grpc v1.26.0/go.mod h1:qbnxyOmOxrQa7FizSgH+ReBfzJrCY1pSN7KXBS8abTk= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= diff --git a/makefile b/makefile index c007d4aa3..db14c69fa 100644 --- a/makefile +++ b/makefile @@ -7,9 +7,26 @@ export GO111MODULE = on all: lint test ### go tests +## By default this will only test memdb & goleveldb test: @echo "--> Running go test" - @go test -p 1 $(PACKAGES) + @go test -p 1 $(PACKAGES) -v + +test-cleveldb: + @echo "--> Running go test" + @go test -p 1 $(PACKAGES) -tags cleveldb -v + +test-rocksdb: + @echo "--> Running go test" + @go test -p 1 $(PACKAGES) -tags rocksdb -v + +test-boltdb: + @echo "--> Running go test" + @go test -p 1 $(PACKAGES) -tags boltdb -v + +test-all: + @echo "--> Running go test" + @go test -p 1 $(PACKAGES) -tags cleveldb,boltdb,rocksdb -v lint: @echo "--> Running linter"