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 experimental method to create DO replicas #2824

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/workerd/api/actor-state.c++
Original file line number Diff line number Diff line change
Expand Up @@ -739,6 +739,10 @@ kj::Promise<void> DurableObjectStorage::waitForBookmark(kj::String bookmark) {
return cache->waitForBookmark(bookmark);
}

void DurableObjectStorage::ensureReplicas() {
return cache->ensureReplicas();
}

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
10 changes: 10 additions & 0 deletions src/workerd/api/actor-state.h
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,12 @@ class DurableObjectStorage: public jsg::Object, public DurableObjectStorageOpera
// `bookmark`.
kj::Promise<void> waitForBookmark(kj::String bookmark);

// Arrange to create replicas for this Durable Object.
//
// Once a Durable Object instance calls `ensureReplicas`, all subsequent calls will be no-ops,
// thus it is idempotent.
void ensureReplicas();

JSG_RESOURCE_TYPE(DurableObjectStorage, CompatibilityFlags::Reader flags) {
JSG_METHOD(get);
JSG_METHOD(list);
Expand All @@ -258,6 +264,10 @@ class DurableObjectStorage: public jsg::Object, public DurableObjectStorageOpera
JSG_METHOD(waitForBookmark);
}

if (flags.getReplicaRouting()) {
JSG_METHOD(ensureReplicas);
}

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

void ActorCacheInterface::ensureReplicas() {
JSG_FAIL_REQUIRE(Error, "This Durable Object's storage back-end does not support replication.");
Copy link
Member

Choose a reason for hiding this comment

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

Nit: Can you add a comment along the lines of this being intended to be implemented internally

}

} // namespace workerd
2 changes: 2 additions & 0 deletions src/workerd/io/actor-cache.h
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,8 @@ class ActorCacheInterface: public ActorCacheOps {
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);

virtual void ensureReplicas();
Copy link
Member

Choose a reason for hiding this comment

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

Given that it's just a throw, consider just inlining the implementation with the throw here. Just keeps things a bit simpler.

};

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