Skip to content

Commit d7d05d2

Browse files
author
lukyan
committed
YT-24071: Fix propagating storage switch
commit_hash:3ea26303230e115d67b95f4339f1d7bed992ee70
1 parent 65d919b commit d7d05d2

File tree

2 files changed

+27
-29
lines changed

2 files changed

+27
-29
lines changed

yt/yt/core/concurrency/fiber_scheduler_thread.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -804,7 +804,9 @@ class TBaseSwitchHandler
804804
void OnSwitch()
805805
{
806806
FiberId_ = SwapCurrentFiberId(FiberId_);
807+
TContextSwitchManager::Get()->OnOut();
807808
Fls_ = SwapCurrentFls(Fls_);
809+
TContextSwitchManager::Get()->OnIn();
808810
MinLogLevel_ = SwapMinLogLevel(MinLogLevel_);
809811
}
810812

@@ -931,8 +933,6 @@ class TFiberSwitchHandler
931933
// On finish fiber running.
932934
void OnOut()
933935
{
934-
TContextSwitchManager::Get()->OnOut();
935-
936936
for (auto it = UserHandlers_.begin(); it != UserHandlers_.end(); ++it) {
937937
if (it->Out) {
938938
it->Out();
@@ -955,8 +955,6 @@ class TFiberSwitchHandler
955955
it->In();
956956
}
957957
}
958-
959-
TContextSwitchManager::Get()->OnIn();
960958
}
961959
};
962960

yt/yt/core/tracing/trace_context.cpp

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -155,31 +155,7 @@ TTraceContextPtr SwapTraceContext(TTraceContextPtr newContext, TSourceLocation l
155155
return oldContext;
156156
}
157157

158-
void OnContextSwitchOut()
159-
{
160-
if (auto* context = TryGetCurrentTraceContext()) {
161-
auto& traceContextTimingCheckpoint = TraceContextTimingCheckpoint();
162-
auto now = GetApproximateCpuInstant();
163-
context->IncrementElapsedCpuTime(now - traceContextTimingCheckpoint);
164-
SetCurrentTraceContext(nullptr);
165-
traceContextTimingCheckpoint = 0;
166-
}
167-
}
168-
169-
void OnContextSwitchIn()
170-
{
171-
if (auto* context = TryGetTraceContextFromPropagatingStorage(GetCurrentPropagatingStorage())) {
172-
SetCurrentTraceContext(context);
173-
TraceContextTimingCheckpoint() = GetApproximateCpuInstant();
174-
} else {
175-
SetCurrentTraceContext(nullptr);
176-
TraceContextTimingCheckpoint() = 0;
177-
}
178-
}
179-
180-
void OnPropagatingStorageSwitch(
181-
const TPropagatingStorage& oldStorage,
182-
const TPropagatingStorage& newStorage)
158+
void OnPropagatingStorageBeforeSwitch(const TPropagatingStorage& oldStorage)
183159
{
184160
TCpuInstant now = 0;
185161
auto& traceContextTimingCheckpoint = TraceContextTimingCheckpoint();
@@ -190,6 +166,12 @@ void OnPropagatingStorageSwitch(
190166
now = GetApproximateCpuInstant();
191167
oldContext->IncrementElapsedCpuTime(now - traceContextTimingCheckpoint);
192168
}
169+
}
170+
171+
void OnPropagatingStorageAfterSwitch(const TPropagatingStorage& newStorage)
172+
{
173+
TCpuInstant now = 0;
174+
auto& traceContextTimingCheckpoint = TraceContextTimingCheckpoint();
193175

194176
if (auto* newContext = TryGetTraceContextFromPropagatingStorage(newStorage)) {
195177
SetCurrentTraceContext(newContext);
@@ -203,6 +185,24 @@ void OnPropagatingStorageSwitch(
203185
}
204186
}
205187

188+
void OnPropagatingStorageSwitch(
189+
const TPropagatingStorage& oldStorage,
190+
const TPropagatingStorage& newStorage)
191+
{
192+
OnPropagatingStorageBeforeSwitch(oldStorage);
193+
OnPropagatingStorageAfterSwitch(newStorage);
194+
}
195+
196+
void OnContextSwitchOut()
197+
{
198+
OnPropagatingStorageBeforeSwitch(GetCurrentPropagatingStorage());
199+
}
200+
201+
void OnContextSwitchIn()
202+
{
203+
OnPropagatingStorageAfterSwitch(GetCurrentPropagatingStorage());
204+
}
205+
206206
void InitializeTraceContexts()
207207
{
208208
static std::once_flag Initialized;

0 commit comments

Comments
 (0)