Skip to content

Commit ea49498

Browse files
author
Christopher Swenson
committed
Upgrade go-msgpack to v2 2.1.1
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
1 parent 2a80828 commit ea49498

File tree

4 files changed

+218
-26
lines changed

4 files changed

+218
-26
lines changed

v2/bolt_store.go

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import (
66
"os"
77
"time"
88

9-
metrics "github.com/armon/go-metrics"
9+
"github.com/armon/go-metrics"
1010
v1 "github.com/boltdb/bolt"
1111
"github.com/hashicorp/raft"
1212
"go.etcd.io/bbolt"
@@ -36,6 +36,8 @@ type BoltStore struct {
3636

3737
// The path to the Bolt database file
3838
path string
39+
40+
msgpackUseNewTimeFormat bool
3941
}
4042

4143
// Options contains all the configuration used to open the Bbolt
@@ -51,6 +53,12 @@ type Options struct {
5153
// write to the log. This is unsafe, so it should be used
5254
// with caution.
5355
NoSync bool
56+
57+
// MsgpackUseNewTimeFormat is used to force the underlying msgpack codec to
58+
// use the newer format of time.Time when encoding, used in versions <=0.5.5
59+
// by default. Decoding is not affected, as all decoders know how to decode
60+
// both formats.
61+
MsgpackUseNewTimeFormat bool
5462
}
5563

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

7785
// Create the new store
7886
store := &BoltStore{
79-
conn: handle,
80-
path: options.Path,
87+
conn: handle,
88+
path: options.Path,
89+
msgpackUseNewTimeFormat: options.MsgpackUseNewTimeFormat,
8190
}
8291

8392
// If the store was opened read-only, don't try and create buckets
@@ -188,7 +197,7 @@ func (b *BoltStore) StoreLogs(logs []*raft.Log) error {
188197
batchSize := 0
189198
for _, log := range logs {
190199
key := uint64ToBytes(log.Index)
191-
val, err := encodeMsgPack(log)
200+
val, err := encodeMsgPack(log, b.msgpackUseNewTimeFormat)
192201
if err != nil {
193202
return err
194203
}

v2/go.mod

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,25 @@
11
module github.com/hashicorp/raft-boltdb/v2
22

3-
go 1.16
3+
go 1.20
44

55
require (
6-
github.com/armon/go-metrics v0.0.0-20190430140413-ec5e00d3c878
6+
github.com/armon/go-metrics v0.4.1
77
github.com/boltdb/bolt v1.3.1
8-
github.com/hashicorp/go-msgpack v0.5.5
8+
github.com/hashicorp/go-msgpack/v2 v2.1.1
99
github.com/hashicorp/raft v1.1.0
10-
github.com/hashicorp/raft-boltdb v0.0.0-20210409134258-03c10cc3d4ea
10+
github.com/hashicorp/raft-boltdb v0.0.0-20230125174641-2a8082862702
1111
go.etcd.io/bbolt v1.3.5
1212
)
13+
14+
require (
15+
github.com/fatih/color v1.13.0 // indirect
16+
github.com/hashicorp/go-hclog v1.5.0 // indirect
17+
github.com/hashicorp/go-immutable-radix v1.0.0 // indirect
18+
github.com/hashicorp/go-msgpack v0.5.5 // indirect
19+
github.com/hashicorp/golang-lru v0.5.0 // indirect
20+
github.com/mattn/go-colorable v0.1.12 // indirect
21+
github.com/mattn/go-isatty v0.0.14 // indirect
22+
golang.org/x/sys v0.13.0 // indirect
23+
)
24+
25+
replace github.com/hashicorp/raft => /Users/swenson/projects/raft

0 commit comments

Comments
 (0)