Skip to content

Commit

Permalink
Merge pull request #38 from hashicorp/vault-19781/msgpack-upgrade
Browse files Browse the repository at this point in the history
Upgrade go-msgpack to v2 2.1.1
  • Loading branch information
Christopher Swenson authored Nov 15, 2023
2 parents 2a80828 + c696b73 commit 027066e
Show file tree
Hide file tree
Showing 4 changed files with 219 additions and 27 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 when set to true, force the underlying msgpack
// codec to use the new format of time.Time when encoding (used in
// go-msgpack v1.1.5 by default). Decoding is not affected, as all
// go-msgpack v2.1.0+ 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
23 changes: 18 additions & 5 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/raft v1.1.0
github.com/hashicorp/raft-boltdb v0.0.0-20210409134258-03c10cc3d4ea
github.com/hashicorp/go-msgpack/v2 v2.1.1
github.com/hashicorp/raft v1.6.0
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 027066e

Please sign in to comment.