// TruncateToSize caps the size of the WAL to the given number of bytes
TruncateToSize caps the size of the WAL to the given number of bytes
// TruncateToSize caps the size of the WAL to the given number of bytes
func (wal *WAL) TruncateToSize(limit int64) (int64, error) {
	remained := int64(0)
	err := wal.forEachSegmentInReverse(func(file os.FileInfo, first bool, last bool) (bool, error) {
		next := file.Size()
		if remained+next > limit {
			fullname := filepath.Join(wal.dir, file.Name())
			rmErr := os.Remove(fullname)
			if rmErr != nil {
				return false, rmErr
			}
			wal.log.Debugf("Removed WAL file %v", fullname)
		} else {
			remained += next
		}
		return true, nil
	})
	return remained, err
}
func ( wal * WAL ) TruncateToSize ( limit int64 ) ( int64 , error ) { remained := int64 ( 0 ) err := wal . forEachSegmentInReverse ( func ( file os . FileInfo , first bool , last bool ) ( bool , error ) { next := file . Size ( ) if remained + next > limit { fullname := filepath . Join ( wal . dir , file . Name ( ) ) rmErr := os . Remove ( fullname ) if rmErr != nil { return false , rmErr } wal . log . Debugf ( " " , fullname ) } else { remained += next } return true , nil } ) return remained , err }
TruncateToSize caps the size of the WAL to the given number of bytes
TruncateToSize caps the size of the WAL to the given number of bytes