Skip to content

Commit

Permalink
fix #312. WAL should wait for server id to be set before recovering
Browse files Browse the repository at this point in the history
  • Loading branch information
jvshahid committed Mar 7, 2014
1 parent 6a3b16e commit 0c7542d
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 6 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -278,3 +278,4 @@

### Bugfixes

- [Issue #312](https://github.com/influxdb/influxdb/issues/312). WAL should wait for server id to be set before recovering
15 changes: 9 additions & 6 deletions src/wal/wal.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,17 +99,18 @@ func NewWAL(config *configuration.Configuration) (*WAL, error) {
break
}

if err := wal.recover(); err != nil {
return nil, err
}

go wal.processEntries()

return wal, err
}

func (self *WAL) SetServerId(id uint32) {
logger.Info("Setting server id to %d and recovering", id)
self.serverId = id

if err := self.recover(); err != nil {
panic(err)
}
}

// Marks a given request for a given server as committed
Expand Down Expand Up @@ -418,8 +419,10 @@ func (self *WAL) recover() error {
return err
}

sequenceNumber := (replayRequest.request.GetSequenceNumber() - uint64(self.serverId)) / HOST_ID_OFFSET
self.state.recover(replayRequest.shardId, sequenceNumber)
for _, point := range replayRequest.request.Series.Points {
sequenceNumber := (point.GetSequenceNumber() - uint64(self.serverId)) / HOST_ID_OFFSET
self.state.recover(replayRequest.shardId, sequenceNumber)
}

if firstOffset == -1 {
firstOffset = replayRequest.startOffset
Expand Down
19 changes: 19 additions & 0 deletions src/wal/wal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,25 @@ func (_ *WalSuite) TestAutoBookmark(c *C) {
c.Assert(s.LargestRequestNumber, Equals, uint32(2))
}

func (_ *WalSuite) TestSequenceNumberRecovery(c *C) {
wal := newWal(c)
serverId := uint32(10)
wal.SetServerId(serverId)
request := generateRequest(2)
id, err := wal.AssignSequenceNumbersAndLog(request, &MockShard{id: 1})
c.Assert(err, IsNil)
c.Assert(id, Equals, uint32(1))
c.Assert(request.Series.Points[1].GetSequenceNumber(), Equals, 2*HOST_ID_OFFSET+uint64(serverId))
wal.closeWithoutBookmarking()
wal, err = NewWAL(wal.config)
wal.SetServerId(serverId)
c.Assert(err, IsNil)
request = generateRequest(2)
id, err = wal.AssignSequenceNumbersAndLog(request, &MockShard{id: 1})
c.Assert(err, IsNil)
c.Assert(request.Series.Points[1].GetSequenceNumber(), Equals, 4*HOST_ID_OFFSET+uint64(serverId))
}

func (_ *WalSuite) TestAutoBookmarkAfterRecovery(c *C) {
wal := newWal(c)
wal.config.WalBookmarkAfterRequests = 2
Expand Down

0 comments on commit 0c7542d

Please sign in to comment.