-
Notifications
You must be signed in to change notification settings - Fork 49
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
refactor: add common crates #1281
Conversation
59dc0e6
to
6018cf7
Compare
I made the opinionated decision to remove syncstorage-rs's dependency on Actix's |
6018cf7
to
2db1c2f
Compare
FYI at one point the unit tests were in a separate crate (IIRC so they ran on nightly to utilize nightly only async/await 😄 ) and instead of wrapping things in
It looks like actix_web 4.0's I can't recall tokio |
Looks like the default upper limit on tokio's blocking threads is 512: https://docs.rs/tokio/latest/tokio/runtime/struct.Builder.html#method.max_blocking_threads I think that should be plenty given that we currently set ACTIX_THREADPOOL to be |
2db1c2f
to
de88cc6
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.
Just a couple small things.
Thanks for carefully doing this, I really appreciate the git history being preserved.
syncstorage/src/db/transaction.rs
Outdated
.await | ||
.map_err(ApiError::from)?; |
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.
Looks like this'll continue working:
.await | |
.map_err(ApiError::from)?; | |
.await?; |
.map_err(|_| TokenserverError::resource_unavailable())? | ||
.map_err(Into::into) |
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.
.map_err(|_| TokenserverError::resource_unavailable())? | |
.map_err(Into::into) | |
.map_err(|_| TokenserverError::resource_unavailable())? |
@@ -112,6 +117,17 @@ impl BatchBsoBody { | |||
} | |||
} | |||
|
|||
impl From<BatchBsoBody> for PostCollectionBso { |
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.
Leave this for now but I'll note we had a TODO comment somewhere that dissapeared to kill one of these types. I logged #1296 to revisit it later.
.map(|id| (id, "db error".to_owned())), | ||
) | ||
} | ||
Err(e) if e.is_conflict() || e.is_quota() => return Err(e.into()), |
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.
🎉
8cb1814
to
c7f1b7f
Compare
Thanks for the review @pjenvey -- this was a long one! |
One thing I just thought of: I changed the database methods to return a |
Yea, good call. |
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.
Looks good!
I'm a little concerned about some of the test functions potentially "leaking" into non-test, since those tend to act without safety checks, but I'm fine with flagging them softly for later potential cleanup. Since they seem to be fairly isolated, perhaps we create a "test" trait we apply? 🤷🏻♂️
offset, | ||
ids, | ||
.. | ||
} = params.params; | ||
let now = self.timestamp().as_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.
Thank You!
(Sorry, but I kinda hated the source masking that this was doing.)
@@ -2128,13 +2104,11 @@ impl<'a> Db<'a> for SpannerDb { | |||
} | |||
} | |||
|
|||
#[cfg(test)] | |||
fn create_collection(&self, name: String) -> DbFuture<'_, i32> { |
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.
My only thought about these functions is that they're really not supposed to be used outside of tests. I wonder if it might make sense to eventually move them into a test module rather than have them sprayed around like they currently are. (I also wonder if it might make sense to flag these as test helper functions, like with a comment or something.)
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.
Yeah I think it might be wise to do something with them. Putting them into a separate trait would at least make them slightly harder to use by mistake 🤔 I'll log an issue for this
@@ -91,6 +80,23 @@ pub struct PoolState { | |||
pub idle_connections: u32, | |||
} | |||
|
|||
impl From<diesel::r2d2::State> for PoolState { |
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.
🎉
Err(DbErrorKind::Integrity( | ||
"Invalid modified i64 (< 0)".to_owned(), | ||
))?; | ||
return Err(DbErrorKind::Integrity("Invalid modified i64 (< 0)".to_owned()).into()); |
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.
ugh, yeah, the previous version was clever. Thanks!
fn from(db_error: DbError) -> Self { | ||
Self { | ||
status: db_error.status, | ||
backtrace: db_error.backtrace.clone(), |
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 won't hold up this PR any longer over this but we could avoid this clone -- maybe adding a backtrace2
method that defers to the inner DbError
+ making the ApiError::backtrace
field a private Option<Backtrace>
.
thiserror
seems to provide a nice way of automatically implementing this for the std::Error::backtrace
method but that method's still unstable, unfortunately making many backtrace things like this a bit clunky.
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 could also use mem::take here, but I'm not sure if that's actually much better than clone (i.e. would memory be allocated for the newly-created default value?)
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 answer appears to be yes, as Backtrace::default()
just calls Backtrace::new()
, which just creates a backtrace :(
Description
syncstorage
cratesyncstorage-db-common
syncstorage-common
tokenserver-common
ApiError
HawkIdentifier
DbError.kind
andApiError.kind
private to simplify APIThings I was unsure about:
#[cfg(test)]
annotations, since anything pinned to thetest
feature isn't made public to other crates. I don't think this is a big deal but just wanted to mention itTesting
No change in functionality
Issue(s)
Closes #1275