Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade armon/go-metrics to hashicorp/go-metrics #33

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
* @hashicorp/consul-core-reviewers

/.release/ @hashicorp/release-engineering
/.github/workflows/ci.yml @hashicorp/release-engineering
7 changes: 7 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
version: 2

updates:
- package-ecosystem: "gomod"
directory: "/"
schedule:
interval: "weekly"
37 changes: 37 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
name: ci

on:
pull_request:
branches: ["master"]
push:
branches: ["master"]
tags: ["*"]

jobs:
go-fmt-and-vet:
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@ac593985615ec2ede58e132d2e21d2b1cbd6127c # [email protected]
- uses: actions/setup-go@6edd4406fa81c3da01a34fa6f6343087c207a568 # [email protected]
with:
go-version-file: "go.mod"
cache: true
- run: |
files=$(go fmt ./...)
if [ -n "$files" ]; then
echo "The following file(s) do not conform to go fmt:"
echo "$files"
exit 1
fi
- run: go vet ./...

go-test:
needs: go-fmt-and-vet
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@ac593985615ec2ede58e132d2e21d2b1cbd6127c # [email protected]
- uses: actions/setup-go@6edd4406fa81c3da01a34fa6f6343087c207a568 # [email protected]
with:
go-version-file: "go.mod"
cache: true
- run: go test -race ./...
10 changes: 0 additions & 10 deletions .travis.yml

This file was deleted.

11 changes: 3 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,9 @@
raft-boltdb
raft-boltdb/v3
===========

