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.release-3.0
parent
71a9d6fc8b
commit
05cc3c3dbb
|
@ -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
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue