From ad1a45cf49972dfcc3c9e26f5b1afad73e6441b2 Mon Sep 17 00:00:00 2001 From: Taha Afzal Date: Mon, 12 Jun 2023 15:49:25 -0400 Subject: [PATCH] ArchivedTheos are truncated on a server start --- .devcontainer/devcontainer.json | 25 + .../net7.0/Spark.Admin.WebApp.deps.json | 486 ++++++++++++++++++ .../analytics/AnalyticsServiceServer.cpp | 97 ++-- .../sparkd/analytics/AnalyticsServiceServer.h | 1 + 4 files changed, 575 insertions(+), 34 deletions(-) create mode 100644 .devcontainer/devcontainer.json create mode 100644 src/Spark.Admin.WebApp/src/bin/Release/net7.0/Spark.Admin.WebApp.deps.json diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json new file mode 100644 index 000000000..ffd1e7f4d --- /dev/null +++ b/.devcontainer/devcontainer.json @@ -0,0 +1,25 @@ +{ + "image": "johncolvin/bluetradingsystems:sparkd-dev", + "initializeCommand": "${localWorkspaceFolder}/docker/sparkd/dev/devcontainer_initialize.sh", + "postCreateCommand": "/home/bts/spark/docker/sparkd/dev/devcontainer_post_create.sh", + "workspaceMount": "source=${localWorkspaceFolder},target=/home/bts/spark,type=bind", + "workspaceFolder": "/home/bts/spark", + "updateRemoteUserUID": true, + "shutdownAction": "none", + // Note: If running multiple containers on the same host, each must use a + // unique set of ports. Usually we just add 1000 to each port as needed. For + // example, if 8000-8003 is taken, go with 9000-9003, then 10000-10003, etc. + "runArgs": [ + "-p", + "8000:8000", + "-p", + "8001:8001", + "-p", + "8002:8002", + "-p", + "8003:8003" + ], + "mounts": [ + "source=${localEnv:HOME}/.sparkd-dev/mounts/sparkd-dev,target=/home/bts,type=bind" + ] +} diff --git a/src/Spark.Admin.WebApp/src/bin/Release/net7.0/Spark.Admin.WebApp.deps.json b/src/Spark.Admin.WebApp/src/bin/Release/net7.0/Spark.Admin.WebApp.deps.json new file mode 100644 index 000000000..7054d31ad --- /dev/null +++ b/src/Spark.Admin.WebApp/src/bin/Release/net7.0/Spark.Admin.WebApp.deps.json @@ -0,0 +1,486 @@ +{ + "runtimeTarget": { + "name": ".NETCoreApp,Version=v7.0", + "signature": "" + }, + "compilationOptions": {}, + "targets": { + ".NETCoreApp,Version=v7.0": { + "Spark.Admin.WebApp/1.0.0": { + "dependencies": { + "Elmish": "4.0.1", + "Elmish.Navigation": "1.0.0", + "Fable.Core": "4.0.0-theta-007", + "Fable.Elmish": "4.0.1", + "Fable.Elmish.Browser": "4.0.1", + "Fable.Elmish.Debugger": "4.0.0", + "Fable.Elmish.HMR": "7.0.0", + "Fable.Elmish.React": "4.0.0", + "Fable.Elmish.UrlParser": "1.0.1", + "Fable.Promise": "3.2.0", + "Fable.React": "9.2.0", + "System.Runtime": "4.3.1" + }, + "runtime": { + "Spark.Admin.WebApp.dll": {} + } + }, + "Elmish/4.0.1": { + "runtime": { + "lib/netstandard2.0/Elmish.dll": { + "assemblyVersion": "4.0.1.0", + "fileVersion": "4.0.1.0" + } + } + }, + "Elmish.Navigation/1.0.0": { + "dependencies": { + "FSharp.Core": "6.0.7", + "Fable.Elmish": "4.0.1" + }, + "runtime": { + "lib/net5.0/Elmish.Navigation.dll": { + "assemblyVersion": "1.0.0.0", + "fileVersion": "1.0.0.0" + } + } + }, + "Fable.Browser.Blob/1.2.0": { + "dependencies": { + "FSharp.Core": "6.0.7", + "Fable.Core": "4.0.0-theta-007" + }, + "runtime": { + "lib/netstandard2.0/Browser.Blob.dll": { + "assemblyVersion": "1.2.0.0", + "fileVersion": "1.2.0.0" + } + } + }, + "Fable.Browser.Dom/2.10.1": { + "dependencies": { + "FSharp.Core": "6.0.7", + "Fable.Browser.Blob": "1.2.0", + "Fable.Browser.Event": "1.5.0", + "Fable.Browser.WebStorage": "1.1.0", + "Fable.Core": "4.0.0-theta-007" + }, + "runtime": { + "lib/netstandard2.0/Browser.Dom.dll": { + "assemblyVersion": "2.10.1.0", + "fileVersion": "2.10.1.0" + } + } + }, + "Fable.Browser.Event/1.5.0": { + "dependencies": { + "FSharp.Core": "6.0.7", + "Fable.Browser.Gamepad": "1.1.0", + "Fable.Core": "4.0.0-theta-007" + }, + "runtime": { + "lib/netstandard2.0/Browser.Event.dll": { + "assemblyVersion": "1.5.0.0", + "fileVersion": "1.5.0.0" + } + } + }, + "Fable.Browser.Gamepad/1.1.0": { + "dependencies": { + "FSharp.Core": "6.0.7", + "Fable.Core": "4.0.0-theta-007" + }, + "runtime": { + "lib/netstandard2.0/Browser.Gamepad.dll": { + "assemblyVersion": "1.1.0.0", + "fileVersion": "1.1.0.0" + } + } + }, + "Fable.Browser.WebStorage/1.1.0": { + "dependencies": { + "FSharp.Core": "6.0.7", + "Fable.Browser.Event": "1.5.0", + "Fable.Core": "4.0.0-theta-007" + }, + "runtime": { + "lib/netstandard2.0/Browser.WebStorage.dll": { + "assemblyVersion": "1.1.0.0", + "fileVersion": "1.1.0.0" + } + } + }, + "Fable.Core/4.0.0-theta-007": { + "runtime": { + "lib/netstandard2.0/Fable.Core.dll": { + "assemblyVersion": "4.0.0.0", + "fileVersion": "4.0.0.0" + } + } + }, + "Fable.Elmish/4.0.1": { + "dependencies": { + "FSharp.Core": "6.0.7", + "Fable.Core": "4.0.0-theta-007" + }, + "runtime": { + "lib/netstandard2.0/Fable.Elmish.dll": { + "assemblyVersion": "4.0.1.0", + "fileVersion": "4.0.1.0" + } + } + }, + "Fable.Elmish.Browser/4.0.1": { + "dependencies": { + "FSharp.Core": "6.0.7", + "Fable.Browser.Dom": "2.10.1", + "Fable.Elmish": "4.0.1", + "Fable.Elmish.UrlParser": "1.0.1" + }, + "runtime": { + "lib/netstandard2.0/Fable.Elmish.Browser.dll": { + "assemblyVersion": "4.0.1.0", + "fileVersion": "4.0.1.0" + } + } + }, + "Fable.Elmish.Debugger/4.0.0": { + "dependencies": { + "FSharp.Core": "6.0.7", + "Fable.Elmish": "4.0.1", + "Thoth.Json": "6.0.0" + }, + "runtime": { + "lib/netstandard2.0/Fable.Elmish.Debugger.dll": { + "assemblyVersion": "4.0.0.0", + "fileVersion": "4.0.0.0" + } + } + }, + "Fable.Elmish.HMR/7.0.0": { + "dependencies": { + "FSharp.Core": "6.0.7", + "Fable.Core": "4.0.0-theta-007", + "Fable.Elmish.React": "4.0.0" + }, + "runtime": { + "lib/netstandard2.0/Fable.Elmish.HMR.dll": { + "assemblyVersion": "7.0.0.0", + "fileVersion": "7.0.0.0" + } + } + }, + "Fable.Elmish.React/4.0.0": { + "dependencies": { + "FSharp.Core": "6.0.7", + "Fable.Elmish": "4.0.1", + "Fable.ReactDom.Types": "18.2.0" + }, + "runtime": { + "lib/netstandard2.0/Fable.Elmish.React.dll": { + "assemblyVersion": "4.0.0.0", + "fileVersion": "4.0.0.0" + } + } + }, + "Fable.Elmish.UrlParser/1.0.1": { + "dependencies": { + "FSharp.Core": "6.0.7" + }, + "runtime": { + "lib/netstandard2.0/Fable.Elmish.UrlParser.dll": { + "assemblyVersion": "1.0.1.0", + "fileVersion": "1.0.1.0" + } + } + }, + "Fable.Promise/3.2.0": { + "dependencies": { + "FSharp.Core": "6.0.7", + "Fable.Core": "4.0.0-theta-007" + }, + "runtime": { + "lib/netstandard2.0/Fable.Promise.dll": { + "assemblyVersion": "3.2.0.0", + "fileVersion": "3.2.0.0" + } + } + }, + "Fable.React/9.2.0": { + "dependencies": { + "FSharp.Core": "6.0.7", + "Fable.React.Types": "18.3.0", + "Fable.ReactDom.Types": "18.2.0" + }, + "runtime": { + "lib/netstandard2.0/Fable.React.dll": { + "assemblyVersion": "9.2.0.0", + "fileVersion": "9.2.0.0" + } + } + }, + "Fable.React.Types/18.3.0": { + "dependencies": { + "FSharp.Core": "6.0.7", + "Fable.Browser.Dom": "2.10.1", + "Fable.Core": "4.0.0-theta-007" + }, + "runtime": { + "lib/netstandard2.0/Fable.React.Types.dll": { + "assemblyVersion": "18.3.0.0", + "fileVersion": "18.3.0.0" + } + } + }, + "Fable.ReactDom.Types/18.2.0": { + "dependencies": { + "FSharp.Core": "6.0.7", + "Fable.React.Types": "18.3.0" + }, + "runtime": { + "lib/netstandard2.0/Fable.ReactDom.Types.dll": { + "assemblyVersion": "18.2.0.0", + "fileVersion": "18.2.0.0" + } + } + }, + "FSharp.Core/6.0.7": { + "runtime": { + "lib/netstandard2.1/FSharp.Core.dll": { + "assemblyVersion": "6.0.0.0", + "fileVersion": "6.0.722.51308" + } + }, + "resources": { + "lib/netstandard2.1/cs/FSharp.Core.resources.dll": { + "locale": "cs" + }, + "lib/netstandard2.1/de/FSharp.Core.resources.dll": { + "locale": "de" + }, + "lib/netstandard2.1/es/FSharp.Core.resources.dll": { + "locale": "es" + }, + "lib/netstandard2.1/fr/FSharp.Core.resources.dll": { + "locale": "fr" + }, + "lib/netstandard2.1/it/FSharp.Core.resources.dll": { + "locale": "it" + }, + "lib/netstandard2.1/ja/FSharp.Core.resources.dll": { + "locale": "ja" + }, + "lib/netstandard2.1/ko/FSharp.Core.resources.dll": { + "locale": "ko" + }, + "lib/netstandard2.1/pl/FSharp.Core.resources.dll": { + "locale": "pl" + }, + "lib/netstandard2.1/pt-BR/FSharp.Core.resources.dll": { + "locale": "pt-BR" + }, + "lib/netstandard2.1/ru/FSharp.Core.resources.dll": { + "locale": "ru" + }, + "lib/netstandard2.1/tr/FSharp.Core.resources.dll": { + "locale": "tr" + }, + "lib/netstandard2.1/zh-Hans/FSharp.Core.resources.dll": { + "locale": "zh-Hans" + }, + "lib/netstandard2.1/zh-Hant/FSharp.Core.resources.dll": { + "locale": "zh-Hant" + } + } + }, + "Microsoft.NETCore.Platforms/1.1.1": {}, + "Microsoft.NETCore.Targets/1.1.3": {}, + "System.Runtime/4.3.1": { + "dependencies": { + "Microsoft.NETCore.Platforms": "1.1.1", + "Microsoft.NETCore.Targets": "1.1.3" + } + }, + "Thoth.Json/6.0.0": { + "dependencies": { + "FSharp.Core": "6.0.7", + "Fable.Core": "4.0.0-theta-007" + }, + "runtime": { + "lib/netstandard2.0/Thoth.Json.dll": { + "assemblyVersion": "6.0.0.0", + "fileVersion": "6.0.0.0" + } + } + } + } + }, + "libraries": { + "Spark.Admin.WebApp/1.0.0": { + "type": "project", + "serviceable": false, + "sha512": "" + }, + "Elmish/4.0.1": { + "type": "package", + "serviceable": true, + "sha512": "sha512-6AI++9Ula33yMUG9F83iVrZClurQn5cgriwK7aX9FvlhJFXgRB6IYybD+wx26NNhdPOKQIvfBYZYWwRWWWqJmA==", + "path": "elmish/4.0.1", + "hashPath": "elmish.4.0.1.nupkg.sha512" + }, + "Elmish.Navigation/1.0.0": { + "type": "package", + "serviceable": true, + "sha512": "sha512-0+CYaZzb988Oi02KeXPTUf0HTi1NXgFXTZ5/OROU22GKAohZe519QK3Be+jkbT0hvQq5EEiJJjPfp3FAgpqDaA==", + "path": "elmish.navigation/1.0.0", + "hashPath": "elmish.navigation.1.0.0.nupkg.sha512" + }, + "Fable.Browser.Blob/1.2.0": { + "type": "package", + "serviceable": true, + "sha512": "sha512-bM4zbtIeycTFFCH7o4WuN28W70dTxNTMZiMvR70XUTYrBnbz7GpS5XxzUy5caDB4l7s2l7wiuVDhh52t7NXxDg==", + "path": "fable.browser.blob/1.2.0", + "hashPath": "fable.browser.blob.1.2.0.nupkg.sha512" + }, + "Fable.Browser.Dom/2.10.1": { + "type": "package", + "serviceable": true, + "sha512": "sha512-G1Ul9D3suwBPUxEw0hwclZzDxDk/hLkwAZytgAoxHmv4uGth9Zpi9Fz4gm6C8v6W87qvhcM8lrCpg1awPeATyg==", + "path": "fable.browser.dom/2.10.1", + "hashPath": "fable.browser.dom.2.10.1.nupkg.sha512" + }, + "Fable.Browser.Event/1.5.0": { + "type": "package", + "serviceable": true, + "sha512": "sha512-Bx2AOOASIG1Eq1Pe8869H8baMePte6STmKGccGuOYMT2p6nWVS8G6ZBZb5encQ0tAL2/0vhA4KJOl4bYwUaQqg==", + "path": "fable.browser.event/1.5.0", + "hashPath": "fable.browser.event.1.5.0.nupkg.sha512" + }, + "Fable.Browser.Gamepad/1.1.0": { + "type": "package", + "serviceable": true, + "sha512": "sha512-8m/Ae/mrH2Hb2ue435rTPEeVb2FhfWsRJJLpCxMvk+5EUOO2+IIjIkLq4thUfRL98uQVt9V5cQd14h2aBf2XJA==", + "path": "fable.browser.gamepad/1.1.0", + "hashPath": "fable.browser.gamepad.1.1.0.nupkg.sha512" + }, + "Fable.Browser.WebStorage/1.1.0": { + "type": "package", + "serviceable": true, + "sha512": "sha512-tGktTk6QHIOeX7JtG5ISem1p9Rc1iYkgcbpIEzHS2YuvpOa9YomUKABU0Lraz4GMjAGxhhNvAXLRry2w89HdVQ==", + "path": "fable.browser.webstorage/1.1.0", + "hashPath": "fable.browser.webstorage.1.1.0.nupkg.sha512" + }, + "Fable.Core/4.0.0-theta-007": { + "type": "package", + "serviceable": true, + "sha512": "sha512-9nDQRQfhz6/NjoXLBMqixCjRYvx8jgHAuGjJow4W0vHoFWNauPhTex+psQsw9FRRuQF2AhIwuhHoh9Tb8JoCfw==", + "path": "fable.core/4.0.0-theta-007", + "hashPath": "fable.core.4.0.0-theta-007.nupkg.sha512" + }, + "Fable.Elmish/4.0.1": { + "type": "package", + "serviceable": true, + "sha512": "sha512-BtsXTur95XkWmZaXwIoqfUk8puWpiwgJK8YMTg62C/FYxMl8Z6WM4yuGAjQ6rVpKWw5Ha47VfmOL6k/znK3msw==", + "path": "fable.elmish/4.0.1", + "hashPath": "fable.elmish.4.0.1.nupkg.sha512" + }, + "Fable.Elmish.Browser/4.0.1": { + "type": "package", + "serviceable": true, + "sha512": "sha512-XqTMh3TzkyuWmKXOoNAHRDjxcnCAiDkUMIZZX6tkxoHPhtruxnOG5zniOm7K/RZD+NGbreKi82pPswcvmjw6/w==", + "path": "fable.elmish.browser/4.0.1", + "hashPath": "fable.elmish.browser.4.0.1.nupkg.sha512" + }, + "Fable.Elmish.Debugger/4.0.0": { + "type": "package", + "serviceable": true, + "sha512": "sha512-a1gABGh8L6kkzGDeVJP6VJtcimfSi/l3Xaa1lzuMlnzb3oXgtfmzXfx1DV/dtDVujIujueCOsA+JmiBh/2HB7A==", + "path": "fable.elmish.debugger/4.0.0", + "hashPath": "fable.elmish.debugger.4.0.0.nupkg.sha512" + }, + "Fable.Elmish.HMR/7.0.0": { + "type": "package", + "serviceable": true, + "sha512": "sha512-4A3u0H3wdmF00UBFJGJK6jlRxzEgkYOegDj2bgVzYTD1L17+0mCy9+QqAYJMuOGtA2klrKAHcU43tYdm0o2Fnw==", + "path": "fable.elmish.hmr/7.0.0", + "hashPath": "fable.elmish.hmr.7.0.0.nupkg.sha512" + }, + "Fable.Elmish.React/4.0.0": { + "type": "package", + "serviceable": true, + "sha512": "sha512-cMuWet7DhxgN2G1caYLwjLvoMkH1u75U36cUyL07yxNt/dmGp8GD/+RTtL9wpkfeThfeJHHouCkR708mJcMRpA==", + "path": "fable.elmish.react/4.0.0", + "hashPath": "fable.elmish.react.4.0.0.nupkg.sha512" + }, + "Fable.Elmish.UrlParser/1.0.1": { + "type": "package", + "serviceable": true, + "sha512": "sha512-Jpw1TPR3YsEeLHF0HMoeHKMYzTgjH+gslq8kNa3/d68GIK09eDpASNzA1gu9YLJkRYy5iUXvvvYtHUOKh+mzEw==", + "path": "fable.elmish.urlparser/1.0.1", + "hashPath": "fable.elmish.urlparser.1.0.1.nupkg.sha512" + }, + "Fable.Promise/3.2.0": { + "type": "package", + "serviceable": true, + "sha512": "sha512-4A+Iiembrny2h3AE2BIbchfuLmWHNhpkOTvbTtFXHtGzHVMqEVFRXrAfdy83wX2wK5Og3fqRo1y8t/Bqkd7j6g==", + "path": "fable.promise/3.2.0", + "hashPath": "fable.promise.3.2.0.nupkg.sha512" + }, + "Fable.React/9.2.0": { + "type": "package", + "serviceable": true, + "sha512": "sha512-ZMRkZpBy+6ytUHPk0WjRh15kigncmSGLOAbtf12VaSy48mtgqIW4lC/23X/FEvz8tUGwHvBUen2GzUU1G/L+RQ==", + "path": "fable.react/9.2.0", + "hashPath": "fable.react.9.2.0.nupkg.sha512" + }, + "Fable.React.Types/18.3.0": { + "type": "package", + "serviceable": true, + "sha512": "sha512-/b8WZ3Bdfhqy9r60ZK9JGZaGNjIMb0ogsrvWIg3k7KfCEvJs5X6+7hCybVkyjVoxwzn9wLyYGRbh5wmuHQT/Vg==", + "path": "fable.react.types/18.3.0", + "hashPath": "fable.react.types.18.3.0.nupkg.sha512" + }, + "Fable.ReactDom.Types/18.2.0": { + "type": "package", + "serviceable": true, + "sha512": "sha512-2WoBjsLiSgrvR68OJXko0iVaqeMbkPM5Bx813A1WlxOSCJ50M9fwnlwG/MUEZtiOIhQmku/YTJY5a8E8r1+j2Q==", + "path": "fable.reactdom.types/18.2.0", + "hashPath": "fable.reactdom.types.18.2.0.nupkg.sha512" + }, + "FSharp.Core/6.0.7": { + "type": "package", + "serviceable": true, + "sha512": "sha512-e6wGrq5smV3Yk2fBE/Y0nBG5oFyF59k5Je0a0QDydUpg6liyaafGjD3xvutciKepCP2knspZ/sWViC/F1OyyQQ==", + "path": "fsharp.core/6.0.7", + "hashPath": "fsharp.core.6.0.7.nupkg.sha512" + }, + "Microsoft.NETCore.Platforms/1.1.1": { + "type": "package", + "serviceable": true, + "sha512": "sha512-TMBuzAHpTenGbGgk0SMTwyEkyijY/Eae4ZGsFNYJvAr/LDn1ku3Etp3FPxChmDp5HHF3kzJuoaa08N0xjqAJfQ==", + "path": "microsoft.netcore.platforms/1.1.1", + "hashPath": "microsoft.netcore.platforms.1.1.1.nupkg.sha512" + }, + "Microsoft.NETCore.Targets/1.1.3": { + "type": "package", + "serviceable": true, + "sha512": "sha512-3Wrmi0kJDzClwAC+iBdUBpEKmEle8FQNsCs77fkiOIw/9oYA07bL1EZNX0kQ2OMN3xpwvl0vAtOCYY3ndDNlhQ==", + "path": "microsoft.netcore.targets/1.1.3", + "hashPath": "microsoft.netcore.targets.1.1.3.nupkg.sha512" + }, + "System.Runtime/4.3.1": { + "type": "package", + "serviceable": true, + "sha512": "sha512-abhfv1dTK6NXOmu4bgHIONxHyEqFjW8HwXPmpY9gmll+ix9UNo4XDcmzJn6oLooftxNssVHdJC1pGT9jkSynQg==", + "path": "system.runtime/4.3.1", + "hashPath": "system.runtime.4.3.1.nupkg.sha512" + }, + "Thoth.Json/6.0.0": { + "type": "package", + "serviceable": true, + "sha512": "sha512-fJ9nhZezOyRIsaluEIj5ytCSCbnsvA7ZCa1kY7KkWPqyHtc+SDvjthz5edoFxOAHH44iSmxl6zakapjMSRJbbw==", + "path": "thoth.json/6.0.0", + "hashPath": "thoth.json.6.0.0.nupkg.sha512" + } + } +} \ No newline at end of file diff --git a/src/server/sparkd/analytics/AnalyticsServiceServer.cpp b/src/server/sparkd/analytics/AnalyticsServiceServer.cpp index e92157b3d..65d5b857d 100644 --- a/src/server/sparkd/analytics/AnalyticsServiceServer.cpp +++ b/src/server/sparkd/analytics/AnalyticsServiceServer.cpp @@ -8,6 +8,7 @@ #include "lib/persistence/SqliteStore.h" #include "lib/utils/PBUtils.h" #include "lib/utils/Puid.h" +#include "lib/utils/TimeStamp.h" #include "lib/utils/bts_assert.h" #include "server/sparkd/algo/AlgoDefinitionServiceServer.h" #include @@ -90,6 +91,11 @@ struct AnalyticsServiceServer::PImpl { const std::string vs_usage_ns = "volsurface_usage"; const std::string reports_ns = "reports"; const std::string archived_theos_ns = "archived_theos"; + // this is the total number of vs data that will be stored in the db, + // beyond that, old values will be recycled + const size_t vs_history_sz = 5000; + // anologous to above for archived theos + const size_t archived_theos_history_sz = 1000; std::unique_ptr vs_store; std::unique_ptr exp_params_store; std::unique_ptr vs_usage_store; @@ -133,6 +139,7 @@ AnalyticsServiceServer::AnalyticsServiceServer( // publishing all vol surfaces LOG(Gen, Info, "Starting AnalyticsServiceServer"); _clean_up_vss(); + _clean_up_archived_theos(); auto vs_table = me->vs_store->retrieve_all(); for (auto const &ns_vals : vs_table) { const std::string &vs_name = ns_vals.first; @@ -429,47 +436,69 @@ void AnalyticsServiceServer::get_archived_theos( AnalyticsServiceServer::~AnalyticsServiceServer() {} +// for a map where the key is the epoch timestamp, this returns the keys to +// delete such that final size is final_sz +std::set get_keys_to_delete( + const std::map &time_keyed_map, size_t final_sz) { + if (time_keyed_map.size() <= final_sz) { + return {}; + } + std::vector keys_uint; + for (const auto &kv : time_keyed_map) { + try { + keys_uint.push_back(std::stoull(kv.first)); + } catch (int) { + LOG(Gen, Error, + "AnalyticsServiceServer::get_keys_to_delete could not convert " + "key: {} to uint", + kv.first); + } + } + // this is sorted lowest to highest + std::sort(keys_uint.begin(), keys_uint.end()); + size_t n_del_rows = keys_uint.size() - final_sz; + std::vector keys_uint_to_del = + std::vector(keys_uint.begin(), keys_uint.begin() + n_del_rows); + std::set keys_to_del; + for (auto k : keys_uint_to_del) { + keys_to_del.insert(std::to_string(k)); + } + return keys_to_del; +} + void AnalyticsServiceServer::_clean_up_vss() { - const size_t final_sz = 500; + const size_t final_sz = me->vs_history_sz; auto all_rows = me->vs_store->retrieve_all(); for (const auto &ns_k : all_rows) { + auto t0 = utils::TimeStamp::now().to_uint64(); const auto &vs = ns_k.first; const auto &vs_row_map = ns_k.second; - if (vs_row_map.size() <= final_sz) { - LOG(Gen, Info, - "AnalyticsServiceServer::_clean_up_vss ignoring vs: {} because it " - "has only {} rows", - vs, vs_row_map.size()); - continue; - } - std::vector keys_uint; - for (const auto &r : vs_row_map) { - const auto &k = r.first; - try { - keys_uint.push_back(std::stoull(k)); - } catch (int) { - LOG(Gen, Error, - "AnalyticsServiceServer::_clean_up_vss could not convert " - "key: " - "{} to uint", - k); - } - } - // sort and remove - std::sort(keys_uint.begin(), keys_uint.end()); - size_t n_del_rows = keys_uint.size() - final_sz; - std::vector keys_uint_to_del = std::vector( - keys_uint.begin(), keys_uint.begin() + n_del_rows); - std::set keys_to_del; - for (auto k : keys_uint_to_del) { - keys_to_del.insert(std::to_string(k)); - } - LOG(Gen, Info, - "AnalyticsServiceServer::_clean_up_vss vs: {} n_rows: {} removing {} " - "rows", - vs, keys_uint.size(), keys_to_del.size()); + auto keys_to_del = get_keys_to_delete(vs_row_map, final_sz); me->vs_store->remove(vs, keys_to_del); + auto t1 = utils::TimeStamp::now().to_uint64(); + LOG(Gen, Info, + "AnalyticsServiceServer::_clean_up_vss vs: {} n_rows: {} n_dels {} " + "time: {} us", + vs, vs_row_map.size(), keys_to_del.size(), t1 - t0); } } +void AnalyticsServiceServer::_clean_up_archived_theos() { + auto t0 = utils::TimeStamp::now().to_uint64(); + std::map> all_data = + me->theos_store->retrieve_all(); + auto it = all_data.find(me->archived_theos_ns); + if (it == all_data.end()) + return; + const std::map &theo_data = it->second; + std::set keys_to_del = + get_keys_to_delete(theo_data, me->archived_theos_history_sz); + me->theos_store->remove(me->archived_theos_ns, keys_to_del); + auto t1 = utils::TimeStamp::now().to_uint64(); + LOG(Gen, Info, + "AnalyticsServiceServer::_clean_up_archived_theos n_dels: {} time: {} " + "us", + keys_to_del.size(), t1 - t0); +} + } // namespace bts::analytics diff --git a/src/server/sparkd/analytics/AnalyticsServiceServer.h b/src/server/sparkd/analytics/AnalyticsServiceServer.h index ca092ea8b..143acae1b 100644 --- a/src/server/sparkd/analytics/AnalyticsServiceServer.h +++ b/src/server/sparkd/analytics/AnalyticsServiceServer.h @@ -72,5 +72,6 @@ class AnalyticsServiceServer private: void _clean_up_vss(); + void _clean_up_archived_theos(); }; } // namespace bts::analytics