This commit is contained in:
2025-06-22 11:56:29 +03:00
parent 5e49c66e15
commit 37893fc805
11 changed files with 59 additions and 110 deletions

View File

@@ -724,12 +724,12 @@ func (s *Database) ListInstantMeasures(conn net.Conn, req proto.ListInstantMeasu
return nil
}
var since, until uint32
if req.FirstHourOfDay > 0 {
since, until = correctToFHD(req.Since, req.Until, req.FirstHourOfDay)
} else {
var (
since = req.Since
until = req.Until
)
if req.FirstHourOfDay > 0 {
since, until = correctToFHD(req.Since, req.Until, req.FirstHourOfDay)
}
resultCh := make(chan instantMeasuresResult, 1)
@@ -800,13 +800,26 @@ type cumulativeMeasuresResult struct {
}
func (s *Database) ListCumulativeMeasures(conn net.Conn, req proto.ListCumulativeMeasuresReq) error {
if req.Since > req.Until {
reply(conn, proto.ErrInvalidRange)
return nil
}
var (
since = req.Since
until = req.Until
)
if req.FirstHourOfDay > 0 {
since, until = correctToFHD(since, until, req.FirstHourOfDay)
}
resultCh := make(chan cumulativeMeasuresResult, 1)
responseWriter := atree.NewCumulativeMeasureWriter(conn)
s.appendJobToWorkerQueue(tryListCumulativeMeasuresReq{
MetricID: req.MetricID,
Since: req.Since,
Until: req.Until,
Since: since,
Until: until,
ResponseWriter: responseWriter,
ResultCh: resultCh,
})
@@ -820,8 +833,8 @@ func (s *Database) ListCumulativeMeasures(conn net.Conn, req proto.ListCumulativ
case UntilFound:
err := s.atree.ContinueIterateCumulativeByTreeCursor(atree.ContinueIterateCumulativeByTreeCursorReq{
FracDigits: result.FracDigits,
Since: req.Since,
Until: req.Until,
Since: since,
Until: until,
LastPageNo: result.PageNo,
EndTimestamp: result.EndTimestamp,
EndValue: result.EndValue,
@@ -837,8 +850,8 @@ func (s *Database) ListCumulativeMeasures(conn net.Conn, req proto.ListCumulativ
case UntilNotFound:
err := s.atree.FindAndIterateCumulativeByTreeCursor(atree.FindAndIterateCumulativeByTreeCursorReq{
FracDigits: result.FracDigits,
Since: req.Since,
Until: req.Until,
Since: since,
Until: until,
RootPageNo: result.PageNo,
ResponseWriter: responseWriter,
})
@@ -868,6 +881,11 @@ type instantPeriodsResult struct {
}
func (s *Database) ListInstantPeriods(conn net.Conn, req proto.ListInstantPeriodsReq) error {
if req.Since > req.Until {
reply(conn, proto.ErrInvalidRange)
return nil
}
var (
since = req.Since
until = req.Until
@@ -876,16 +894,11 @@ func (s *Database) ListInstantPeriods(conn net.Conn, req proto.ListInstantPeriod
since, until = correctToFHD(since, until, req.FirstHourOfDay)
}
if req.LastDayOfMonth > 0 {
// fix
}
resultCh := make(chan instantPeriodsResult, 1)
aggregator, err := atree.NewInstantAggregator(atree.InstantAggregatorOptions{
GroupBy: req.GroupBy,
FirstHourOfDay: req.FirstHourOfDay,
LastDayOfMonth: req.LastDayOfMonth,
})
if err != nil {
reply(conn, proto.ErrUnexpected)
@@ -896,8 +909,8 @@ func (s *Database) ListInstantPeriods(conn net.Conn, req proto.ListInstantPeriod
s.appendJobToWorkerQueue(tryListInstantPeriodsReq{
MetricID: req.MetricID,
Since: req.Since,
Until: req.Until,
Since: since,
Until: until,
Aggregator: aggregator,
ResponseWriter: responseWriter,
ResultCh: resultCh,
@@ -915,8 +928,8 @@ func (s *Database) ListInstantPeriods(conn net.Conn, req proto.ListInstantPeriod
Aggregator: aggregator,
ResponseWriter: responseWriter,
LastPageNo: result.PageNo,
Since: req.Since,
Until: req.Until,
Since: since,
Until: until,
})
s.metricRUnlock(req.MetricID)
@@ -931,11 +944,10 @@ func (s *Database) ListInstantPeriods(conn net.Conn, req proto.ListInstantPeriod
FracDigits: result.FracDigits,
ResponseWriter: responseWriter,
RootPageNo: result.PageNo,
Since: req.Since,
Until: req.Until,
Since: since,
Until: until,
GroupBy: req.GroupBy,
FirstHourOfDay: req.FirstHourOfDay,
LastDayOfMonth: req.LastDayOfMonth,
})
s.metricRUnlock(req.MetricID)
@@ -964,12 +976,24 @@ type cumulativePeriodsResult struct {
}
func (s *Database) ListCumulativePeriods(conn net.Conn, req proto.ListCumulativePeriodsReq) error {
if req.Since > req.Until {
reply(conn, proto.ErrInvalidRange)
return nil
}
var (
since = req.Since
until = req.Until
)
if req.FirstHourOfDay > 0 {
since, until = correctToFHD(since, until, req.FirstHourOfDay)
}
resultCh := make(chan cumulativePeriodsResult, 1)
aggregator, err := atree.NewCumulativeAggregator(atree.CumulativeAggregatorOptions{
GroupBy: req.GroupBy,
FirstHourOfDay: req.FirstHourOfDay,
LastDayOfMonth: req.LastDayOfMonth,
})
if err != nil {
reply(conn, proto.ErrUnexpected)
@@ -980,8 +1004,8 @@ func (s *Database) ListCumulativePeriods(conn net.Conn, req proto.ListCumulative
s.appendJobToWorkerQueue(tryListCumulativePeriodsReq{
MetricID: req.MetricID,
Since: req.Since,
Until: req.Until,
Since: since,
Until: until,
Aggregator: aggregator,
ResponseWriter: responseWriter,
ResultCh: resultCh,
@@ -999,8 +1023,8 @@ func (s *Database) ListCumulativePeriods(conn net.Conn, req proto.ListCumulative
Aggregator: aggregator,
ResponseWriter: responseWriter,
LastPageNo: result.PageNo,
Since: req.Since,
Until: req.Until,
Since: since,
Until: until,
})
s.metricRUnlock(req.MetricID)
@@ -1015,11 +1039,10 @@ func (s *Database) ListCumulativePeriods(conn net.Conn, req proto.ListCumulative
FracDigits: result.FracDigits,
ResponseWriter: responseWriter,
RootPageNo: result.PageNo,
Since: req.Since,
Until: req.Until,
Since: since,
Until: until,
GroupBy: req.GroupBy,
FirstHourOfDay: req.FirstHourOfDay,
LastDayOfMonth: req.LastDayOfMonth,
})
s.metricRUnlock(req.MetricID)