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

Add waitForBookmark to DurableObjectStorage #2923

Merged
merged 1 commit into from
Oct 18, 2024
Merged

Conversation

justin-mp
Copy link
Contributor

This exposes the internal waitForBookmark method to JavaScript. We’ll need this in order to implement decent consistency models with SQLite replication.

@justin-mp justin-mp requested review from a team as code owners October 14, 2024 23:47
@justin-mp justin-mp force-pushed the jmp/waitForBookmark branch 2 times, most recently from 30f4a45 to 59ce3bd Compare October 15, 2024 19:10
@justin-mp
Copy link
Contributor Author

justin-mp commented Oct 15, 2024

59ce3bd is a rebase on main.

@@ -735,6 +735,10 @@ kj::Promise<kj::String> DurableObjectStorage::onNextSessionRestoreBookmark(kj::S
return cache->onNextSessionRestoreBookmark(bookmark);
}

kj::Promise<void> DurableObjectStorage::waitForBookmark(kj::String bookmark) {
return cache->waitForBookmark(bookmark);
Copy link
Member

Choose a reason for hiding this comment

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

Can this safely be called multiple times from javascript? As it is here, every call on this will result in a new JavaScript promise backed by a kj::Promise... specifically, if I do..

const p1 = whatever.waitForBookmark('...');
const p2 = whatever.waitForBookmark('...');

Then p1 !== p2

Should this always return the same JS promise when the bookmark id is the same and is already being waited on?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The internal PR waits on the same forked promise, so in production this will wait on the same thing. p1 will still be !== p2, is that a problem?

Copy link
Member

Choose a reason for hiding this comment

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

Not a problem just something to be aware of. Creating multiple promises that wait on the same thing can add performance cost.

Copy link
Member

Choose a reason for hiding this comment

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

I think this is fine as-is. Don't think people are likely to call it multiple times in a row like that.

Copy link
Member

Choose a reason for hiding this comment

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

But for @justin-mp's understanding: One problem with waiting on multiple forks of the KJ promise is that each one's resolution will lead to a separate entering of the isolate, requiring taking the isolate lock, setting up CPU time limits, etc., which is relatively expensive. If we somehow imported just one instance of the KJ promise to JS, and then had all the waiters wait on that shared JS promise, then the isolate only needs to be entered once.

But this is an optimization which can easily be left for later.

This exposes the internal `waitForBookmark` method to JavaScript.
We’ll need this in order to implement decent consistency models with
SQLite replication.
@justin-mp
Copy link
Contributor Author

@justin-mp justin-mp merged commit b6bc9cf into main Oct 18, 2024
13 checks passed
@justin-mp justin-mp deleted the jmp/waitForBookmark branch October 18, 2024 19:04
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.

3 participants