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
add snapshot while context , default configs updates #10
base: main
Are you sure you want to change the base?
Conversation
b6410a5
to
b7c93df
Compare
crates/context_aware_config/migrations/2024-04-22-122806_config_verions/up.sql
Outdated
Show resolved
Hide resolved
@@ -313,7 +356,8 @@ async fn get_filtered_config( | |||
.map_or_else(|_| json!(value), |int_val| json!(int_val)), |
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 think we can now deprecate this handler.
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.
why?
b7c93df
to
2b3bd23
Compare
@@ -134,6 +135,8 @@ async fn main() -> Result<()> { | |||
return view! { <App app_envs=routes_ui_envs.clone()/> }; | |||
}); | |||
|
|||
let snowflake_generator = Arc::new(Mutex::new(SnowflakeIdGenerator::new(1, 1))); |
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.
Why add Arc? as per rust docs
Shared references in Rust disallow mutation by default, and Arc is no exception: you cannot generally obtain a mutable reference to something inside an Arc. If you need to mutate through an Arc, use Mutex, RwLock, or one of the Atomic types.
If we aren't mutating the snowflakeIdGenerator, just use Arc otherwise there is no need to add it
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.
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.
@Datron arc is used to share the same mutex instance
you can check the example for mutex implementation
/// use std::sync::{Arc, Mutex}; /// use std::thread; /// /// let mutex = Arc::new(Mutex::new(0)); /// let c_mutex = Arc::clone(&mutex); /// /// thread::spawn(move || { /// let mut lock = c_mutex.try_lock(); /// if let Ok(ref mut mutex) = lock { /// **mutex = 10; /// } else { /// println!("try_lock failed"); /// } /// }).join().expect("thread::spawn failed"); /// assert_eq!(*mutex.lock().unwrap(), 10);
crates/context_aware_config/migrations/2024-04-22-122806_config_verions/up.sql
Outdated
Show resolved
Hide resolved
Can we squash all commits into one? |
2b3bd23
to
7c77fe5
Compare
70fabc6
to
5a0dcbd
Compare
800bbe4
to
0699ef5
Compare
0699ef5
to
ca5e540
Compare
3ae53b5
to
bb9cc5a
Compare
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.
What happens when someone tries to update tags? Is that possible?
@@ -177,12 +221,13 @@ async fn get( | |||
query_params_map.insert( | |||
key, | |||
value | |||
.parse::<i32>() | |||
.parse::<i64>() |
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.
Why bump up to i64?
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.
@Datron expecting version_id in query params, which is snowflake_id and it is i64
config -> Json, | ||
config_hash -> Text, | ||
- tags -> Nullable<Array<Nullable<Varchar>>>, | ||
+ tags -> Nullable<Array<Varchar>>, |
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.
Would like to avoid this patch file. Can we make the type in DB in such a way that we can avoid this?
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 can concatenate tags with comma and store it as string , but then the DB filter query will not be optimised
https://diesel.rs/guides/configuring-diesel-cli.html
https://diesel.rs/guides/migration_guide.html
bb9cc5a
to
dfdc5ba
Compare
@Datron currently this is not supported , a different api will be needed |
dfdc5ba
to
4524af3
Compare
@@ -5,11 +5,18 @@ use serde_json::{Map, Value}; | |||
pub struct PutReq { | |||
pub context: Map<String, Value>, | |||
pub r#override: Map<String, Value>, | |||
pub tags: Option<Vec<String>>, |
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.
Can we accept tags as headers? These don't really belong here, and the name is also misleading should be snapshot_tags
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.
headers can be used when its value is consistent across similar requests or let say it is a global level identifier for requests .
although tags is consistent across all write requests , I think we should not add this in header because probably tags can be changed based on the different operations (c, u, d) on different entities (default_configs, contexts)
also we have other entities and request where this header is of no use ( like functions, types, dimensions, get apis ) so for me it probably seems more close to a create request than a global request identifier
will change tags -> version_tags
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.
tags
is a actually a metadata here, and not exactly the part of the request, are we using this to tag the actual resource we are touching in these request, the answer is no, these tags in fact are used to tag the versions created after the actual defined job for the request is completed.
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 are repeating everywhere too, all request types are changed, can't we do something to abstract this out.
.do_update() | ||
.set(&default_config) | ||
.execute(transaction_conn); | ||
add_config_version(&state, req.tags, transaction_conn)?; |
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.
@pratikmishra356 , do we have to fail a request because we weren't able to create a snapshot.
What I think, the user never intended to make a snapshot, he just wanted to create a default_config/context/....., creating a snapshot should be our separate task, I feel we really shouldn't fail the endpoints when we fail to create a snapshot
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.
since currently we dont have any process/event based tracking mechanisms to do these operations in async , we might lose track of updates on configs thats why we followed this behavior ,
we assume every updates on default_config and contexts is crucial which results in changing the configs , and since now we are relying only on config_version table for serving configs ( i.e no more db fetch from multiple tables ) it is important to have this both operation in sync
0a00a77
to
f006a38
Compare
0305021
to
6b61691
Compare
6b61691
to
a6142d4
Compare
Problem
Record for config's history after every cac_config changes,
we also encountered problem regarding generating snowflake_id, we were not dropping the acquired mutex lock,
and when generating another snowflake_id , it gets stuck in deadlock kind of situation
Solution
Created config_versions table which will store the config's snapshot after every updates which affect the configs.
Fetch contexts and default_configs and insert into config_Versions table after any updates within the same transaction.
we are explicitly dropping acquired lock after snowflake_id generation
Also accepting tags parameters in every update request so that user can tag every versions
Environment variable changes
NA
Pre-deployment activity
Create db changes
Post-deployment activity
NA
API changes
get_config apis we will now provide priority inside context objects
adding optional tags field in every context, default_config and experiments updates
accepting version queryparam in every get_config apis
Possible Issues in the future
NA