forked from StarRocks/starrocks
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Enhancement] Print compaction task statistics logs for cloud native …
…table (StarRocks#37616) Signed-off-by: drake_wang <wxl250059@alibaba-inc.com>
- Loading branch information
Showing
21 changed files
with
408 additions
and
144 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
// Copyright 2021-present StarRocks, Inc. All rights reserved. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// https://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
#include "storage/lake/compaction_task_context.h" | ||
|
||
#include <rapidjson/document.h> | ||
#include <rapidjson/stringbuffer.h> | ||
#include <rapidjson/writer.h> | ||
|
||
#include "storage/olap_common.h" | ||
|
||
namespace starrocks::lake { | ||
|
||
static constexpr long TIME_UNIT_NS_PER_SECOND = 1000000000; | ||
|
||
void CompactionTaskStats::accumulate(const OlapReaderStatistics& reader_stats) { | ||
io_ns += reader_stats.io_ns; | ||
io_ns_remote += reader_stats.io_ns_remote; | ||
io_ns_local_disk += reader_stats.io_ns_local_disk; | ||
segment_init_ns += reader_stats.segment_init_ns; | ||
column_iterator_init_ns += reader_stats.column_iterator_init_ns; | ||
io_count_local_disk += reader_stats.io_count_local_disk; | ||
io_count_remote += reader_stats.io_count_remote; | ||
compressed_bytes_read += reader_stats.compressed_bytes_read; | ||
} | ||
|
||
std::string CompactionTaskStats::to_json_stats() { | ||
rapidjson::Document root; | ||
root.SetObject(); | ||
auto& allocator = root.GetAllocator(); | ||
// add stats | ||
root.AddMember("reader_total_time_second", rapidjson::Value(reader_time_ns / TIME_UNIT_NS_PER_SECOND), allocator); | ||
root.AddMember("reader_io_second", rapidjson::Value(io_ns / TIME_UNIT_NS_PER_SECOND), allocator); | ||
root.AddMember("reader_io_second_remote", rapidjson::Value(io_ns_remote / TIME_UNIT_NS_PER_SECOND), allocator); | ||
root.AddMember("reader_io_second_local_disk", rapidjson::Value(io_ns_local_disk / TIME_UNIT_NS_PER_SECOND), | ||
allocator); | ||
root.AddMember("reader_io_count_remote", rapidjson::Value(io_count_remote), allocator); | ||
root.AddMember("reader_io_count_local_disk", rapidjson::Value(io_count_local_disk), allocator); | ||
root.AddMember("compressed_bytes_read", rapidjson::Value(compressed_bytes_read), allocator); | ||
root.AddMember("segment_init_second", rapidjson::Value(segment_init_ns / TIME_UNIT_NS_PER_SECOND), allocator); | ||
root.AddMember("column_iterator_init_second", rapidjson::Value(column_iterator_init_ns / TIME_UNIT_NS_PER_SECOND), | ||
allocator); | ||
root.AddMember("segment_write_second", rapidjson::Value(segment_write_ns / TIME_UNIT_NS_PER_SECOND), allocator); | ||
|
||
rapidjson::StringBuffer strbuf; | ||
rapidjson::Writer<rapidjson::StringBuffer> writer(strbuf); | ||
root.Accept(writer); | ||
return {strbuf.GetString()}; | ||
} | ||
} // namespace starrocks::lake |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
// Copyright 2021-present StarRocks, Inc. All rights reserved. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// https://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
#pragma once | ||
|
||
#include <butil/containers/linked_list.h> | ||
|
||
#include <atomic> | ||
#include <memory> | ||
#include <string> | ||
|
||
#include "common/status.h" | ||
|
||
namespace starrocks { | ||
struct OlapReaderStatistics; | ||
} | ||
|
||
namespace starrocks::lake { | ||
|
||
class CompactionTaskCallback; | ||
class Progress { | ||
public: | ||
int value() const { return _value.load(std::memory_order_acquire); } | ||
|
||
void update(int value) { _value.store(value, std::memory_order_release); } | ||
|
||
private: | ||
std::atomic<int> _value{0}; | ||
}; | ||
|
||
struct CompactionTaskStats { | ||
int64_t io_ns = 0; | ||
int64_t io_ns_remote = 0; | ||
int64_t io_ns_local_disk = 0; | ||
int64_t segment_init_ns = 0; | ||
int64_t column_iterator_init_ns = 0; | ||
int64_t io_count_local_disk = 0; | ||
int64_t io_count_remote = 0; | ||
int64_t compressed_bytes_read = 0; | ||
int64_t reader_time_ns = 0; | ||
int64_t segment_write_ns = 0; | ||
|
||
void accumulate(const OlapReaderStatistics& reader_stats); | ||
std::string to_json_stats(); | ||
}; | ||
|
||
// Context of a single tablet compaction task. | ||
struct CompactionTaskContext : public butil::LinkNode<CompactionTaskContext> { | ||
explicit CompactionTaskContext(int64_t txn_id_, int64_t tablet_id_, int64_t version_, | ||
std::shared_ptr<CompactionTaskCallback> cb_) | ||
: txn_id(txn_id_), tablet_id(tablet_id_), version(version_), callback(std::move(cb_)) {} | ||
|
||
#ifndef NDEBUG | ||
~CompactionTaskContext() { | ||
CHECK(next() == this && previous() == this) << "Must remove CompactionTaskContext from list before destructor"; | ||
} | ||
#endif | ||
|
||
const int64_t txn_id; | ||
const int64_t tablet_id; | ||
const int64_t version; | ||
std::atomic<int64_t> start_time{0}; | ||
std::atomic<int64_t> finish_time{0}; | ||
std::atomic<bool> skipped{false}; | ||
std::atomic<int> runs{0}; | ||
Status status; | ||
Progress progress; | ||
std::shared_ptr<CompactionTaskCallback> callback; | ||
std::unique_ptr<CompactionTaskStats> stats = std::make_unique<CompactionTaskStats>(); | ||
}; | ||
|
||
} // namespace starrocks::lake |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.