diff --git a/vendor/github.com/hashicorp/raft/inmem_snapshot.go b/vendor/github.com/hashicorp/raft/inmem_snapshot.go index 3eb6adb98..3aa92b3e9 100644 --- a/vendor/github.com/hashicorp/raft/inmem_snapshot.go +++ b/vendor/github.com/hashicorp/raft/inmem_snapshot.go @@ -5,6 +5,7 @@ import ( "fmt" "io" "io/ioutil" + "sync" ) // InmemSnapshotStore implements the SnapshotStore interface and @@ -12,6 +13,7 @@ import ( type InmemSnapshotStore struct { latest *InmemSnapshotSink hasSnapshot bool + sync.RWMutex } // InmemSnapshotSink implements SnapshotSink in memory @@ -39,24 +41,32 @@ func (m *InmemSnapshotStore) Create(version SnapshotVersion, index, term uint64, name := snapshotName(term, index) - sink := m.latest - sink.meta = SnapshotMeta{ - Version: version, - ID: name, - Index: index, - Term: term, - Peers: encodePeers(configuration, trans), - Configuration: configuration, - ConfigurationIndex: configurationIndex, + m.Lock() + defer m.Unlock() + + sink := &InmemSnapshotSink{ + meta: SnapshotMeta{ + Version: version, + ID: name, + Index: index, + Term: term, + Peers: encodePeers(configuration, trans), + Configuration: configuration, + ConfigurationIndex: configurationIndex, + }, + contents: &bytes.Buffer{}, } - sink.contents = &bytes.Buffer{} m.hasSnapshot = true + m.latest = sink return sink, nil } // List returns the latest snapshot taken func (m *InmemSnapshotStore) List() ([]*SnapshotMeta, error) { + m.RLock() + defer m.RUnlock() + if !m.hasSnapshot { return []*SnapshotMeta{}, nil } @@ -65,6 +75,9 @@ func (m *InmemSnapshotStore) List() ([]*SnapshotMeta, error) { // Open wraps an io.ReadCloser around the snapshot contents func (m *InmemSnapshotStore) Open(id string) (*SnapshotMeta, io.ReadCloser, error) { + m.RLock() + defer m.RUnlock() + if m.latest.meta.ID != id { return nil, nil, fmt.Errorf("[ERR] snapshot: failed to open snapshot id: %s", id) } diff --git a/vendor/vendor.json b/vendor/vendor.json index 6f485d5c0..caf6ba283 100644 --- a/vendor/vendor.json +++ b/vendor/vendor.json @@ -506,10 +506,10 @@ "revisionTime": "2015-11-16T02:03:38Z" }, { - "checksumSHA1": "ed1YY/S0BSb57IRRSDUbFp7r0IE=", + "checksumSHA1": "hwvKyyRujRkxMtrdwigHuE5SIyo=", "path": "github.com/hashicorp/raft", - "revision": "def7451ceceb8a919cbb1f6d1c0f7648e9311879", - "revisionTime": "2016-10-31T16:57:40Z" + "revision": "aaad9f10266e089bd401e7a6487651a69275641b", + "revisionTime": "2016-11-10T00:52:40Z" }, { "checksumSHA1": "QAxukkv54/iIvLfsUP6IK4R0m/A=",