Skip to content

Commit

Permalink
Upgrade go-msgpack to v2 2.1.1
Browse files Browse the repository at this point in the history
This adds the option to specify what version of the `time.Time` encoding
format is desired. The default option is false, which preserves
compatibility with the current dependency of
`hashicorp/go-msgpack 0.5.5` in go.mod, but users of this library will
probably want to override the the setting.

While we're here, upgrade the go.mod file.

I tested that this appears to work with Nomad.

This needs to be updated and merged after
hashicorp/raft#577
  • Loading branch information
Christopher Swenson committed Oct 19, 2023
1 parent 2a80828 commit ea49498
Show file tree
Hide file tree
Showing 4 changed files with 218 additions and 26 deletions.
17 changes: 13 additions & 4 deletions v2/bolt_store.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"os"
"time"

metrics "github.com/armon/go-metrics"
"github.com/armon/go-metrics"
v1 "github.com/boltdb/bolt"
"github.com/hashicorp/raft"
"go.etcd.io/bbolt"
Expand Down Expand Up @@ -36,6 +36,8 @@ type BoltStore struct {

// The path to the Bolt database file
path string

msgpackUseNewTimeFormat bool
}

// Options contains all the configuration used to open the Bbolt
Expand All @@ -51,6 +53,12 @@ type Options struct {
// write to the log. This is unsafe, so it should be used
// with caution.
NoSync bool

// MsgpackUseNewTimeFormat is used to force the underlying msgpack codec to
// use the newer format of time.Time when encoding, used in versions <=0.5.5
// by default. Decoding is not affected, as all decoders know how to decode
// both formats.
MsgpackUseNewTimeFormat bool
}

// readOnly returns true if the contained bolt options say to open
Expand All @@ -76,8 +84,9 @@ func New(options Options) (*BoltStore, error) {

// Create the new store
store := &BoltStore{
conn: handle,
path: options.Path,
conn: handle,
path: options.Path,
msgpackUseNewTimeFormat: options.MsgpackUseNewTimeFormat,
}

// If the store was opened read-only, don't try and create buckets
Expand Down Expand Up @@ -188,7 +197,7 @@ func (b *BoltStore) StoreLogs(logs []*raft.Log) error {
batchSize := 0
for _, log := range logs {
key := uint64ToBytes(log.Index)
val, err := encodeMsgPack(log)
val, err := encodeMsgPack(log, b.msgpackUseNewTimeFormat)
if err != nil {
return err
}
Expand Down
21 changes: 17 additions & 4 deletions v2/go.mod
Original file line number Diff line number Diff line change
@@ -1,12 +1,25 @@
module github.com/hashicorp/raft-boltdb/v2

go 1.16
go 1.20

require (
github.com/armon/go-metrics v0.0.0-20190430140413-ec5e00d3c878
github.com/armon/go-metrics v0.4.1
github.com/boltdb/bolt v1.3.1
github.com/hashicorp/go-msgpack v0.5.5
github.com/hashicorp/go-msgpack/v2 v2.1.1
github.com/hashicorp/raft v1.1.0
github.com/hashicorp/raft-boltdb v0.0.0-20210409134258-03c10cc3d4ea
github.com/hashicorp/raft-boltdb v0.0.0-20230125174641-2a8082862702
go.etcd.io/bbolt v1.3.5
)

require (
github.com/fatih/color v1.13.0 // indirect
github.com/hashicorp/go-hclog v1.5.0 // indirect
github.com/hashicorp/go-immutable-radix v1.0.0 // indirect
github.com/hashicorp/go-msgpack v0.5.5 // indirect
github.com/hashicorp/golang-lru v0.5.0 // indirect
github.com/mattn/go-colorable v0.1.12 // indirect
github.com/mattn/go-isatty v0.0.14 // indirect
golang.org/x/sys v0.13.0 // indirect
)

replace github.com/hashicorp/raft => /Users/swenson/projects/raft
Loading

0 comments on commit ea49498

Please sign in to comment.