Add an api to create a wal checkpoint (i.e. bookmark and index)

pull/342/head
John Shahid 2014-03-26 12:37:09 -04:00
parent 87f49644de
commit 92463617f9
2 changed files with 18 additions and 0 deletions

View File

@ -10,6 +10,10 @@ type closeEntry struct {
shouldBookmark bool
}
type bookmarkEntry struct {
confirmation chan *confirmation
}
type commitEntry struct {
confirmation chan *confirmation
serverId uint32

View File

@ -241,6 +241,13 @@ func (self *WAL) processEntries() {
self.processCommitEntry(x)
case *appendEntry:
self.processAppendEntry(x)
case *bookmarkEntry:
err := self.bookmark()
if err != nil {
x.confirmation <- &confirmation{0, err}
continue
}
x.confirmation <- &confirmation{0, self.index()}
case *closeEntry:
x.confirmation <- &confirmation{0, self.processClose(x.shouldBookmark)}
logger.Info("Closing wal")
@ -515,6 +522,13 @@ func (self *WAL) flush() error {
return nil
}
func (self *WAL) CreateCheckpoint() error {
confirmationChan := make(chan *confirmation)
self.entries <- &bookmarkEntry{confirmationChan}
confirmation := <-confirmationChan
return confirmation.err
}
func (self *WAL) bookmark() error {
if err := self.state.writeToFile(); err != nil {
logger.Error("Cannot write bookmark %s", err)