Add an api to create a wal checkpoint (i.e. bookmark and index)
parent
87f49644de
commit
92463617f9
|
@ -10,6 +10,10 @@ type closeEntry struct {
|
|||
shouldBookmark bool
|
||||
}
|
||||
|
||||
type bookmarkEntry struct {
|
||||
confirmation chan *confirmation
|
||||
}
|
||||
|
||||
type commitEntry struct {
|
||||
confirmation chan *confirmation
|
||||
serverId uint32
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in New Issue