promql: Modify the order of return values. (#5940)
Signed-off-by: johncming <johncming@yahoo.com>
This commit is contained in:
parent
d1b3a6e013
commit
ac3cedb108
|
@ -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")
|
||||||
}
|
}
|
||||||
|
|
|
@ -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")
|
||||||
|
|
Loading…
Reference in New Issue