From 05cc3c3dbb15ecb9da7c16b69ae6807e90255924 Mon Sep 17 00:00:00 2001 From: Anthony Romano Date: Sat, 28 May 2016 20:28:26 -0700 Subject: [PATCH] wal: limit number of tmp file names This fixes a space leak if the etcd server is restarted in shorter and shorter intervals causing the tmp files to stack up. --- wal/file_pipeline.go | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/wal/file_pipeline.go b/wal/file_pipeline.go index e5674e63c..5b282b6cd 100644 --- a/wal/file_pipeline.go +++ b/wal/file_pipeline.go @@ -48,7 +48,8 @@ func newFilePipeline(dir string, fileSize int64) *filePipeline { return fp } -// Open returns a fresh file for writing +// Open returns a fresh file for writing. Rename the file before calling +// Open again or there will be file collisions. func (fp *filePipeline) Open() (f *fileutil.LockedFile, err error) { select { case f = <-fp.filec: @@ -63,7 +64,8 @@ func (fp *filePipeline) Close() error { } func (fp *filePipeline) alloc() (f *fileutil.LockedFile, err error) { - fpath := path.Join(fp.dir, fmt.Sprintf("%d.tmp", fp.count)) + // count % 2 so this file isn't the same as the one last published + fpath := path.Join(fp.dir, fmt.Sprintf("%d.tmp", fp.count%2)) if f, err = fileutil.LockFile(fpath, os.O_CREATE|os.O_WRONLY, 0600); err != nil { return nil, err }