Skip to content
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

Enable transactional endpoint evaluation. #700

Merged
merged 1 commit into from Jan 28, 2022
Merged

Conversation

BearLemma
Copy link
Contributor

No description provided.

server/src/deno.rs Outdated Show resolved Hide resolved
server/src/query/engine.rs Outdated Show resolved Hide resolved
let mut borrow = self.stream.borrow_mut();
borrow.as_mut().unwrap().as_mut().poll_next(cx)
let mut lock_borrow = self.lock.borrow_mut();
let mut stream_borrow = self.stream.borrow_mut();
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this needs a shitload of comments.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've added some comments from my limited POV. I don't think I understand it fully though. The code is crazy complicated and it should burn.

@glommer
Copy link

glommer commented Jan 26, 2022

It's good, but the unsafe blocks need a lot of comments explaining why they are safe, and potentially some asserts to make sure the pointers are not null and obey preconditions we may want.

@espindola
Copy link
Contributor

This should probably be rebased -i. For example, there is no reason to define TransactionStatic as Rc and then change it to Arc.

@espindola
Copy link
Contributor

Also, we should not have a commit message "fix" :-) I did that to have a single commit on top of the old branch, those changes should be split among other commits in a meaningful way.

@glommer
Copy link

glommer commented Jan 26, 2022

likely a squash is enough here

@espindola
Copy link
Contributor

likely a squash is enough here

+1

pub(crate) type TransactionStatic = Arc<Mutex<Transaction<'static, Any>>>;

