Skip to content

Commit

Permalink
Merge pull request #2923 from cloudflare/jmp/waitForBookmark
Browse files Browse the repository at this point in the history
Add waitForBookmark to DurableObjectStorage
  • Loading branch information
justin-mp authored Oct 18, 2024
2 parents c400fdd + 4d5c89c commit b6bc9cf
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/workerd/api/actor-state.c++
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

ActorCacheOps& DurableObjectTransaction::getCache(OpName op) {
JSG_REQUIRE(!rolledBack, Error, kj::str("Cannot ", op, " on rolled back transaction"));
auto& result = *JSG_REQUIRE_NONNULL(cacheTxn, Error,
Expand Down
9 changes: 9 additions & 0 deletions src/workerd/api/actor-state.h
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,14 @@ class DurableObjectStorage: public jsg::Object, public DurableObjectStorageOpera
// by calling state.abort() or by throwing from a blockConcurrencyWhile() callback.
kj::Promise<kj::String> onNextSessionRestoreBookmark(kj::String bookmark);

// Wait until the database has been updated to the state represented by `bookmark`.
//
// `waitForBookmark` is useful synchronizing requests across replicas of the same database. On
// primary databases, `waitForBookmark` will resolve immediately. On replica databases,
// `waitForBookmark` will resolve when the replica has been updated to a point at or after
// `bookmark`.
kj::Promise<void> waitForBookmark(kj::String bookmark);

JSG_RESOURCE_TYPE(DurableObjectStorage, CompatibilityFlags::Reader flags) {
JSG_METHOD(get);
JSG_METHOD(list);
Expand All @@ -245,6 +253,7 @@ class DurableObjectStorage: public jsg::Object, public DurableObjectStorageOpera
JSG_METHOD(getCurrentBookmark);
JSG_METHOD(getBookmarkForTime);
JSG_METHOD(onNextSessionRestoreBookmark);
JSG_METHOD(waitForBookmark);

JSG_TS_OVERRIDE({
get<T = unknown>(key: string, options?: DurableObjectGetOptions): Promise<T | undefined>;
Expand Down
5 changes: 5 additions & 0 deletions src/workerd/io/actor-cache.c++
Original file line number Diff line number Diff line change
Expand Up @@ -3357,4 +3357,9 @@ kj::Promise<kj::String> ActorCacheInterface::onNextSessionRestoreBookmark(kj::St
Error, "This Durable Object's storage back-end does not implement point-in-time recovery.");
}

kj::Promise<void> ActorCacheInterface::waitForBookmark(kj::StringPtr bookmark) {
JSG_FAIL_REQUIRE(
Error, "This Durable Object's storage back-end does not implement point-in-time recovery.");
}

} // namespace workerd
1 change: 1 addition & 0 deletions src/workerd/io/actor-cache.h
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,7 @@ class ActorCacheInterface: public ActorCacheOps {
virtual kj::Promise<kj::String> getCurrentBookmark();
virtual kj::Promise<kj::String> getBookmarkForTime(kj::Date timestamp);
virtual kj::Promise<kj::String> onNextSessionRestoreBookmark(kj::StringPtr bookmark);
virtual kj::Promise<void> waitForBookmark(kj::StringPtr bookmark);
};

// An in-memory caching layer on top of ActorStorage.Stage RPC interface.
Expand Down

0 comments on commit b6bc9cf

Please sign in to comment.