Skip to content

Commit 4750b1c

Browse files
branch-4.1: [improve](profile) Skip _init_profile in load_v1 when enable_profile is false #61131 (#62801)
Cherry-picked from #61131 Co-authored-by: 黄瑞鑫 <[email protected]>
1 parent dee10ac commit 4750b1c

6 files changed

Lines changed: 38 additions & 10 deletions

File tree

‎be/src/cloud/cloud_tablets_channel.cpp‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,9 @@ Status CloudTabletsChannel::add_batch(const PTabletWriterAddBlockRequest& reques
4646
// FIXME(plat1ko): Too many duplicate code with `TabletsChannel`
4747
SCOPED_TIMER(_add_batch_timer);
4848
int64_t cur_seq = 0;
49-
_add_batch_number_counter->update(1);
49+
if (_add_batch_number_counter != nullptr) {
50+
_add_batch_number_counter->update(1);
51+
}
5052

5153
auto status = _get_current_seq(cur_seq, request);
5254
if (UNLIKELY(!status.ok())) {

‎be/src/load/channel/load_channel.cpp‎

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,9 @@ LoadChannel::LoadChannel(const UniqueId& load_id, int64_t timeout_s, bool is_hig
7272
// _load_channels in load_channel_mgr, or it may be erased
7373
// immediately by gc thread.
7474
_last_updated_time.store(time(nullptr));
75-
_init_profile();
75+
if (enable_profile) {
76+
_init_profile();
77+
}
7678
}
7779

7880
LoadChannel::~LoadChannel() {
@@ -88,6 +90,7 @@ LoadChannel::~LoadChannel() {
8890
}
8991

9092
void LoadChannel::_init_profile() {
93+
DCHECK(_enable_profile);
9194
_profile = std::make_unique<RuntimeProfile>("LoadChannels");
9295
_mgr_add_batch_timer = ADD_TIMER(_profile, "LoadChannelMgrAddBatchTime");
9396
_handle_mem_limit_timer = ADD_TIMER(_profile, "HandleMemLimitTime");
@@ -179,7 +182,9 @@ Status LoadChannel::add_batch(const PTabletWriterAddBlockRequest& request,
179182
DBUG_EXECUTE_IF("LoadChannel.add_batch.failed",
180183
{ return Status::InternalError("fault injection"); });
181184
SCOPED_TIMER(_add_batch_timer);
182-
COUNTER_UPDATE(_add_batch_times, 1);
185+
if (_enable_profile) {
186+
COUNTER_UPDATE(_add_batch_times, 1);
187+
}
183188
SCOPED_ATTACH_TASK(_resource_ctx);
184189
int64_t index_id = request.index_id();
185190
// 1. get tablets channel
@@ -193,7 +198,9 @@ Status LoadChannel::add_batch(const PTabletWriterAddBlockRequest& request,
193198
// 2. add block to tablets channel
194199
if (request.has_block()) {
195200
RETURN_IF_ERROR(channel->add_batch(request, response));
196-
_add_batch_number_counter->update(1);
201+
if (_enable_profile) {
202+
_add_batch_number_counter->update(1);
203+
}
197204
}
198205

199206
// 3. handle eos
@@ -204,7 +211,7 @@ Status LoadChannel::add_batch(const PTabletWriterAddBlockRequest& request,
204211
if (!st.ok()) {
205212
return st;
206213
}
207-
} else if (_add_batch_number_counter->value() % 100 == 1) {
214+
} else if (_enable_profile && _add_batch_number_counter->value() % 100 == 1) {
208215
_report_profile(response);
209216
}
210217
_last_updated_time.store(time(nullptr));
@@ -214,7 +221,9 @@ Status LoadChannel::add_batch(const PTabletWriterAddBlockRequest& request,
214221
Status LoadChannel::_handle_eos(BaseTabletsChannel* channel,
215222
const PTabletWriterAddBlockRequest& request,
216223
PTabletWriterAddBlockResult* response) {
217-
_self_profile->add_info_string("EosHost", fmt::format("{}", request.backend_id()));
224+
if (_enable_profile) {
225+
_self_profile->add_info_string("EosHost", fmt::format("{}", request.backend_id()));
226+
}
218227
bool finished = false;
219228
auto index_id = request.index_id();
220229

‎be/src/load/channel/tablets_channel.cpp‎

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,9 @@ BaseTabletsChannel::BaseTabletsChannel(const TabletsChannelKey& key, const Uniqu
6666
_closed_senders(64),
6767
_is_high_priority(is_high_priority) {
6868
static std::once_flag once_flag;
69-
_init_profile(profile);
69+
if (profile != nullptr) {
70+
_init_profile(profile);
71+
}
7072
std::call_once(once_flag, [] {
7173
REGISTER_HOOK_METRIC(tablet_writer_count, [&]() { return _s_tablet_writer_count.load(); });
7274
});
@@ -102,6 +104,7 @@ Status BaseTabletsChannel::_get_current_seq(int64_t& cur_seq,
102104
}
103105

104106
void BaseTabletsChannel::_init_profile(RuntimeProfile* profile) {
107+
DCHECK(profile != nullptr);
105108
_profile =
106109
profile->create_child(fmt::format("TabletsChannel {}", _key.to_string()), true, true);
107110
_add_batch_number_counter = ADD_COUNTER(_profile, "NumberBatchAdded", TUnit::UNIT);
@@ -122,6 +125,7 @@ void BaseTabletsChannel::_init_profile(RuntimeProfile* profile) {
122125
}
123126

124127
void TabletsChannel::_init_profile(RuntimeProfile* profile) {
128+
DCHECK(profile != nullptr);
125129
BaseTabletsChannel::_init_profile(profile);
126130
_slave_replica_timer = ADD_TIMER(_profile, "SlaveReplicaTime");
127131
}
@@ -847,7 +851,9 @@ Status TabletsChannel::add_batch(const PTabletWriterAddBlockRequest& request,
847851
PTabletWriterAddBlockResult* response) {
848852
SCOPED_TIMER(_add_batch_timer);
849853
int64_t cur_seq = 0;
850-
_add_batch_number_counter->update(1);
854+
if (_add_batch_number_counter) {
855+
_add_batch_number_counter->update(1);
856+
}
851857

852858
auto status = _get_current_seq(cur_seq, request);
853859
if (UNLIKELY(!status.ok())) {

‎be/src/load/delta_writer/delta_writer.cpp‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,9 @@ using namespace ErrorCode;
6464
BaseDeltaWriter::BaseDeltaWriter(const WriteRequest& req, RuntimeProfile* profile,
6565
const UniqueId& load_id)
6666
: _req(req), _memtable_writer(new MemTableWriter(req)) {
67-
_init_profile(profile);
67+
if (profile != nullptr) {
68+
_init_profile(profile);
69+
}
6870
}
6971

7072
DeltaWriter::DeltaWriter(StorageEngine& engine, const WriteRequest& req, RuntimeProfile* profile,
@@ -74,12 +76,14 @@ DeltaWriter::DeltaWriter(StorageEngine& engine, const WriteRequest& req, Runtime
7476
}
7577

7678
void BaseDeltaWriter::_init_profile(RuntimeProfile* profile) {
79+
DCHECK(profile != nullptr);
7780
_profile = profile->create_child(fmt::format("DeltaWriter {}", _req.tablet_id), true, true);
7881
_close_wait_timer = ADD_TIMER(_profile, "CloseWaitTime");
7982
_wait_flush_limit_timer = ADD_TIMER(_profile, "WaitFlushLimitTime");
8083
}
8184

8285
void DeltaWriter::_init_profile(RuntimeProfile* profile) {
86+
DCHECK(profile != nullptr);
8387
BaseDeltaWriter::_init_profile(profile);
8488
_commit_txn_timer = ADD_TIMER(_profile, "CommitTxnTime");
8589
}

‎be/src/load/memtable/memtable_writer.cpp‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -303,6 +303,9 @@ Status MemTableWriter::_do_close_wait() {
303303
}
304304

305305
void MemTableWriter::_update_profile(RuntimeProfile* profile) {
306+
if (!profile) {
307+
return;
308+
}
306309
// NOTE: MemTableWriter may be accessed when profile is out of scope, in MemTableMemoryLimiter.
307310
// To avoid accessing dangling pointers, we cannot make profile as a member of MemTableWriter.
308311
auto child =

‎be/src/storage/rowset_builder.cpp‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,21 +66,25 @@ using namespace ErrorCode;
6666

6767
BaseRowsetBuilder::BaseRowsetBuilder(const WriteRequest& req, RuntimeProfile* profile)
6868
: _req(req), _tablet_schema(std::make_shared<TabletSchema>()) {
69-
_init_profile(profile);
69+
if (profile != nullptr) {
70+
_init_profile(profile);
71+
}
7072
}
7173

7274
RowsetBuilder::RowsetBuilder(StorageEngine& engine, const WriteRequest& req,
7375
RuntimeProfile* profile)
7476
: BaseRowsetBuilder(req, profile), _engine(engine) {}
7577

7678
void BaseRowsetBuilder::_init_profile(RuntimeProfile* profile) {
79+
DCHECK(profile != nullptr);
7780
_profile = profile->create_child(fmt::format("RowsetBuilder {}", _req.tablet_id), true, true);
7881
_build_rowset_timer = ADD_TIMER(_profile, "BuildRowsetTime");
7982
_submit_delete_bitmap_timer = ADD_TIMER(_profile, "DeleteBitmapSubmitTime");
8083
_wait_delete_bitmap_timer = ADD_TIMER(_profile, "DeleteBitmapWaitTime");
8184
}
8285

8386
void RowsetBuilder::_init_profile(RuntimeProfile* profile) {
87+
DCHECK(profile != nullptr);
8488
BaseRowsetBuilder::_init_profile(profile);
8589
_commit_txn_timer = ADD_TIMER(_profile, "CommitTxnTime");
8690
}

0 commit comments

Comments
 (0)