diff --git a/internal/api/handler.go b/internal/api/handler.go index e87067e31..9f9437875 100644 --- a/internal/api/handler.go +++ b/internal/api/handler.go @@ -138,6 +138,7 @@ const ( cacheInvalidateCheckInterval = 1 * time.Second cacheInvalidateCheckTimeout = 5 * time.Second cacheInvalidateMaxRows = 100_000 + cacheDefaultDropEvery = 90 * time.Second queryClientCache = 1 * time.Second queryClientCacheStale = 9 * time.Second // ~ v2 lag @@ -629,7 +630,7 @@ func NewHandler(staticDir fs.FS, jsSettings JSSettings, showInvisible bool, chV1 bufferPoolBytesFree: statshouse.GetMetricRef(format.BuiltinMetricAPIBufferBytesFree, statshouse.Tags{1: srvfunc.HostnameForStatshouse(), 2: "1"}), bufferPoolBytesTotal: statshouse.GetMetricRef(format.BuiltinMetricAPIBufferBytesTotal, statshouse.Tags{1: srvfunc.HostnameForStatshouse()}), } - h.cache = newTSCacheGroup(cfg.ApproxCacheMaxSize, data_model.LODTables, h.utcOffset, loadPoints) + h.cache = newTSCacheGroup(cfg.ApproxCacheMaxSize, data_model.LODTables, h.utcOffset, loadPoints, cacheDefaultDropEvery) h.pointsCache = newPointsCache(cfg.ApproxCacheMaxSize, h.utcOffset, loadPoint, time.Now) cl.AddChangeCB(func(c config.Config) { cfg := c.(*Config) @@ -786,7 +787,7 @@ SETTINGS IsLight: true, User: "cache-update", Metric: format.BuiltinMetricIDContributorsLog, - Table: _1sTableSH3, + Table: _1sTableSH2, Kind: "cache-update", }, Version2, ch.Query{ Body: queryBody, @@ -805,7 +806,7 @@ SETTINGS if _, ok := seen[r]; ok { continue } - for lodLevel := range data_model.LODTables[Version3] { + for lodLevel := range data_model.LODTables[Version2] { t := roundTime(r.At, lodLevel, h.utcOffset) w := todo[lodLevel] if len(w) == 0 || w[len(w)-1] != t { @@ -869,7 +870,7 @@ func (r *requestHandler) version() string { if r.versionDice != nil { return r.versionDice() } - return Version3 + return Version2 } func (h *Handler) getMetricNameWithNamespace(metricID int32) (string, error) { diff --git a/internal/api/sql.go b/internal/api/sql.go index 03d539411..5d038c394 100644 --- a/internal/api/sql.go +++ b/internal/api/sql.go @@ -60,7 +60,7 @@ func (pq *pointsQuery) cacheKey() string { case Version1: sb.WriteString(Version1) default: - sb.WriteString(Version3) + sb.WriteString(Version2) } sb.WriteString(";m=") sb.WriteString(fmt.Sprint(pq.metricID)) diff --git a/internal/api/tscache.go b/internal/api/tscache.go index 1c43391b3..c70cf1056 100644 --- a/internal/api/tscache.go +++ b/internal/api/tscache.go @@ -53,12 +53,17 @@ type tsCacheGroup struct { shutdown func() } -func newTSCacheGroup(approxMaxSize int, lodTables map[string]map[int64]string, utcOffset int64, loader tsLoadFunc) *tsCacheGroup { +func newTSCacheGroup(approxMaxSize int, lodTables map[string]map[int64]string, utcOffset int64, loader tsLoadFunc, dropEvery time.Duration) *tsCacheGroup { g := &tsCacheGroup{ pointCaches: map[string]map[int64]*tsCache{}, } for version, tables := range lodTables { + drop := dropEvery + if version == Version2 { + drop = 0 // NB! WHY?? + } + g.pointCaches[version] = map[int64]*tsCache{} for stepSec := range tables { now := time.Now() @@ -70,7 +75,7 @@ func newTSCacheGroup(approxMaxSize int, lodTables map[string]map[int64]string, u cache: map[string]*tsEntry{}, invalidatedAtNano: map[int64]int64{}, lastDrop: now, - dropEvery: data_model.CacheDropInterval(version), + dropEvery: drop, bytesAlloc: statshouse.GetMetricRef(format.BuiltinMetricAPICacheBytesAlloc, statshouse.Tags{ 1: srvfunc.HostnameForStatshouse(), 2: version, 3: strconv.FormatInt(stepSec, 10), }), diff --git a/internal/data_model/timescale.go b/internal/data_model/timescale.go index 64d812f59..b69c2817a 100644 --- a/internal/data_model/timescale.go +++ b/internal/data_model/timescale.go @@ -259,15 +259,6 @@ var ( var errQueryOutOfRange = fmt.Errorf("exceeded maximum resolution of %d points per timeseries", MaxSlice) -func CacheDropInterval(version string) time.Duration { - switch version { - case Version1: - return 90 * time.Second - default: - return 0 - } -} - func GetTimescale(args GetTimescaleArgs) (Timescale, error) { if args.End <= args.Start || args.Step < 0 { return Timescale{}, nil