This repository provides the `raftboltdb` package. The package exports the
`BoltStore` which is an implementation of both a `LogStore` and `StableStore`.
This implementation uses the maintained version of BoltDB, [BBolt](https://github.com/etcd-io/bbolt). This is the primary version of `raft-boltdb` and should be used whenever possible.

It is meant to be used as a backend for the `raft` [package
here](https://github.com/hashicorp/raft).

This implementation uses [BoltDB](https://github.com/boltdb/bolt). BoltDB is
a simple key/value store implemented in pure Go, and inspired by LMDB.
There is no breaking API change with v2 of the library outside of removing the v1 to v2 migration code. V3 does change the module used for metrics from github.com/armon/go-metrics to github.com/hashicorp/go-metrics. You should ensure that this version of the library is only used with a version of Raft and your application that are using github.com/hashicorp/go-metrics. If not, then the metrics emission will not work properly.

## Metrics

Expand Down
29 changes: 18 additions & 11 deletions bolt_store.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import (
"errors"
"time"

metrics "github.com/armon/go-metrics"
"github.com/boltdb/bolt"
metrics "github.com/hashicorp/go-metrics"
"github.com/hashicorp/raft"
"go.etcd.io/bbolt"
)

const (
Expand All @@ -24,25 +24,25 @@ var (
ErrKeyNotFound = errors.New("not found")
)

// BoltStore provides access to BoltDB for Raft to store and retrieve
// BoltStore provides access to Bbolt for Raft to store and retrieve
// log entries. It also provides key/value storage, and can be used as
// a LogStore and StableStore.
type BoltStore struct {
// conn is the underlying handle to the db.
conn *bolt.DB
conn *bbolt.DB

// The path to the Bolt database file
path string
}

// Options contains all the configuration used to open the BoltDB
// Options contains all the configuration used to open the Bbolt
type Options struct {
// Path is the file path to the BoltDB to use
// Path is the file path to the Bbolt to use
Path string

// BoltOptions contains any specific BoltDB options you might
// BoltOptions contains any specific Bbolt options you might
// want to specify [e.g. open timeout]
BoltOptions *bolt.Options
BoltOptions *bbolt.Options

// NoSync causes the database to skip fsync calls after each
// write to the log. This is unsafe, so it should be used
Expand All @@ -62,10 +62,10 @@ func NewBoltStore(path string) (*BoltStore, error) {
return New(Options{Path: path})
}

// New uses the supplied options to open the BoltDB and prepare it for use as a raft backend.
// New uses the supplied options to open the Bbolt and prepare it for use as a raft backend.
func New(options Options) (*BoltStore, error) {
// Try to connect
handle, err := bolt.Open(options.Path, dbFileMode, options.BoltOptions)
handle, err := bbolt.Open(options.Path, dbFileMode, options.BoltOptions)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -107,6 +107,10 @@ func (b *BoltStore) initialize() error {
return tx.Commit()
}

func (b *BoltStore) Stats() bbolt.Stats {
return b.conn.Stats()
}

// Close is used to gracefully close the DB connection.
func (b *BoltStore) Close() error {
return b.conn.Close()
Expand Down Expand Up @@ -144,8 +148,10 @@ func (b *BoltStore) LastIndex() (uint64, error) {
}
}

// GetLog is used to retrieve a log from BoltDB at a given index.
// GetLog is used to retrieve a log from Bbolt at a given index.
func (b *BoltStore) GetLog(idx uint64, log *raft.Log) error {
defer metrics.MeasureSince([]string{"raft", "boltdb", "getLog"}, time.Now())

tx, err := b.conn.Begin(false)
if err != nil {
return err
Expand All @@ -169,6 +175,7 @@ func (b *BoltStore) StoreLog(log *raft.Log) error {
// StoreLogs is used to store a set of raft logs
func (b *BoltStore) StoreLogs(logs []*raft.Log) error {
now := time.Now()

tx, err := b.conn.Begin(true)
if err != nil {
return err
Expand Down
16 changes: 8 additions & 8 deletions bolt_store_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import (
"testing"
"time"

"github.com/boltdb/bolt"
"github.com/hashicorp/raft"
"go.etcd.io/bbolt"
)

func testBoltStore(t testing.TB) *BoltStore {
Expand Down Expand Up @@ -54,7 +54,7 @@ func TestBoltOptionsTimeout(t *testing.T) {
defer os.Remove(fh.Name())
options := Options{
Path: fh.Name(),
BoltOptions: &bolt.Options{
BoltOptions: &bbolt.Options{
Timeout: time.Second / 10,
},
}
Expand Down Expand Up @@ -102,7 +102,7 @@ func TestBoltOptionsReadOnly(t *testing.T) {
store.Close()
options := Options{
Path: fh.Name(),
BoltOptions: &bolt.Options{
BoltOptions: &bbolt.Options{
Timeout: time.Second / 10,
ReadOnly: true,
},
Expand All @@ -123,8 +123,8 @@ func TestBoltOptionsReadOnly(t *testing.T) {
}
// Attempt to store the log, should fail on a read-only store
err = roStore.StoreLog(log)
if err != bolt.ErrDatabaseReadOnly {
t.Errorf("expecting error %v, but got %v", bolt.ErrDatabaseReadOnly, err)
if err != bbolt.ErrDatabaseReadOnly {
t.Errorf("expecting error %v, but got %v", bbolt.ErrDatabaseReadOnly, err)
}
}

Expand Down Expand Up @@ -156,18 +156,18 @@ func TestNewBoltStore(t *testing.T) {
}

// Ensure our tables were created
db, err := bolt.Open(fh.Name(), dbFileMode, nil)
db, err := bbolt.Open(fh.Name(), dbFileMode, nil)
if err != nil {
t.Fatalf("err: %s", err)
}
tx, err := db.Begin(true)
if err != nil {
t.Fatalf("err: %s", err)
}
if _, err := tx.CreateBucket([]byte(dbLogs)); err != bolt.ErrBucketExists {
if _, err := tx.CreateBucket([]byte(dbLogs)); err != bbolt.ErrBucketExists {
t.Fatalf("bad: %v", err)
}
if _, err := tx.CreateBucket([]byte(dbConf)); err != bolt.ErrBucketExists {
if _, err := tx.CreateBucket([]byte(dbConf)); err != bbolt.ErrBucketExists {
t.Fatalf("bad: %v", err)
}
}
Expand Down
5 changes: 3 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
module github.com/hashicorp/raft-boltdb
module github.com/hashicorp/raft-boltdb/v3

go 1.16

require (
github.com/armon/go-metrics v0.3.8 // indirect
github.com/boltdb/bolt v1.3.1
github.com/hashicorp/go-metrics v0.5.1
github.com/hashicorp/go-msgpack v0.5.5
github.com/hashicorp/raft v1.1.0
go.etcd.io/bbolt v1.3.5
)
11 changes: 8 additions & 3 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf/go.mod h1:ybxpYRF
github.com/alecthomas/units v0.0.0-20190717042225-c3de453c63f4/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0=
github.com/armon/go-metrics v0.0.0-20190430140413-ec5e00d3c878 h1:EFSB7Zo9Eg91v7MJPVsifUysc/wPdN+NOnVe6bWbdBM=
github.com/armon/go-metrics v0.0.0-20190430140413-ec5e00d3c878/go.mod h1:3AMJUQhVx52RsWOnlkpikZr01T/yAVN2gn0861vByNg=
github.com/armon/go-metrics v0.3.8 h1:oOxq3KPj0WhCuy50EhzwiyMyG2ovRQZpZLXQuOh2a/M=
github.com/armon/go-metrics v0.3.8/go.mod h1:4O98XIr/9W0sxpJ8UaYkvjk10Iff7SnFrb4QAOwNTFc=
github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24TaqPxmxbtue+5NUziq4I4S80YR8gNf3Q=
github.com/beorn7/perks v1.0.0/go.mod h1:KWe93zE9D1o94FZ5RNwFwVgaQK1VOXiVxmqh+CedLV8=
github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw=
Expand Down Expand Up @@ -36,6 +34,8 @@ github.com/hashicorp/go-hclog v0.9.1 h1:9PZfAcVEvez4yhLH2TBU64/h/z4xlFI80cWXRrxu
github.com/hashicorp/go-hclog v0.9.1/go.mod h1:5CU+agLiy3J7N7QjHK5d05KxGsuXiQLrjA0H7acj2lQ=
github.com/hashicorp/go-immutable-radix v1.0.0 h1:AKDB1HM5PWEA7i4nhcpwOrO2byshxBjXVn/J/3+z5/0=
github.com/hashicorp/go-immutable-radix v1.0.0/go.mod h1:0y9vanUI8NX6FsYoO3zeMjhV/C5i9g4Q3DwcSNZ4P60=
github.com/hashicorp/go-metrics v0.5.1 h1:rfPwUqFU6uZXNvGl4hzjY8LEBsqFVU4si1H9/Hqck/U=
github.com/hashicorp/go-metrics v0.5.1/go.mod h1:KEjodfebIOuBYSAe/bHTm+HChmKSxAOXPBieMLYozDE=
github.com/hashicorp/go-msgpack v0.5.5 h1:i9R9JSrqIz0QVLz3sz+i3YJdT7TTSLcfLLzJi9aZTuI=
github.com/hashicorp/go-msgpack v0.5.5/go.mod h1:ahLV/dePpqEmjfWmKiqvPkv/twdG7iPBM1vqhUKIvfM=
github.com/hashicorp/go-retryablehttp v0.5.3/go.mod h1:9B5zBasrRhHXnJnui7y6sL7es7NDiJgTc6Er0maI1Xs=
Expand Down Expand Up @@ -84,10 +84,12 @@ github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6Mwd
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
github.com/stretchr/testify v1.3.0 h1:TivCn/peBQ7UY8ooIcPgZFpTNSz0Q2U6UrFlUfqbe0Q=
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
github.com/stretchr/testify v1.4.0 h1:2E4SXV/wtOkTonXsotYi4li6zVWxYlZuYNCXe9XRJyk=
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
github.com/tv42/httpunix v0.0.0-20150427012821-b75d8614f926/go.mod h1:9ESjWnEqriFuLhtthL60Sar/7RFoluCcXsuvEwTV5KM=
go.etcd.io/bbolt v1.3.5 h1:XAzx9gjCb0Rxj7EoqcClPD1d5ZBxZJk0jbuoPHenBt0=
go.etcd.io/bbolt v1.3.5/go.mod h1:G5EMThwa9y8QZGBClrRx5EY+Yw9kAhnjy3bSjsnlVTQ=
golang.org/x/crypto v0.0.0-20180904163835-0709b304e793/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/net v0.0.0-20181114220301-adae6a3d119a/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
Expand All @@ -101,6 +103,8 @@ golang.org/x/sys v0.0.0-20181116152217-5ac8a444bdc5/go.mod h1:STP8DvDyc/dI5b8T5h
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190422165155-953cdadca894/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200122134326-e047566fdf82/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200202164722-d101bd2416d5 h1:LfCXLvNmTYH9kEmVgqbnsWfruoXZIrh4YBgqVHtDvw0=
golang.org/x/sys v0.0.0-20200202164722-d101bd2416d5/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw=
Expand All @@ -109,4 +113,5 @@ gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8
gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.2.5 h1:ymVxjfMaHvXD8RqPRmzHHsB3VvucivSkIAvJFDI5O3c=
gopkg.in/yaml.v2 v2.2.5/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
6 changes: 3 additions & 3 deletions metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import (
"context"
"time"

metrics "github.com/armon/go-metrics"
"github.com/boltdb/bolt"
metrics "github.com/hashicorp/go-metrics"
"go.etcd.io/bbolt"
)

const (
Expand Down Expand Up @@ -33,7 +33,7 @@ func (b *BoltStore) RunMetrics(ctx context.Context, interval time.Duration) {
}
}

func (b *BoltStore) emitMetrics(prev *bolt.Stats) *bolt.Stats {
func (b *BoltStore) emitMetrics(prev *bbolt.Stats) *bbolt.Stats {
newStats := b.conn.Stats()

stats := newStats
Expand Down
37 changes: 0 additions & 37 deletions v2/README.md

This file was deleted.

Loading