Skip to content

Commit bd601c1

Browse files
committed
Get rid of lambdas in logging macros
1 parent fdcdd6f commit bd601c1

File tree

4 files changed

+77
-53
lines changed

4 files changed

+77
-53
lines changed

ydb/core/tx/columnshard/columnshard.cpp

+7-11
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ namespace NKikimr::NColumnShard {
1717
void TColumnShard::CleanupActors(const TActorContext& ctx) {
1818
ctx.Send(ResourceSubscribeActor, new TEvents::TEvPoisonPill);
1919
ctx.Send(BufferizationWriteActorId, new TEvents::TEvPoisonPill);
20-
20+
2121
StoragesManager->Stop();
2222
if (Tiers) {
2323
Tiers->Stop();
@@ -307,10 +307,10 @@ void TColumnShard::ConfigureStats(const NOlap::TColumnEngineStats& indexStats, :
307307

308308
tabletStats->SetRowCount(activeIndexStats.Rows);
309309
tabletStats->SetDataSize(activeIndexStats.Bytes + TabletCounters->Simple()[COUNTER_COMMITTED_BYTES].Get());
310-
310+
311311
// TODO: we need row/dataSize counters for evicted data (managed by tablet but stored outside)
312312
//tabletStats->SetIndexSize(); // TODO: calc size of internal tables
313-
313+
314314
tabletStats->SetLastAccessTime(LastAccessTime.MilliSeconds());
315315
tabletStats->SetLastUpdateTime(lastIndexUpdate.GetPlanStep());
316316
}
@@ -361,13 +361,13 @@ void TColumnShard::FillColumnTableStats(const TActorContext& ctx, std::unique_pt
361361
auto* periodicTableStats = ev->Record.AddTables();
362362
periodicTableStats->SetDatashardId(TabletID());
363363
periodicTableStats->SetTableLocalId(tableLocalID);
364-
364+
365365
periodicTableStats->SetShardState(2); // NKikimrTxDataShard.EDatashardState.Ready
366366
periodicTableStats->SetGeneration(Executor()->Generation());
367367
periodicTableStats->SetRound(StatsReportRound++);
368368
periodicTableStats->SetNodeId(ctx.ExecutorThread.ActorSystem->NodeId);
369369
periodicTableStats->SetStartTime(StartTime().MilliSeconds());
370-
370+
371371
if (auto* resourceMetrics = Executor()->GetResourceMetrics()) {
372372
resourceMetrics->Fill(*periodicTableStats->MutableTabletMetrics());
373373
}
@@ -376,11 +376,7 @@ void TColumnShard::FillColumnTableStats(const TActorContext& ctx, std::unique_pt
376376
FillTxTableStats(tableStats);
377377
ConfigureStats(*columnStats, tableStats);
378378

379-
{
380-
// Workaround "reference to local binding declared in enclousing function" issue for clang14
381-
ui64 id = tableLocalID;
382-
LOG_S_TRACE("Add stats for table, tableLocalID=" << id);
383-
}
379+
LOG_S_TRACE("Add stats for table, tableLocalID=" << tableLocalID);
384380
}
385381
}
386382

@@ -411,7 +407,7 @@ void TColumnShard::SendPeriodicStats() {
411407

412408
FillOlapStats(ctx, ev);
413409
FillColumnTableStats(ctx, ev);
414-
410+
415411
NTabletPipe::SendData(ctx, StatsReportPipe, ev.release());
416412
}
417413

ydb/core/tx/ctor_logger.h

+37-16
Original file line numberDiff line numberDiff line change
@@ -3,31 +3,52 @@
33
#include <ydb/library/actors/core/log.h>
44
#include <ydb/library/services/services.pb.h>
55

6+
#include <optional>
7+
68
// You have to define TLogThis in local namespace to use these macros
7-
#define LOG_S_EMERG(stream) { TLogThis(*TlsActivationContext, NActors::NLog::PRI_EMERG, [&](TStringBuilder& ss){ ss << stream; }); }
8-
#define LOG_S_ALERT(stream) { TLogThis(*TlsActivationContext, NActors::NLog::PRI_ALERT, [&](TStringBuilder& ss){ ss << stream; }); }
9-
#define LOG_S_CRIT(stream) { TLogThis(*TlsActivationContext, NActors::NLog::PRI_CRIT, [&](TStringBuilder& ss){ ss << stream; }); }
10-
#define LOG_S_ERROR(stream) { TLogThis(*TlsActivationContext, NActors::NLog::PRI_ERROR, [&](TStringBuilder& ss){ ss << stream; }); }
11-
#define LOG_S_WARN(stream) { TLogThis(*TlsActivationContext, NActors::NLog::PRI_WARN, [&](TStringBuilder& ss){ ss << stream; }); }
12-
#define LOG_S_NOTICE(stream) { TLogThis(*TlsActivationContext, NActors::NLog::PRI_NOTICE, [&](TStringBuilder& ss){ ss << stream; }); }
13-
#define LOG_S_INFO(stream) { TLogThis(*TlsActivationContext, NActors::NLog::PRI_INFO, [&](TStringBuilder& ss){ ss << stream; }); }
14-
#define LOG_S_DEBUG(stream) { TLogThis(*TlsActivationContext, NActors::NLog::PRI_DEBUG, [&](TStringBuilder& ss){ ss << stream; }); }
15-
#define LOG_S_TRACE(stream) { TLogThis(*TlsActivationContext, NActors::NLog::PRI_TRACE, [&](TStringBuilder& ss){ ss << stream; }); }
9+
#define __LOG_S_PRIORITY_IMPL__(stream, priority) \
10+
if (auto logThis = TLogThis(*TlsActivationContext, priority)) { \
11+
logThis.Str() << stream; \
12+
logThis.WriteLog(); \
13+
}
14+
15+
#define LOG_S_EMERG(stream) __LOG_S_PRIORITY_IMPL__(stream, NActors::NLog::PRI_EMERG)
16+
#define LOG_S_ALERT(stream) __LOG_S_PRIORITY_IMPL__(stream, NActors::NLog::PRI_ALERT)
17+
#define LOG_S_CRIT(stream) __LOG_S_PRIORITY_IMPL__(stream, NActors::NLog::PRI_CRIT)
18+
#define LOG_S_ERROR(stream) __LOG_S_PRIORITY_IMPL__(stream, NActors::NLog::PRI_ERROR)
19+
#define LOG_S_WARN(stream) __LOG_S_PRIORITY_IMPL__(stream, NActors::NLog::PRI_WARN)
20+
#define LOG_S_NOTICE(stream) __LOG_S_PRIORITY_IMPL__(stream, NActors::NLog::PRI_NOTICE)
21+
#define LOG_S_INFO(stream) __LOG_S_PRIORITY_IMPL__(stream, NActors::NLog::PRI_INFO)
22+
#define LOG_S_DEBUG(stream) __LOG_S_PRIORITY_IMPL__(stream, NActors::NLog::PRI_DEBUG)
23+
#define LOG_S_TRACE(stream) __LOG_S_PRIORITY_IMPL__(stream, NActors::NLog::PRI_TRACE)
1624

1725
namespace NKikimr {
1826

1927
template <NKikimrServices::EServiceKikimr Component>
2028
class TCtorLogger
2129
{
30+
const NActors::TActivationContext& Ctx;
31+
NActors::NLog::EPriority Priority;
32+
std::optional<TStringBuilder> StrStream;
33+
2234
public:
23-
template <typename TFunc>
24-
TCtorLogger(const NActors::TActivationContext& ctx, NActors::NLog::EPriority priority, TFunc logFunc)
35+
TCtorLogger(const NActors::TActivationContext& ctx, NActors::NLog::EPriority priority)
36+
: Ctx(ctx)
37+
, Priority(priority)
2538
{
26-
if (IS_LOG_PRIORITY_ENABLED(priority, Component)) {
27-
TStringBuilder strStream;
28-
logFunc(strStream);
29-
::NActors::MemLogAdapter(ctx, priority, Component, "%s", strStream.data());
30-
}
39+
}
40+
41+
operator bool() const {
42+
return IS_LOG_PRIORITY_ENABLED(Priority, Component);
43+
}
44+
45+
TStringBuilder& Str() {
46+
StrStream.emplace();
47+
return *StrStream;
48+
}
49+
50+
void WriteLog() {
51+
::NActors::MemLogAdapter(Ctx, Priority, Component, std::move(*StrStream));
3152
}
3253
};
3354

ydb/library/actors/core/log.h

+27-14
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,15 @@
2525
// TODO: limit number of messages per second
2626
// TODO: make TLogComponentLevelRequest/Response network messages
2727

28-
#define IS_LOG_PRIORITY_ENABLED(priority, component) \
29-
[p = static_cast<::NActors::NLog::EPriority>(priority), c = static_cast<::NActors::NLog::EComponent>(component)]() -> bool { \
30-
::NActors::TActivationContext *context = ::NActors::TlsActivationContext; \
31-
return !context || context->LoggerSettings()->Satisfies(p, c, 0ull); \
32-
}()
28+
#define IS_LOG_PRIORITY_ENABLED(priority, component) \
29+
::NActors::IsLogPriorityEnabled(static_cast<::NActors::NLog::EPriority>(priority), \
30+
static_cast<::NActors::NLog::EComponent>(component))
31+
32+
#define IS_CTX_LOG_PRIORITY_ENABLED(actorCtxOrSystem, priority, component, sampleBy) \
33+
::NActors::IsLogPriorityEnabled(static_cast<::NActors::NLog::TSettings*>((actorCtxOrSystem).LoggerSettings()), \
34+
static_cast<::NActors::NLog::EPriority>(priority), \
35+
static_cast<::NActors::NLog::EComponent>(component), \
36+
sampleBy)
3337

3438
#define IS_EMERG_LOG_ENABLED(component) IS_LOG_PRIORITY_ENABLED(NActors::NLog::PRI_EMERG, component)
3539
#define IS_ALERT_LOG_ENABLED(component) IS_LOG_PRIORITY_ENABLED(NActors::NLog::PRI_ALERT, component)
@@ -43,21 +47,21 @@
4347

4448
#define LOG_LOG_SAMPLED_BY(actorCtxOrSystem, priority, component, sampleBy, ...) \
4549
do { \
46-
::NActors::NLog::TSettings* mSettings = static_cast<::NActors::NLog::TSettings*>((actorCtxOrSystem).LoggerSettings()); \
47-
::NActors::NLog::EPriority mPriority = static_cast<::NActors::NLog::EPriority>(priority); \
48-
::NActors::NLog::EComponent mComponent = static_cast<::NActors::NLog::EComponent>(component); \
49-
if (mSettings && mSettings->Satisfies(mPriority, mComponent, sampleBy)) { \
50+
if (IS_CTX_LOG_PRIORITY_ENABLED(actorCtxOrSystem, priority, component, sampleBy)) { \
5051
::NActors::MemLogAdapter( \
5152
actorCtxOrSystem, priority, component, __VA_ARGS__); \
5253
} \
5354
} while (0) /**/
5455

5556
#define LOG_LOG_S_SAMPLED_BY(actorCtxOrSystem, priority, component, sampleBy, stream) \
56-
LOG_LOG_SAMPLED_BY(actorCtxOrSystem, priority, component, sampleBy, [&]() -> TString { \
57-
TStringBuilder logStringBuilder; \
58-
logStringBuilder << stream; \
59-
return std::move(logStringBuilder); \
60-
}())
57+
do { \
58+
if (IS_CTX_LOG_PRIORITY_ENABLED(actorCtxOrSystem, priority, component, sampleBy)) { \
59+
TStringBuilder logStringBuilder; \
60+
logStringBuilder << stream; \
61+
::NActors::MemLogAdapter( \
62+
actorCtxOrSystem, priority, component, std::move(logStringBuilder)); \
63+
} \
64+
} while (0) /**/
6165

6266
#define LOG_LOG(actorCtxOrSystem, priority, component, ...) LOG_LOG_SAMPLED_BY(actorCtxOrSystem, priority, component, 0ull, __VA_ARGS__)
6367
#define LOG_LOG_S(actorCtxOrSystem, priority, component, stream) LOG_LOG_S_SAMPLED_BY(actorCtxOrSystem, priority, component, 0ull, stream)
@@ -327,6 +331,15 @@ namespace NActors {
327331
}
328332
} // namespace NDetail
329333

334+
inline bool IsLogPriorityEnabled(NLog::TSettings* settings, NLog::EPriority proirity, NLog::EComponent component, ui64 sampleBy = 0) {
335+
return settings && settings->Satisfies(proirity, component, sampleBy);
336+
}
337+
338+
inline bool IsLogPriorityEnabled(NLog::EPriority priority, NLog::EComponent component, ui64 sampleBy = 0) {
339+
TActivationContext* context = TlsActivationContext;
340+
return !context || IsLogPriorityEnabled(context->LoggerSettings(), priority, component, sampleBy);
341+
}
342+
330343
template <typename TCtx>
331344
inline void DeliverLogMessage(TCtx& ctx, NLog::EPriority mPriority, NLog::EComponent mComponent, TString &&str)
332345
{

ydb/library/yql/dq/actors/compute/dq_compute_actor_impl.h

+6-12
Original file line numberDiff line numberDiff line change
@@ -1572,10 +1572,9 @@ class TDqComputeActorBase : public NActors::TActorBootstrapped<TDerived>
15721572
const auto& inputDesc = Task.GetInputs(inputIndex);
15731573
Y_ABORT_UNLESS(inputDesc.HasSource());
15741574
source.Type = inputDesc.GetSource().GetType();
1575-
const ui64 i = inputIndex; // Crutch for clang
15761575
const auto& settings = Task.GetSourceSettings();
15771576
Y_ABORT_UNLESS(settings.empty() || inputIndex < settings.size());
1578-
CA_LOG_D("Create source for input " << i << " " << inputDesc);
1577+
CA_LOG_D("Create source for input " << inputIndex << " " << inputDesc);
15791578
try {
15801579
std::tie(source.AsyncInput, source.Actor) = AsyncIoFactory->CreateDqSource(
15811580
IDqAsyncIoFactory::TSourceArguments {
@@ -1607,8 +1606,7 @@ class TDqComputeActorBase : public NActors::TActorBootstrapped<TDerived>
16071606
std::tie(transform.InputBuffer, transform.Buffer) = TaskRunner->GetInputTransform(inputIndex);
16081607
Y_ABORT_UNLESS(AsyncIoFactory);
16091608
const auto& inputDesc = Task.GetInputs(inputIndex);
1610-
const ui64 i = inputIndex; // Crutch for clang
1611-
CA_LOG_D("Create transform for input " << i << " " << inputDesc.ShortDebugString());
1609+
CA_LOG_D("Create transform for input " << inputIndex << " " << inputDesc.ShortDebugString());
16121610
try {
16131611
std::tie(transform.AsyncInput, transform.Actor) = AsyncIoFactory->CreateDqInputTransform(
16141612
IDqAsyncIoFactory::TInputTransformArguments {
@@ -1644,8 +1642,7 @@ class TDqComputeActorBase : public NActors::TActorBootstrapped<TDerived>
16441642
std::tie(transform.Buffer, transform.OutputBuffer) = TaskRunner->GetOutputTransform(outputIndex);
16451643
Y_ABORT_UNLESS(AsyncIoFactory);
16461644
const auto& outputDesc = Task.GetOutputs(outputIndex);
1647-
const ui64 i = outputIndex; // Crutch for clang
1648-
CA_LOG_D("Create transform for output " << i << " " << outputDesc.ShortDebugString());
1645+
CA_LOG_D("Create transform for output " << outputIndex << " " << outputDesc.ShortDebugString());
16491646
try {
16501647
std::tie(transform.AsyncOutput, transform.Actor) = AsyncIoFactory->CreateDqOutputTransform(
16511648
IDqAsyncIoFactory::TOutputTransformArguments {
@@ -1673,8 +1670,7 @@ class TDqComputeActorBase : public NActors::TActorBootstrapped<TDerived>
16731670
const auto& outputDesc = Task.GetOutputs(outputIndex);
16741671
Y_ABORT_UNLESS(outputDesc.HasSink());
16751672
sink.Type = outputDesc.GetSink().GetType();
1676-
const ui64 i = outputIndex; // Crutch for clang
1677-
CA_LOG_D("Create sink for output " << i << " " << outputDesc);
1673+
CA_LOG_D("Create sink for output " << outputIndex << " " << outputDesc);
16781674
try {
16791675
std::tie(sink.AsyncOutput, sink.Actor) = AsyncIoFactory->CreateDqSink(
16801676
IDqAsyncIoFactory::TSinkArguments {
@@ -1829,15 +1825,13 @@ class TDqComputeActorBase : public NActors::TActorBootstrapped<TDerived>
18291825
bool AllAsyncOutputsFinished() const {
18301826
for (const auto& [outputIndex, sinkInfo] : SinksMap) {
18311827
if (!sinkInfo.FinishIsAcknowledged) {
1832-
ui64 index = outputIndex; // Crutch for logging through lambda.
1833-
CA_LOG_D("Waiting finish of sink[" << index << "]");
1828+
CA_LOG_D("Waiting finish of sink[" << outputIndex << "]");
18341829
return false;
18351830
}
18361831
}
18371832
for (const auto& [outputIndex, transformInfo] : OutputTransformsMap) {
18381833
if (!transformInfo.FinishIsAcknowledged) {
1839-
ui64 index = outputIndex; // Crutch for logging through lambda.
1840-
CA_LOG_D("Waiting finish of transform[" << index << "]");
1834+
CA_LOG_D("Waiting finish of transform[" << outputIndex << "]");
18411835
return false;
18421836
}
18431837
}

0 commit comments

Comments
 (0)