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

This commit is contained in:
Kyle Havlovitz 2016-11-09 20:10:03 -05:00 committed by James Phillips
parent e32ef962e1
commit b2cdba8fcf
2 changed files with 26 additions and 13 deletions

View File

@ -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)
}

6
vendor/vendor.json vendored
View File

@ -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=",