Repository navigation
feat: add LRU-aware cache warming for KeyValues #3592
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
bblaszkow06
wants to merge
12
commits into
Logflare:main
Choose a base branch
from
bblaszkow06:bb/o11y-1890-kv-warmup-lru
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
7cd3e7f
feat: add LRU-aware cache warming for KeyValues
bblaszkow06 5e9279e
style: remove unnecessary parentheses from zero-arg function definition
bblaszkow06 b561843
refactor: replace ETS UsageTracker with cache-streamed Oban touch for…
bblaszkow06 9f7dc11
chore: update migration timestamp, revert unneeded refactor
bblaszkow06 fd19cb0
fix: exclude warmed entries from KeyValues usage tracking
bblaszkow06 7dd0452
Merge branch 'main' into bb/o11y-1890-kv-warmup-lru
bblaszkow06 7d14945
Merge branch 'main' into bb/o11y-1890-kv-warmup-lru
bblaszkow06 34be83c
Merge branch 'main' into bb/o11y-1890-kv-warmup-lru
bblaszkow06 b092fd6
Merge branch 'main' into bb/o11y-1890-kv-warmup-lru
bblaszkow06 85eef23
Merge branch 'main' into bb/o11y-1890-kv-warmup-lru
bblaszkow06 755b4bf
Merge branch 'main' into bb/o11y-1890-kv-warmup-lru
bblaszkow06 36624e9
Merge branch 'main' into bb/o11y-1890-kv-warmup-lru
Ziinc File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| defmodule Logflare.KeyValues.KeyValueUsage do | ||
| @moduledoc """ | ||
| A helper table storing the last-touched timestamp for `KeyValue` entries. | ||
|
|
||
| This table is intentionally **excluded from the `logflare_pub` publication**, so | ||
| upserting `last_used_at` does not flow through `ContextCache.CacheBuster` and does | ||
| not evict entries from `KeyValues.Cache` — which is precisely the cache whose access | ||
| patterns drive the usage signal. Storing usage on the `key_values` row itself would | ||
| cause every touch to bust the cache entry it is trying to track. | ||
| """ | ||
| use TypedEctoSchema | ||
|
|
||
| alias Logflare.KeyValues.KeyValue | ||
|
|
||
| typed_schema "key_value_usages" do | ||
| field :last_used_at, :utc_datetime_usec | ||
|
|
||
| belongs_to :key_value, KeyValue | ||
| end | ||
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| defmodule Logflare.KeyValues.UsageTouchWorker do | ||
| @moduledoc false | ||
| use Oban.Worker, queue: :default, max_attempts: 1 | ||
|
|
||
| alias Logflare.KeyValues | ||
| alias Logflare.KeyValues.Cache | ||
|
|
||
| @impl Oban.Worker | ||
| @spec perform(Oban.Job.t()) :: :ok | ||
| def perform(_job) do | ||
| Cache.touch_recent_usages() | ||
| KeyValues.prune_usages() | ||
| :ok | ||
| end | ||
| end |
13 changes: 13 additions & 0 deletions
13
priv/repo/migrations/20260921000000_create_key_value_usages.exs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| defmodule Logflare.Repo.Migrations.CreateKeyValueUsages do | ||
| use Ecto.Migration | ||
|
|
||
| def change do | ||
| create table(:key_value_usages) do | ||
| add :key_value_id, references(:key_values, on_delete: :delete_all), null: false | ||
| add :last_used_at, :utc_datetime_usec, null: false, default: fragment("now()") | ||
| end | ||
|
|
||
| create unique_index(:key_value_usages, [:key_value_id]) | ||
| create index(:key_value_usages, [:last_used_at]) | ||
| end | ||
| end | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hmm this also implies that if all 1 mil records are in use, then 1 mil records will also be created in this table. why would we want a separate table as compared to having these two fields directly on the
:key_valuestable?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm guessing that the separate table means that the table isn't tracked it isn't tracked as part of ContextCache since it is not included in the published tables, so bumping it would not trigger cache invalidations.
should make this clear in the KeyValuesUsage module
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should probably have some periodic truncation logic to keep the size of this table down