Skip to content

Commit 9da3040

Browse files
jordanhunt22Convex, Inc.
authored and
Convex, Inc.
committed
Improve committer tracing (#35754)
GitOrigin-RevId: b97dc0e8ebb15674ae33420e483b67e01f46ab45
1 parent 92ccd03 commit 9da3040

File tree

1 file changed

+28
-19
lines changed

1 file changed

+28
-19
lines changed

crates/database/src/committer.rs

Lines changed: 28 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,10 @@ impl<RT: Runtime> Committer<RT> {
226226
// commit out of order and regress the repeatable timestamp.
227227
let mut next_bump_wait = Some(*MAX_REPEATABLE_TIMESTAMP_COMMIT_DELAY);
228228

229-
let mut root_span = None;
229+
// This span starts with receiving a commit message and ends with that same
230+
// commit getting published. It captures all of the committer activity
231+
// in between.
232+
let mut committer_span = None;
230233
// Keep a monotonically increasing id to keep track of honeycomb traces
231234
// Each commit_id tracks a single write to persistence, from the time the commit
232235
// message is received until the time the commit has been published. We skip
@@ -245,16 +248,17 @@ impl<RT: Runtime> Committer<RT> {
245248
};
246249
select_biased! {
247250
_ = bump_fut.fuse() => {
248-
let root_span = root_span.get_or_insert_with(|| {
251+
let committer_span = committer_span.get_or_insert_with(|| {
249252
span_commit_id = Some(commit_id);
250253
Span::root("bump_max_repeatable", SpanContext::random())
251254
});
252-
let _span = Span::enter_with_parent("queue_bump_max_repeatable", root_span);
255+
let local_span = Span::enter_with_parent("queue_bump_max_repeatable", committer_span);
256+
local_span.set_local_parent();
253257
// Advance the repeatable read timestamp so non-leaders can
254258
// establish a recent repeatable snapshot.
255259
next_bump_wait = None;
256260
let (tx, _rx) = oneshot::channel();
257-
self.bump_max_repeatable_ts(tx, commit_id, root_span);
261+
self.bump_max_repeatable_ts(tx, commit_id, committer_span);
258262
commit_id += 1;
259263
last_bumped_repeatable_ts = self.runtime.monotonic_now();
260264
}
@@ -277,9 +281,9 @@ impl<RT: Runtime> Committer<RT> {
277281
parent_trace,
278282
..
279283
} => {
280-
let _span = root_span.as_ref().map(|root| Span::enter_with_parent("publish_commit", root));
281-
let root = initialize_root_from_parent("Committer::publish_commit", parent_trace);
282-
let _guard = root.set_local_parent();
284+
let parent_span = initialize_root_from_parent("Committer::publish_commit", parent_trace);
285+
let publish_commit_span = committer_span.as_ref().map(|root| Span::enter_with_parents("publish_commit", [root, &parent_span])).unwrap_or_else(|| parent_span);
286+
let _guard = publish_commit_span.set_local_parent();
283287
let commit_ts = pending_write.must_commit_ts();
284288
self.publish_commit(pending_write);
285289
let _ = result.send(Ok(commit_ts));
@@ -297,7 +301,8 @@ impl<RT: Runtime> Committer<RT> {
297301
result,
298302
..
299303
} => {
300-
let _span = root_span.as_ref().map(|root| Span::enter_with_parent("publish_max_repeatable_ts", root));
304+
let span = committer_span.as_ref().map(|root| Span::enter_with_parent("publish_max_repeatable_ts", root)).unwrap_or_else(Span::noop);
305+
span.set_local_parent();
301306
self.publish_max_repeatable_ts(new_max_repeatable);
302307
next_bump_wait = Some(*MAX_REPEATABLE_TIMESTAMP_IDLE_FREQUENCY);
303308
let _ = result.send(new_max_repeatable);
@@ -306,7 +311,7 @@ impl<RT: Runtime> Committer<RT> {
306311
}
307312
// Report the trace if it is longer than the threshold
308313
if let Some(id) = span_commit_id && id == pending_commit_id {
309-
if let Some(mut span) = root_span.take() {
314+
if let Some(mut span) = committer_span.take() {
310315
if span.elapsed() < Some(*COMMIT_TRACE_THRESHOLD) {
311316
tracing::debug!("Not sending span to honeycomb because it is below the threshold");
312317
span.cancel();
@@ -330,30 +335,30 @@ impl<RT: Runtime> Committer<RT> {
330335
parent_trace,
331336
}) => {
332337

333-
let root_span_ref = root_span.get_or_insert_with(|| {
338+
let parent_span = initialize_root_from_parent("handle_commit_message", parent_trace.clone())
339+
.with_property(|| ("time_in_queue_ms", format!("{}", queue_timer.elapsed().as_secs_f64() * 1000.0)));
340+
let committer_span_ref = committer_span.get_or_insert_with(|| {
334341
span_commit_id = Some(commit_id);
335342
Span::root("commit", SpanContext::random())
336343
});
337-
let _span =
338-
Span::enter_with_parent("start_commit", root_span_ref);
339-
let root = initialize_root_from_parent("handle_commit_message", parent_trace.clone())
340-
.with_property(|| ("time_in_queue_ms", format!("{}", queue_timer.elapsed().as_secs_f64() * 1000.0)));
341-
let _guard = root.set_local_parent();
344+
let start_commit_span =
345+
Span::enter_with_parents("start_commit", [committer_span_ref, &parent_span]);
346+
let _guard = start_commit_span.set_local_parent();
342347
drop(queue_timer);
343348
if let Some(persistence_write_future) = self.start_commit(transaction,
344349
result,
345350
write_source,
346351
parent_trace,
347352
commit_id,
348-
root_span_ref) {
353+
committer_span_ref) {
349354
self.persistence_writes.push_back(persistence_write_future);
350355
commit_id += 1;
351356
} else if span_commit_id == Some(commit_id) {
352357
// If the span_commit_id is the same as the commit_id, that means we created a root span in this block
353358
// and it didn't get incremented, so it's not a write to persistence and we should not trace it.
354-
// We also need to reset the span_commit_id and root_span.
355-
root_span_ref.cancel();
356-
root_span = None;
359+
// We also need to reset the span_commit_id and committer_span.
360+
committer_span_ref.cancel();
361+
committer_span = None;
357362
span_commit_id = None;
358363
}
359364
},
@@ -685,6 +690,7 @@ impl<RT: Runtime> Committer<RT> {
685690
})
686691
}
687692

693+
#[fastrace::trace]
688694
fn compute_writes(
689695
&self,
690696
commit_ts: Timestamp,
@@ -730,6 +736,7 @@ impl<RT: Runtime> Committer<RT> {
730736
Ok((document_writes, index_writes, latest_pending_snapshot))
731737
}
732738

739+
#[fastrace::trace]
733740
fn commit_has_conflict(
734741
&self,
735742
reads: &ReadSet,
@@ -775,6 +782,7 @@ impl<RT: Runtime> Committer<RT> {
775782

776783
/// After writing the new rows to persistence, mark the commit as complete
777784
/// and allow the updated rows to be read by other transactions.
785+
#[fastrace::trace]
778786
fn publish_commit(&mut self, pending_write: PendingWriteHandle) {
779787
let apply_timer = metrics::commit_apply_timer();
780788
let commit_ts = pending_write.must_commit_ts();
@@ -886,6 +894,7 @@ impl<RT: Runtime> Committer<RT> {
886894
})
887895
}
888896
.in_span(outer_span)
897+
.in_span(request_span)
889898
.boxed(),
890899
)
891900
}

0 commit comments

Comments
 (0)