Skip to content

Commit

Permalink
Don't try to take 2 snapshots at a time
Browse files Browse the repository at this point in the history
Fix #943. Close #1081
  • Loading branch information
dgnorton authored and jvshahid committed Oct 31, 2014
1 parent de95dd6 commit 4b59ddd
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 0 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@

### Bugfixes

- [Issue #943](https://github.com/influxdb/influxdb/issues/943). Don't
take two snapshots at the same time
- [Issue #1085](https://github.com/influxdb/influxdb/issues/1085). Set
the connection string of the local raft node
- [Issue #996](https://github.com/influxdb/influxdb/issues/996). Fill should
Expand Down
2 changes: 2 additions & 0 deletions _vendor/raft/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -1203,6 +1203,7 @@ func (s *server) TakeSnapshot() error {

state, err := s.stateMachine.Save()
if err != nil {
s.pendingSnapshot = nil
return err
}

Expand Down Expand Up @@ -1237,6 +1238,7 @@ func (s *server) saveSnapshot() error {

// Write snapshot to disk.
if err := s.pendingSnapshot.save(); err != nil {
s.pendingSnapshot = nil
return err
}

Expand Down
13 changes: 13 additions & 0 deletions _vendor/raft/snapshot_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package raft

import (
"errors"
"fmt"
"io/ioutil"
"os"
Expand Down Expand Up @@ -121,6 +122,18 @@ func TestSnapshotRequest(t *testing.T) {
})
}

func TestTakeSnapshotWhenStateMachineSaveFails(t *testing.T) {
runServerWithMockStateMachine(Leader, func(s Server, m *mock.Mock) {
m.On("Save").Return([]byte("foo"), errors.New("test error message"))

s.Do(&testCommand1{})
err := s.TakeSnapshot()
assert.Equal(t, err.Error(), "test error message")
assert.Nil(t, s.(*server).pendingSnapshot)
s.Stop()
})
}

func runServerWithMockStateMachine(state string, fn func(s Server, m *mock.Mock)) {
var m mockStateMachine
s := newTestServer("1", &testTransporter{})
Expand Down
2 changes: 2 additions & 0 deletions coordinator/raft_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,8 @@ const (
)

func (s *RaftServer) ForceLogCompaction() error {
s.mutex.Lock()
defer s.mutex.Unlock()
err := s.raftServer.TakeSnapshot()
if err != nil {
log.Error("Cannot take snapshot: %s", err)
Expand Down

0 comments on commit 4b59ddd

Please sign in to comment.