diff --git a/src/workerd/api/actor-state.c++ b/src/workerd/api/actor-state.c++ index db23d3a4c00..4d6523c0c96 100644 --- a/src/workerd/api/actor-state.c++ +++ b/src/workerd/api/actor-state.c++ @@ -735,6 +735,10 @@ kj::Promise DurableObjectStorage::onNextSessionRestoreBookmark(kj::S return cache->onNextSessionRestoreBookmark(bookmark); } +kj::Promise 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, diff --git a/src/workerd/api/actor-state.h b/src/workerd/api/actor-state.h index e2c62a321af..490c8ff28e9 100644 --- a/src/workerd/api/actor-state.h +++ b/src/workerd/api/actor-state.h @@ -227,6 +227,14 @@ class DurableObjectStorage: public jsg::Object, public DurableObjectStorageOpera // by calling state.abort() or by throwing from a blockConcurrencyWhile() callback. kj::Promise 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 waitForBookmark(kj::String bookmark); + JSG_RESOURCE_TYPE(DurableObjectStorage, CompatibilityFlags::Reader flags) { JSG_METHOD(get); JSG_METHOD(list); @@ -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(key: string, options?: DurableObjectGetOptions): Promise; diff --git a/src/workerd/io/actor-cache.c++ b/src/workerd/io/actor-cache.c++ index 5da0c0c6c28..67d0856b70c 100644 --- a/src/workerd/io/actor-cache.c++ +++ b/src/workerd/io/actor-cache.c++ @@ -3357,4 +3357,9 @@ kj::Promise ActorCacheInterface::onNextSessionRestoreBookmark(kj::St Error, "This Durable Object's storage back-end does not implement point-in-time recovery."); } +kj::Promise 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 diff --git a/src/workerd/io/actor-cache.h b/src/workerd/io/actor-cache.h index 1ccf53a206a..bfe8a5b7ca4 100644 --- a/src/workerd/io/actor-cache.h +++ b/src/workerd/io/actor-cache.h @@ -238,6 +238,7 @@ class ActorCacheInterface: public ActorCacheOps { virtual kj::Promise getCurrentBookmark(); virtual kj::Promise getBookmarkForTime(kj::Date timestamp); virtual kj::Promise onNextSessionRestoreBookmark(kj::StringPtr bookmark); + virtual kj::Promise waitForBookmark(kj::StringPtr bookmark); }; // An in-memory caching layer on top of ActorStorage.Stage RPC interface.