Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Flush to file periodically #237

Merged
merged 2 commits into from
Dec 13, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions controller/aofshrink.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,12 +169,12 @@ func (c *Controller) aofshrink() {
)

}()
}
if len(aofbuf) > maxchunk {
if _, err := f.Write(aofbuf); err != nil {
return err
if len(aofbuf) > maxchunk {
if _, err := f.Write(aofbuf); err != nil {
return err
}
aofbuf = aofbuf[:0]
}
aofbuf = aofbuf[:0]
}
}

Expand Down Expand Up @@ -264,22 +264,22 @@ func (c *Controller) aofshrink() {
// anything below this point is unrecoverable. just log and exit process
// back up the live aof, just in case of fatal error
if err := c.aof.Close(); err != nil {
log.Fatalf("shink live aof close fatal operation: %v", err)
log.Fatalf("shrink live aof close fatal operation: %v", err)
}
if err := os.Rename(path.Join(c.dir, "appendonly.aof"), path.Join(c.dir, "appendonly.bak")); err != nil {
log.Fatalf("shink backup fatal operation: %v", err)
log.Fatalf("shrink backup fatal operation: %v", err)
}
if err := os.Rename(path.Join(c.dir, "shrink"), path.Join(c.dir, "appendonly.aof")); err != nil {
log.Fatalf("shink rename fatal operation: %v", err)
log.Fatalf("shrink rename fatal operation: %v", err)
}
c.aof, err = os.OpenFile(path.Join(c.dir, "appendonly.aof"), os.O_CREATE|os.O_RDWR, 0600)
if err != nil {
log.Fatalf("shink openfile fatal operation: %v", err)
log.Fatalf("shrink openfile fatal operation: %v", err)
}
var n int64
n, err = c.aof.Seek(0, 2)
if err != nil {
log.Fatalf("shink seek end fatal operation: %v", err)
log.Fatalf("shrink seek end fatal operation: %v", err)
}
c.aofsz = int(n)

Expand Down