promql: Modify the order of return values. (#5940)

Signed-off-by: johncming <johncming@yahoo.com>
This commit is contained in:
johncming 2019-08-24 09:39:15 +08:00 committed by Brian Brazil
parent d1b3a6e013
commit ac3cedb108
2 changed files with 7 additions and 7 deletions

View File

@ -76,27 +76,27 @@ func logUnfinishedQueries(filename string, filesize int, logger log.Logger) {
} }
} }
func getMMapedFile(filename string, filesize int, logger log.Logger) (error, []byte) { func getMMapedFile(filename string, filesize int, logger log.Logger) ([]byte, error) {
file, err := os.OpenFile(filename, os.O_CREATE|os.O_RDWR|os.O_TRUNC, 0644) file, err := os.OpenFile(filename, os.O_CREATE|os.O_RDWR|os.O_TRUNC, 0644)
if err != nil { if err != nil {
level.Error(logger).Log("msg", "Error opening query log file", "file", filename, "err", err) level.Error(logger).Log("msg", "Error opening query log file", "file", filename, "err", err)
return err, []byte{} return nil, err
} }
err = file.Truncate(int64(filesize)) err = file.Truncate(int64(filesize))
if err != nil { if err != nil {
level.Error(logger).Log("msg", "Error setting filesize.", "filesize", filesize, "err", err) level.Error(logger).Log("msg", "Error setting filesize.", "filesize", filesize, "err", err)
return err, []byte{} return nil, err
} }
fileAsBytes, err := mmap.Map(file, mmap.RDWR, 0) fileAsBytes, err := mmap.Map(file, mmap.RDWR, 0)
if err != nil { if err != nil {
level.Error(logger).Log("msg", "Failed to mmap", "file", filename, "Attempted size", filesize, "err", err) level.Error(logger).Log("msg", "Failed to mmap", "file", filename, "Attempted size", filesize, "err", err)
return err, []byte{} return nil, err
} }
return err, fileAsBytes return fileAsBytes, err
} }
func NewActiveQueryTracker(localStoragePath string, maxQueries int, logger log.Logger) *ActiveQueryTracker { func NewActiveQueryTracker(localStoragePath string, maxQueries int, logger log.Logger) *ActiveQueryTracker {
@ -108,7 +108,7 @@ func NewActiveQueryTracker(localStoragePath string, maxQueries int, logger log.L
filename, filesize := filepath.Join(localStoragePath, "queries.active"), 1+maxQueries*entrySize filename, filesize := filepath.Join(localStoragePath, "queries.active"), 1+maxQueries*entrySize
logUnfinishedQueries(filename, filesize, logger) logUnfinishedQueries(filename, filesize, logger)
err, fileAsBytes := getMMapedFile(filename, filesize, logger) fileAsBytes, err := getMMapedFile(filename, filesize, logger)
if err != nil { if err != nil {
panic("Unable to create mmap-ed active query log") panic("Unable to create mmap-ed active query log")
} }

View File

@ -113,7 +113,7 @@ func TestMMapFile(t *testing.T) {
filename := file.Name() filename := file.Name()
defer os.Remove(filename) defer os.Remove(filename)
err, fileAsBytes := getMMapedFile(filename, 2, nil) fileAsBytes, err := getMMapedFile(filename, 2, nil)
if err != nil { if err != nil {
t.Fatalf("Couldn't create test mmaped file") t.Fatalf("Couldn't create test mmaped file")