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.
This commit is contained in:
@ -48,7 +48,8 @@ func newFilePipeline(dir string, fileSize int64) *filePipeline {
|
|||||||
return fp
|
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) {
|
func (fp *filePipeline) Open() (f *fileutil.LockedFile, err error) {
|
||||||
select {
|
select {
|
||||||
case f = <-fp.filec:
|
case f = <-fp.filec:
|
||||||
@ -63,7 +64,8 @@ func (fp *filePipeline) Close() error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (fp *filePipeline) alloc() (f *fileutil.LockedFile, err 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 {
|
if f, err = fileutil.LockFile(fpath, os.O_CREATE|os.O_WRONLY, 0600); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user