Skip to content

Commit 903f530

Browse files
committed
Add tracing for DurableObjectStorage::getCurrentBookmark()
We’ve noticed this is slower than we expect in production, so we want to figure out why.
1 parent 5c0348a commit 903f530

File tree

5 files changed

+10
-4
lines changed

5 files changed

+10
-4
lines changed

src/workerd/api/actor-state.c++

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -839,7 +839,10 @@ jsg::Ref<SyncKvStorage> DurableObjectStorage::getKv(jsg::Lock& js) {
839839
}
840840

841841
kj::Promise<kj::String> DurableObjectStorage::getCurrentBookmark() {
842-
return cache->getCurrentBookmark();
842+
auto& context = IoContext::current();
843+
auto span = context.makeTraceSpan("durable_object_storage_getCurrentBookmark"_kjc);
844+
845+
return cache->getCurrentBookmark(span).attach(kj::mv(span));
843846
}
844847

845848
kj::Promise<kj::String> DurableObjectStorage::getBookmarkForTime(kj::Date timestamp) {

src/workerd/io/BUILD.bazel

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,7 @@ wd_cc_library(
203203
deps = [
204204
":actor-storage_capnp",
205205
":io-gate",
206+
":trace",
206207
"//src/workerd/jsg:exception",
207208
"//src/workerd/util:autogate",
208209
"//src/workerd/util:duration-exceeded-logger",

src/workerd/io/actor-cache.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#pragma once
66

77
#include <workerd/io/actor-storage.capnp.h>
8+
#include <workerd/io/trace.h>
89
#include <workerd/jsg/exception.h>
910

1011
#include <kj/async.h>
@@ -242,7 +243,7 @@ class ActorCacheInterface: public ActorCacheOps {
242243

243244
// Implements the respective PITR API calls. The default implementations throw JSG errors saying
244245
// PITR is not implemented. These methods are meant to be implemented internally.
245-
virtual kj::Promise<kj::String> getCurrentBookmark() {
246+
virtual kj::Promise<kj::String> getCurrentBookmark(SpanParent parentSpan) {
246247
JSG_FAIL_REQUIRE(
247248
Error, "This Durable Object's storage back-end does not implement point-in-time recovery.");
248249
}

src/workerd/io/actor-sqlite.c++

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -824,7 +824,7 @@ kj::Maybe<kj::Promise<void>> ActorSqlite::onNoPendingFlush() {
824824
return kj::joinPromisesFailFast(kj::arr(lastCommit.addBranch(), outputGate.wait()));
825825
}
826826

827-
kj::Promise<kj::String> ActorSqlite::getCurrentBookmark() {
827+
kj::Promise<kj::String> ActorSqlite::getCurrentBookmark(SpanParent parentSpan) {
828828
// This is an ersatz implementation that's good enough for local dev with D1's Session API.
829829
//
830830
// The returned bookmark satisfies the properties that D1 cares about:

src/workerd/io/actor-sqlite.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
#include "actor-cache.h"
88

9+
#include <workerd/io/trace.h>
910
#include <workerd/util/sqlite-kv.h>
1011
#include <workerd/util/sqlite-metadata.h>
1112

@@ -92,7 +93,7 @@ class ActorSqlite final: public ActorCacheInterface, private kj::TaskSet::ErrorH
9293
kj::Date scheduledTime, bool noCache = false, kj::StringPtr actorId = "") override;
9394
void cancelDeferredAlarmDeletion() override;
9495
kj::Maybe<kj::Promise<void>> onNoPendingFlush() override;
95-
kj::Promise<kj::String> getCurrentBookmark() override;
96+
kj::Promise<kj::String> getCurrentBookmark(SpanParent parentSpan) override;
9697
kj::Promise<void> waitForBookmark(kj::StringPtr bookmark) override;
9798
// See ActorCacheInterface
9899

0 commit comments

Comments
 (0)