aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorlukyan <lukyan@yandex-team.com>2025-02-11 15:09:33 +0300
committerlukyan <lukyan@yandex-team.com>2025-02-11 15:31:45 +0300
commitd7d05d23126e95527238f162faf9c6487a1e9726 (patch)
tree268b85936ac704138ad204a211314aefcea98f32
parent65d919bb2e7b06ba8ce8624370d96f7daadfdc73 (diff)
downloadydb-d7d05d23126e95527238f162faf9c6487a1e9726.tar.gz
YT-24071: Fix propagating storage switch
commit_hash:3ea26303230e115d67b95f4339f1d7bed992ee70
-rw-r--r--yt/yt/core/concurrency/fiber_scheduler_thread.cpp6
-rw-r--r--yt/yt/core/tracing/trace_context.cpp50
2 files changed, 27 insertions, 29 deletions
diff --git a/yt/yt/core/concurrency/fiber_scheduler_thread.cpp b/yt/yt/core/concurrency/fiber_scheduler_thread.cpp
index 92fa3e1212..4057222ffa 100644
--- a/yt/yt/core/concurrency/fiber_scheduler_thread.cpp
+++ b/yt/yt/core/concurrency/fiber_scheduler_thread.cpp
@@ -804,7 +804,9 @@ protected:
void OnSwitch()
{
FiberId_ = SwapCurrentFiberId(FiberId_);
+ TContextSwitchManager::Get()->OnOut();
Fls_ = SwapCurrentFls(Fls_);
+ TContextSwitchManager::Get()->OnIn();
MinLogLevel_ = SwapMinLogLevel(MinLogLevel_);
}
@@ -931,8 +933,6 @@ private:
// On finish fiber running.
void OnOut()
{
- TContextSwitchManager::Get()->OnOut();
-
for (auto it = UserHandlers_.begin(); it != UserHandlers_.end(); ++it) {
if (it->Out) {
it->Out();
@@ -955,8 +955,6 @@ private:
it->In();
}
}
-
- TContextSwitchManager::Get()->OnIn();
}
};
diff --git a/yt/yt/core/tracing/trace_context.cpp b/yt/yt/core/tracing/trace_context.cpp
index e717e49e5a..01087bb158 100644
--- a/yt/yt/core/tracing/trace_context.cpp
+++ b/yt/yt/core/tracing/trace_context.cpp
@@ -155,31 +155,7 @@ TTraceContextPtr SwapTraceContext(TTraceContextPtr newContext, TSourceLocation l
return oldContext;
}
-void OnContextSwitchOut()
-{
- if (auto* context = TryGetCurrentTraceContext()) {
- auto& traceContextTimingCheckpoint = TraceContextTimingCheckpoint();
- auto now = GetApproximateCpuInstant();
- context->IncrementElapsedCpuTime(now - traceContextTimingCheckpoint);
- SetCurrentTraceContext(nullptr);
- traceContextTimingCheckpoint = 0;
- }
-}
-
-void OnContextSwitchIn()
-{
- if (auto* context = TryGetTraceContextFromPropagatingStorage(GetCurrentPropagatingStorage())) {
- SetCurrentTraceContext(context);
- TraceContextTimingCheckpoint() = GetApproximateCpuInstant();
- } else {
- SetCurrentTraceContext(nullptr);
- TraceContextTimingCheckpoint() = 0;
- }
-}
-
-void OnPropagatingStorageSwitch(
- const TPropagatingStorage& oldStorage,
- const TPropagatingStorage& newStorage)
+void OnPropagatingStorageBeforeSwitch(const TPropagatingStorage& oldStorage)
{
TCpuInstant now = 0;
auto& traceContextTimingCheckpoint = TraceContextTimingCheckpoint();
@@ -190,6 +166,12 @@ void OnPropagatingStorageSwitch(
now = GetApproximateCpuInstant();
oldContext->IncrementElapsedCpuTime(now - traceContextTimingCheckpoint);
}
+}
+
+void OnPropagatingStorageAfterSwitch(const TPropagatingStorage& newStorage)
+{
+ TCpuInstant now = 0;
+ auto& traceContextTimingCheckpoint = TraceContextTimingCheckpoint();
if (auto* newContext = TryGetTraceContextFromPropagatingStorage(newStorage)) {
SetCurrentTraceContext(newContext);
@@ -203,6 +185,24 @@ void OnPropagatingStorageSwitch(
}
}
+void OnPropagatingStorageSwitch(
+ const TPropagatingStorage& oldStorage,
+ const TPropagatingStorage& newStorage)
+{
+ OnPropagatingStorageBeforeSwitch(oldStorage);
+ OnPropagatingStorageAfterSwitch(newStorage);
+}
+
+void OnContextSwitchOut()
+{
+ OnPropagatingStorageBeforeSwitch(GetCurrentPropagatingStorage());
+}
+
+void OnContextSwitchIn()
+{
+ OnPropagatingStorageAfterSwitch(GetCurrentPropagatingStorage());
+}
+
void InitializeTraceContexts()
{
static std::once_flag Initialized;