Skip to content

Commit 38ea945

Browse files
authored
Merge pull request #2621 from cloudflare/milan/replica-routing-compat-flag
Add `replicaRouting` compat flag
2 parents ea718b8 + 619b393 commit 38ea945

File tree

6 files changed

+22
-6
lines changed

6 files changed

+22
-6
lines changed

Diff for: src/workerd/api/actor.c++

+10-5
Original file line numberDiff line numberDiff line change
@@ -53,11 +53,13 @@ public:
5353
GlobalActorOutgoingFactory(uint channelId,
5454
jsg::Ref<DurableObjectId> id,
5555
kj::Maybe<kj::String> locationHint,
56-
ActorGetMode mode)
56+
ActorGetMode mode,
57+
bool enableReplicaRouting)
5758
: channelId(channelId),
5859
id(kj::mv(id)),
5960
locationHint(kj::mv(locationHint)),
60-
mode(mode) {}
61+
mode(mode),
62+
enableReplicaRouting(enableReplicaRouting) {}
6163

6264
kj::Own<WorkerInterface> newSingleUseClient(kj::Maybe<kj::String> cfStr) override {
6365
auto& context = IoContext::current();
@@ -71,7 +73,7 @@ public:
7173
// Lazily initialize actorChannel
7274
if (actorChannel == kj::none) {
7375
actorChannel = context.getGlobalActorChannel(
74-
channelId, id->getInner(), kj::mv(locationHint), mode, span);
76+
channelId, id->getInner(), kj::mv(locationHint), mode, enableReplicaRouting, span);
7577
}
7678

7779
return KJ_REQUIRE_NONNULL(actorChannel)
@@ -87,6 +89,7 @@ private:
8789
jsg::Ref<DurableObjectId> id;
8890
kj::Maybe<kj::String> locationHint;
8991
ActorGetMode mode;
92+
bool enableReplicaRouting;
9093
kj::Maybe<kj::Own<IoChannelFactory::ActorChannel>> actorChannel;
9194
};
9295

@@ -147,8 +150,10 @@ jsg::Ref<DurableObject> DurableObjectNamespace::getImpl(jsg::Lock& js,
147150
locationHint = kj::mv(o.locationHint);
148151
}
149152

150-
auto outgoingFactory = context.addObject<Fetcher::OutgoingFactory>(
151-
kj::heap<GlobalActorOutgoingFactory>(channel, id.addRef(), kj::mv(locationHint), mode));
153+
bool enableReplicaRouting = FeatureFlags::get(js).getReplicaRouting();
154+
auto outgoingFactory =
155+
context.addObject<Fetcher::OutgoingFactory>(kj::heap<GlobalActorOutgoingFactory>(
156+
channel, id.addRef(), kj::mv(locationHint), mode, enableReplicaRouting));
152157
auto requiresHost = FeatureFlags::get(js).getDurableObjectFetchRequiresSchemeAuthority()
153158
? Fetcher::RequiresHostAndProtocol::YES
154159
: Fetcher::RequiresHostAndProtocol::NO;

Diff for: src/workerd/io/compatibility-date.capnp

+6
Original file line numberDiff line numberDiff line change
@@ -588,4 +588,10 @@ struct CompatibilityFlags @0x8f8c1b68151b6cef {
588588
# Enables node:zlib implementation while it is in-development.
589589
# Once the node:zlib implementation is complete, this will be automatically enabled when
590590
# nodejs_compat is enabled.
591+
592+
replicaRouting @60 :Bool
593+
$compatEnableFlag("replica_routing")
594+
$experimental;
595+
# Enables routing to a replica on the client-side.
596+
# Doesn't mean requests *will* be routed to a replica, only that they can be.
591597
}

Diff for: src/workerd/io/io-channels.h

+1
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,7 @@ class IoChannelFactory {
151151
const ActorIdFactory::ActorId& id,
152152
kj::Maybe<kj::String> locationHint,
153153
ActorGetMode mode,
154+
bool enableReplicaRouting,
154155
SpanParent parentSpan) = 0;
155156

156157
// Get an actor stub from the given namespace for the actor with the given name.

Diff for: src/workerd/io/io-context.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -721,9 +721,10 @@ class IoContext final: public kj::Refcounted, private kj::TaskSet::ErrorHandler
721721
const ActorIdFactory::ActorId& id,
722722
kj::Maybe<kj::String> locationHint,
723723
ActorGetMode mode,
724+
bool enableReplicaRouting,
724725
SpanParent parentSpan) {
725726
return getIoChannelFactory().getGlobalActor(
726-
channel, id, kj::mv(locationHint), mode, kj::mv(parentSpan));
727+
channel, id, kj::mv(locationHint), mode, enableReplicaRouting, kj::mv(parentSpan));
727728
}
728729
kj::Own<IoChannelFactory::ActorChannel> getColoLocalActorChannel(
729730
uint channel, kj::StringPtr id, SpanParent parentSpan) {

Diff for: src/workerd/server/server.c++

+2
Original file line numberDiff line numberDiff line change
@@ -2205,9 +2205,11 @@ private:
22052205
const ActorIdFactory::ActorId& id,
22062206
kj::Maybe<kj::String> locationHint,
22072207
ActorGetMode mode,
2208+
bool enableReplicaRouting,
22082209
SpanParent parentSpan) override {
22092210
JSG_REQUIRE(mode == ActorGetMode::GET_OR_CREATE, Error,
22102211
"workerd only supports GET_OR_CREATE mode for getting actor stubs");
2212+
JSG_REQUIRE(!enableReplicaRouting, Error, "workerd does not support replica routing.");
22112213
auto& channels =
22122214
KJ_REQUIRE_NONNULL(ioChannels.tryGet<LinkedIoChannels>(), "link() has not been called");
22132215

Diff for: src/workerd/tests/test-fixture.c++

+1
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ struct DummyIoChannelFactory final: public IoChannelFactory {
9999
const ActorIdFactory::ActorId& id,
100100
kj::Maybe<kj::String> locationHint,
101101
ActorGetMode mode,
102+
bool enableReplicaRouting,
102103
SpanParent parentSpan) override {
103104
KJ_FAIL_REQUIRE("no actor channels");
104105
}

0 commit comments

Comments
 (0)