Browse Source

Update raft deps to fix snapshot races in -dev mode (#2498)

pull/2499/head
Kyle Havlovitz 8 years ago committed by James Phillips
parent
commit
b2cdba8fcf
  1. 33
      vendor/github.com/hashicorp/raft/inmem_snapshot.go
  2. 6
      vendor/vendor.json

33
vendor/github.com/hashicorp/raft/inmem_snapshot.go generated vendored

@ -5,6 +5,7 @@ import (
"fmt" "fmt"
"io" "io"
"io/ioutil" "io/ioutil"
"sync"
) )
// InmemSnapshotStore implements the SnapshotStore interface and // InmemSnapshotStore implements the SnapshotStore interface and
@ -12,6 +13,7 @@ import (
type InmemSnapshotStore struct { type InmemSnapshotStore struct {
latest *InmemSnapshotSink latest *InmemSnapshotSink
hasSnapshot bool hasSnapshot bool
sync.RWMutex
} }
// InmemSnapshotSink implements SnapshotSink in memory // InmemSnapshotSink implements SnapshotSink in memory
@ -39,24 +41,32 @@ func (m *InmemSnapshotStore) Create(version SnapshotVersion, index, term uint64,
name := snapshotName(term, index) name := snapshotName(term, index)
sink := m.latest m.Lock()
sink.meta = SnapshotMeta{ defer m.Unlock()
Version: version,
ID: name, sink := &InmemSnapshotSink{
Index: index, meta: SnapshotMeta{
Term: term, Version: version,
Peers: encodePeers(configuration, trans), ID: name,
Configuration: configuration, Index: index,
ConfigurationIndex: configurationIndex, Term: term,
Peers: encodePeers(configuration, trans),
Configuration: configuration,
ConfigurationIndex: configurationIndex,
},
contents: &bytes.Buffer{},
} }
sink.contents = &bytes.Buffer{}
m.hasSnapshot = true m.hasSnapshot = true
m.latest = sink
return sink, nil return sink, nil
} }
// List returns the latest snapshot taken // List returns the latest snapshot taken
func (m *InmemSnapshotStore) List() ([]*SnapshotMeta, error) { func (m *InmemSnapshotStore) List() ([]*SnapshotMeta, error) {
m.RLock()
defer m.RUnlock()
if !m.hasSnapshot { if !m.hasSnapshot {
return []*SnapshotMeta{}, nil return []*SnapshotMeta{}, nil
} }
@ -65,6 +75,9 @@ func (m *InmemSnapshotStore) List() ([]*SnapshotMeta, error) {
// Open wraps an io.ReadCloser around the snapshot contents // Open wraps an io.ReadCloser around the snapshot contents
func (m *InmemSnapshotStore) Open(id string) (*SnapshotMeta, io.ReadCloser, error) { func (m *InmemSnapshotStore) Open(id string) (*SnapshotMeta, io.ReadCloser, error) {
m.RLock()
defer m.RUnlock()
if m.latest.meta.ID != id { if m.latest.meta.ID != id {
return nil, nil, fmt.Errorf("[ERR] snapshot: failed to open snapshot id: %s", id) return nil, nil, fmt.Errorf("[ERR] snapshot: failed to open snapshot id: %s", id)
} }

6
vendor/vendor.json vendored

@ -506,10 +506,10 @@
"revisionTime": "2015-11-16T02:03:38Z" "revisionTime": "2015-11-16T02:03:38Z"
}, },
{ {
"checksumSHA1": "ed1YY/S0BSb57IRRSDUbFp7r0IE=", "checksumSHA1": "hwvKyyRujRkxMtrdwigHuE5SIyo=",
"path": "github.com/hashicorp/raft", "path": "github.com/hashicorp/raft",
"revision": "def7451ceceb8a919cbb1f6d1c0f7648e9311879", "revision": "aaad9f10266e089bd401e7a6487651a69275641b",
"revisionTime": "2016-10-31T16:57:40Z" "revisionTime": "2016-11-10T00:52:40Z"
}, },
{ {
"checksumSHA1": "QAxukkv54/iIvLfsUP6IK4R0m/A=", "checksumSHA1": "QAxukkv54/iIvLfsUP6IK4R0m/A=",

Loading…
Cancel
Save