mirror of
https://github.com/VictoriaMetrics/VictoriaMetrics.git
synced 2024-12-14 16:12:15 +01:00
lib/storage: code cleanup after 5bfd4e6218
This commit is contained in:
parent
0db7c2b500
commit
9c5cd5a6c5
@ -1047,13 +1047,14 @@ func checkTimeRange(s *storage.Storage, tr storage.TimeRange) error {
|
||||
if !*denyQueriesOutsideRetention {
|
||||
return nil
|
||||
}
|
||||
retentionPeriod := s.RetentionMonths()
|
||||
minAllowedTimestamp := (int64(fasttime.UnixTimestamp()) - int64(retentionPeriod)*3600*24*30) * 1000
|
||||
retentionMsecs := s.RetentionMsecs()
|
||||
minAllowedTimestamp := int64(fasttime.UnixTimestamp()*1000) - retentionMsecs
|
||||
if tr.MinTimestamp > minAllowedTimestamp {
|
||||
return nil
|
||||
}
|
||||
return &httpserver.ErrorWithStatusCode{
|
||||
Err: fmt.Errorf("the given time range %s is outside the allowed retention of %d months according to -denyQueriesOutsideRetention", &tr, retentionPeriod),
|
||||
Err: fmt.Errorf("the given time range %s is outside the allowed retention %.3f days according to -denyQueriesOutsideRetention",
|
||||
&tr, float64(retentionMsecs)/(24*3600*1000)),
|
||||
StatusCode: http.StatusServiceUnavailable,
|
||||
}
|
||||
}
|
||||
|
@ -50,9 +50,9 @@ type Storage struct {
|
||||
slowPerDayIndexInserts uint64
|
||||
slowMetricNameLoads uint64
|
||||
|
||||
path string
|
||||
cachePath string
|
||||
retentionMonths int
|
||||
path string
|
||||
cachePath string
|
||||
retentionMsecs int64
|
||||
|
||||
// lock file for exclusive access to the storage on the given path.
|
||||
flockF *os.File
|
||||
@ -129,11 +129,10 @@ func OpenStorage(path string, retentionMsecs int64) (*Storage, error) {
|
||||
if retentionMsecs <= 0 {
|
||||
retentionMsecs = maxRetentionMsecs
|
||||
}
|
||||
retentionMonths := (retentionMsecs + (msecsPerMonth - 1)) / msecsPerMonth
|
||||
s := &Storage{
|
||||
path: path,
|
||||
cachePath: path + "/cache",
|
||||
retentionMonths: int(retentionMonths),
|
||||
path: path,
|
||||
cachePath: path + "/cache",
|
||||
retentionMsecs: retentionMsecs,
|
||||
|
||||
stop: make(chan struct{}),
|
||||
}
|
||||
@ -202,9 +201,9 @@ func OpenStorage(path string, retentionMsecs int64) (*Storage, error) {
|
||||
return s, nil
|
||||
}
|
||||
|
||||
// RetentionMonths returns retention months for s.
|
||||
func (s *Storage) RetentionMonths() int {
|
||||
return s.retentionMonths
|
||||
// RetentionMsecs returns retentionMsecs for s.
|
||||
func (s *Storage) RetentionMsecs() int64 {
|
||||
return s.retentionMsecs
|
||||
}
|
||||
|
||||
// debugFlush flushes recently added storage data, so it becomes visible to search.
|
||||
@ -488,8 +487,9 @@ func (s *Storage) startRetentionWatcher() {
|
||||
}
|
||||
|
||||
func (s *Storage) retentionWatcher() {
|
||||
retentionMonths := int((s.retentionMsecs + (msecsPerMonth - 1)) / msecsPerMonth)
|
||||
for {
|
||||
d := nextRetentionDuration(s.retentionMonths)
|
||||
d := nextRetentionDuration(retentionMonths)
|
||||
select {
|
||||
case <-s.stop:
|
||||
return
|
||||
|
Loading…
Reference in New Issue
Block a user