-
Notifications
You must be signed in to change notification settings - Fork 181
PostgresKeyValueStorage and NamespaceRoutedKeyValueStorage #2959
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
Merged
Merged
Changes from 1 commit
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
a2c6512
feat: KeyValueStorage implementation for Postgres
kmatasfp c80437b
feat: impromve multi queries
kmatasfp 4e70ee6
Merge branch 'main' into 2957-keyvaluestorage-for-postgres
kmatasfp 8d4d0b4
Merge branch 'main' into 2957-keyvaluestorage-for-postgres
kmatasfp 757d549
feat: remove hash for set_storage, does not add value
kmatasfp f607ac4
chore: formatting
kmatasfp 65df04c
Merge branch 'main' into 2957-keyvaluestorage-for-postgres
kmatasfp 8545f8c
feat: clearer purpose for the consts
kmatasfp bd3d2b5
feat: add RoutedKeyValueStorage
kmatasfp d64590c
Merge branch 'main' into 2957-keyvaluestorage-for-postgres
kmatasfp bbe2435
feat: make RoutedKeyValueStorage more generic
kmatasfp 4387bd0
fix: formatting
kmatasfp 97e8f3f
Merge branch 'main' into 2957-keyvaluestorage-for-postgres
kmatasfp 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
File renamed without changes.
26 changes: 26 additions & 0 deletions
26
golem-worker-executor/db/migration/postgres/keyvalue/postgres/001_init.sql
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,26 @@ | ||
| CREATE TABLE kv_storage ( | ||
| namespace TEXT NOT NULL, | ||
| key TEXT NOT NULL, | ||
| value BYTEA NOT NULL, | ||
| PRIMARY KEY (namespace, key) | ||
| ); | ||
|
|
||
| CREATE TABLE set_storage ( | ||
| namespace TEXT NOT NULL, | ||
| key TEXT NOT NULL, | ||
| value_hash BYTEA NOT NULL, | ||
| value BYTEA NOT NULL, | ||
| PRIMARY KEY (namespace, key, value_hash) | ||
| ); | ||
|
|
||
| CREATE TABLE sorted_set_storage ( | ||
| namespace TEXT NOT NULL, | ||
| key TEXT NOT NULL, | ||
| value_hash BYTEA NOT NULL, | ||
| value BYTEA NOT NULL, | ||
| score DOUBLE PRECISION NOT NULL, | ||
| PRIMARY KEY (namespace, key, value_hash) | ||
| ); | ||
|
|
||
| CREATE INDEX idx_sorted_set_storage_namespace_key_score | ||
| ON sorted_set_storage (namespace, key, score); | ||
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 |
|---|---|---|
|
|
@@ -14,6 +14,7 @@ | |
|
|
||
| pub mod memory; | ||
| pub mod multi_sqlite; | ||
| pub mod postgres; | ||
| pub mod redis; | ||
| pub mod sqlite; | ||
|
|
||
|
|
||
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.
Uh oh!
There was an error while loading. Please reload this page.
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.
FYI PK on (namespace, key, value BYTEA) can become expensive, so we use blake3 hash of the value here instead
Uh oh!
There was an error while loading. Please reload this page.
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.
Assumption is we store values larger than 32 bytes in the set, if not then hash optimization does not make any sense
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.
We only use the "set" subset of the trait for tracking running agents per executor, and the value is always a serialized
OwnedAgentId. We can change the trait API to use strings for this, if that helpsThere 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.
yeah i think using strings as a value here would be more efficient and I take for sorted_set the value is equally small in reality @vigoo ?
Uh oh!
There was an error while loading. Please reload this page.
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.
and from my investigation we seem to write more than just a
OwnedAgentIdto the set, we write also this guy as a valuegolem/golem-common/src/model/mod.rs
Line 677 in e00a1dc
we do it here:
golem/golem-worker-executor/src/services/worker.rs
Line 309 in e00a1dc
Uh oh!
There was an error while loading. Please reload this page.
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.
To answer my own question, sorted_set values seems be all over the place, from small to largish, its serialized value of:
golem/golem-common/src/model/mod.rs
Line 302 in e00a1dc
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.
The AgentStatusRecord is a typical "KV cache" scenario. There the value is big indeed, the whole serialized record. But that's the "get/set" API.
What I was referring to is the "set-like" API which is only used to to store a set of currently running agents.
The sorted set "subset" of the kv store trait is only used for the scheduler.
(We could split the KV Store trait to 3 sub-traits actually, but let's not do it now)
Uh oh!
There was an error while loading. Please reload this page.
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.
yes you are right as always xD. Confused myself, early morning here xD
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.
Ok removed value hash for
set_storagekept it forsorted_set_storageasScheduledAction::Invokecan be largish