Browse Source

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.
Anthony Romano 9 years ago
parent
commit
05cc3c3dbb
1 changed files with 4 additions and 2 deletions
  1. 4 2
      wal/file_pipeline.go

+ 4 - 2
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
 	}