struct QueryResults<T> {
fut: RefCell<Option<T>>,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Having a single inner: RefCell is a bit cleaner, but not much.

@espindola
Copy link
Contributor

If smol-rs/async-lock#20 is approved it would simplify this code a bit.

@BearLemma BearLemma force-pushed the glauber.costa/jan branch 2 times, most recently from 08bf2d0 to 3eb1f61 Compare January 27, 2022 09:53
@BearLemma
Copy link
Contributor Author

I fixuped the fix commit.

@espindola
Copy link
Contributor

I just noticed that tokio's mutex has an easier to use API:

pub async fn lock_owned(self: Arc) -> OwnedMutexGuard

which is somewhat on the lines of the patch I sent to async_mutex. Using that could simplify this code, but add more dependencies on tokio.

@BearLemma
Copy link
Contributor Author

BearLemma commented Jan 27, 2022

I just noticed that tokio's mutex has an easier to use API:

pub async fn lock_owned(self: Arc) -> OwnedMutexGuard

which is somewhat on the lines of the patch I sent to async_mutex. Using that could simplify this code, but add more dependencies on tokio.

@espindola would you mind suggesting a patch? I'm really afraid to touch that code. I think that any simplification would be very appreciated in this case. Regarding Tokio dependencies - is it a problem?

@espindola
Copy link
Contributor

Please do squash or otherwise reorganize the commits. We still have a patch with:

-pub(crate) type TransactionStatic = Rc<Mutex<Transaction<'static, Any>>>;
+pub(crate) type TransactionStatic = Arc<Mutex<Transaction<'static, Any>>>;

Also, tests fail in the intermediate commits.

@espindola
Copy link
Contributor

@espindola would you mind suggesting a patch? I'm really afraid to touch that code. I think that any simplification would be very appreciated in this case. Regarding Tokio dependencies - is it a problem?

I will try. Not sure what the status is for trying to not use tokio, but it is always nice to have options.

@BearLemma
Copy link
Contributor Author

Please do squash or otherwise reorganize the commits. We still have a patch with:

-pub(crate) type TransactionStatic = Rc<Mutex<Transaction<'static, Any>>>;
+pub(crate) type TransactionStatic = Arc<Mutex<Transaction<'static, Any>>>;

Also, tests fail in the intermediate commits.

Squashed everything.

@espindola
Copy link
Contributor

I have pushed a496bb3. Feel free to include it if you like it.

@BearLemma
Copy link
Contributor Author

I have pushed a496bb3. Feel free to include it if you like it.

@espindola very nice, I squashed it in.

@espindola
Copy link
Contributor

@espindola very nice, I squashed it in.

And I have now pushed d2a3731, which uses pin_project. The net result is that we get only one extra unsafe with this PR if that is included.

@espindola
Copy link
Contributor

@espindola very nice, I squashed it in.

And I have now pushed d2a3731, which uses pin_project. The net result is that we get only one extra unsafe with this PR if that is included.

And d3dc67f on top of that that uses flatten_stream.

@BearLemma
Copy link
Contributor Author

BearLemma commented Jan 27, 2022

@espindola very nice, I squashed it in.

And I have now pushed d2a3731, which uses pin_project. The net result is that we get only one extra unsafe with this PR if that is included.

@espindola doesn't this part of the code use a pointer to a local variable (the query_string seems to be just a local string)? That doesn't look very safe at all 🤔

@espindola
Copy link
Contributor

@espindola very nice, I squashed it in.

And I have now pushed d2a3731, which uses pin_project. The net result is that we get only one extra unsafe with this PR if that is included.

@espindola doesn't this part of the code use a pointer to a local variable (the query_string seems to be just a local string)? That doesn't look very safe at all thinking

It doesn't use a pointer to the String, it uses a pointer to the str.

@espindola
Copy link
Contributor

Take a look at 95e299f. It is rebased on top of #725. It adds only one unsafe block, which is required because of the sqlx api.

@espindola
Copy link
Contributor

espindola commented Jan 27, 2022

Take a look at 95e299f. It is rebased on top of #725. It adds only one unsafe block, which is required because of the sqlx api.

rebased espindola/jan again. it is now 081de5d

@BearLemma
Copy link
Contributor Author

Take a look at 95e299f. It is rebased on top of #725. It adds only one unsafe block, which is required because of the sqlx api.

rebased espindola/jan again. it is now 081de5d

Oh man, that looks so much better than the original. I can actually understand that. Awesome work.
So I've pushed your work to this branch and I suppose we can merge it? @glommer ?

@espindola
Copy link
Contributor

BTW, smol-rs/async-lock#20 got merged, so once that is released we should be able to move back to async_mutex.

@@ -212,7 +212,7 @@ The `findMany()` method is convenient, but also problematic if you have a lot of
entities stored because loading them can take a lot of time and memory. In future
releases of ChiselStrike, the runtime will enforce a maximum number of entities
`findMany()` can return and also enforce timeouts at the data store level. The
runtime will also provide optional pagination for the `findMany()` method.
runtime will also provide optional pagination for the `findMany()` method.
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for the future: avoid unrelated changes to the PR

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah but this is an editor extension that trims trailing white-spaces on save...

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that's fine, but use git add -p to select what goes into the PR or not

Comment on lines +282 to +283
transaction automatically.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Follow up: Mention that the user should be careful that external accesses like POST requests with side effects obviously are not part of the transaction and users should be careful with that

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't understand the situation. You mean that our user would call a chisel endpoint within another chisel endpoint? Doesn't that go without saying?

glommer
glommer previously approved these changes Jan 28, 2022
@espindola
Copy link
Contributor

So, is this approved? Looks like github somehow lost the approval.

@BearLemma
Copy link
Contributor Author

BearLemma commented Jan 28, 2022

So, is this approved? Looks like github somehow lost the approval.

I had to do another rebase as there were changes in main and approval is lost when you push a change to the branch upon which a PR is based.

Copy link
Contributor

@espindola espindola left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

reapproving

@mergify mergify bot merged commit 3f31cb1 into main Jan 28, 2022
@mergify mergify bot deleted the glauber.costa/jan branch January 28, 2022 14:28
@BearLemma BearLemma restored the glauber.costa/jan branch January 28, 2022 17:17
@glommer glommer deleted the glauber.costa/jan branch May 16, 2022 16:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants