Enhance Alternator API#158
Conversation
ConnectionConf now only has fields that are shared between different databases. Database specific fields are moved to DbConnectionConf inside the scripting folder. (cherry picked from commit 5e4661e)
The config allows for specifying the credentials as command line arguments. By specifying the aws-credentials option the SDK will fetch credentials from the environment. (cherry picked from commit 1d37fa9)
Used serde(skip_serializing) to avoid serializing secret fields. (cherry picked from commit 62669ca)
Sets are represented as special objects with a single specific key. The items of the sets are stored in a vector. (cherry picked from commit d775dfc)
…les. (cherry picked from commit a1dd717)
PaginationToken will allow for retrying both normal Query requests and batch requests. (cherry picked from commit 0313ea2)
Implemented the functions with automatic retry and added a workflow that demonstrates the usage. (cherry picked from commit 7cac86f)
Added new `get_unprocessed` to batch write and get. Modified `handle_request` and added `format_batch_result` to properly return the unprocessed items. (cherry picked from commit a0f9ecb)
| /// Use AWS credentials and region from the environment. | ||
| /// If this flag is set, access key ID, secret access key, and region args will be ignored. | ||
| #[clap(long("aws-credentials"))] | ||
| pub aws_credentials: bool, |
There was a problem hiding this comment.
I think that the aws-credentials must be mutually exclusive to other 3 on the config validation level.
So, user will know he needs to specify this information in one or another way.
It will not make him to remember the order of significance...
There was a problem hiding this comment.
Used conflicts_with_all to mark this as mutually exclusive with access-key-id, secret-access-key and region.
|
|
||
| /// Marks a list of items as an Alternator string set. | ||
| #[rune::function] | ||
| pub fn sset(items: Vec<Value>) -> VmResult<Value> { |
There was a problem hiding this comment.
Such short names are pretty cryptic, IMHO.
I would like to see more intuitive ones reading rune scripts - such as string_set, number_set and bytes_set (or binary_set)?
There was a problem hiding this comment.
DynamoDB uses even more cryptic names: Ss, Ns and Bs haha.
But good point, changed them to the names you proposed.
| } | ||
|
|
||
| pub async fn run(db, i) { | ||
| let batch_size = 5; |
There was a problem hiding this comment.
What happens when we use bigger sizes?
What do we expect to happen?
Shouldn't the oversize be covered in rune scripts?
There was a problem hiding this comment.
In Alternator/DynamoDB the maximum batch size is limited to 100 by default, but this is configurable on the DB side (alternator_max_items_in_batch_write).
Providing more items will cause the request to fail and will be reported to rune as an error. I don't think we should do anything about it in our wrapper, the database already provides a descriptive error for it.
| type: "put", | ||
| item: #{ | ||
| pk: base_id + j.to_string(), | ||
| data: "batch_item_" + j.to_string() |
There was a problem hiding this comment.
Double transformation of the j into a string.
Also, it may be written shorter removing double transformation:
pk: `base_id${j}`,
data: `batch_item_${j}`
|
|
||
| pub async fn run(db, i) { | ||
| let batch_size = 5; | ||
| let base_id = "user_" + i.to_string() + "_"; |
There was a problem hiding this comment.
let base_id = `user_${i}_`;
?
| if let Some(unprocessed) = res.get("unprocessed_items") { | ||
| current_writes = unprocessed; | ||
| } else { | ||
| current_writes = []; // All items processed |
There was a problem hiding this comment.
Shouldn't the break do what you need?
It looks exactly the case for it.
|
@vponomaryov thanks for already reviewing. |
|
I made a PR with the fixes in our repo: scylladb-zpp-2025-alternator-rs-driver#45 |
|
@m-szymon |
@vponomaryov you were too quick with review - I created draft, but I was not sure if we want to add something, especially that we were syncing with some other changes from master. I will rebase and include fixes in this PR. |
Refactor ConnectionConf and add custom credentials support for Alternator
DbConnectionConf field. This way the database specific code is contained
inside the scripting folder.
and used them in connect.
passwords/secrets. This stops the secrets from being saved to generated
raports.
The Alternator credential options work as follows:
aws-credentialsis specified, the default AWS SDK credentialsflow will be used, i.e. the SDK will try to fetch the credentials from
the environment
access-key-idandsecret-access-keyoptions can be used tospecify the keys, otherwise the default empty values ("") are used
Add support for DynamoDB Sets to Alternator.
Implemented support for passing and receiving of DynamoDB Sets to Rune.
They are implemented as objects with exactly one key with a special
name. The values are stored as a vector of appropriate types.
Convenience functions used to create the sets are provided to Rune.
Implement batch_get_item and batch_write_item.
Implemented the functions and added workflows that demonstrates the
usage.
Batch operations support the
get_unprocessedoption that disables theauto pagination feature and allows the user to do it manually from rune.
Implementing the auto pagination feature required editing some existing
traits.
Follow-up #138