Skip to content

Commit

Permalink
Added counters for local db tables loading times (#10402)
Browse files Browse the repository at this point in the history
  • Loading branch information
aavdonkin authored Oct 24, 2024
1 parent 8be2b13 commit 4d5a0f8
Show file tree
Hide file tree
Showing 14 changed files with 149 additions and 5 deletions.
17 changes: 17 additions & 0 deletions ydb/core/tx/columnshard/counters/common_data.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,21 @@ TDataOwnerSignals::TDataOwnerSignals(const TString& module, const TString dataNa
SkipEraseBytes = GetDeriviative(DataName + "/SkipErase/Bytes");
}

TLoadTimeSignals::TLoadTimer::~TLoadTimer() {
ui64 duration = (TInstant::Now() - Start).MicroSeconds();
if (Failed) {
Signals.AddFailedLoadingTime(duration);
} else {
Signals.AddLoadingTime(duration);
}
AFL_INFO(NKikimrServices::TX_COLUMNSHARD)(Name, duration);
}

void TLoadTimeSignals::TLoadTimer::AddLoadingFail() {
if (!Failed) {
Failed = true;
Signals.AddLoadingFail();
}
}

}
78 changes: 78 additions & 0 deletions ydb/core/tx/columnshard/counters/common_data.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#pragma once
#include "common/owner.h"

#include <ydb/library/actors/core/log.h>

namespace NKikimr::NColumnShard {

class TDataOwnerSignals: public TCommonCountersOwner {
Expand Down Expand Up @@ -53,4 +55,80 @@ class TDataOwnerSignals: public TCommonCountersOwner {

};

class TLoadTimeSignals;

class TLoadTimeSignals: public TCommonCountersOwner {
public:
class TLoadTimer : public TNonCopyable {
private:
const TLoadTimeSignals& Signals;
TInstant Start;
TString Name;
bool Failed = false;

public:
TLoadTimer(const TLoadTimeSignals& signals, const TString& name)
: Signals(signals)
, Name(name)
{
Start = TInstant::Now();
}

void AddLoadingFail();

~TLoadTimer();
};

private:
using TBase = TCommonCountersOwner;
NMonitoring::TDynamicCounters::TCounterPtr LoadingTimeCounter;
NMonitoring::TDynamicCounters::TCounterPtr FailedLoadingTimeCounter;
NMonitoring::TDynamicCounters::TCounterPtr LoadingFailCounter;
TString Type;

public:
TLoadTimeSignals(const TString& type)
: TBase("Startup")
, Type(type)
{
LoadingTimeCounter = TBase::GetValue("Startup/" + type + "LoadingTime");
FailedLoadingTimeCounter = TBase::GetValue("Startup/" + type + "FailedLoadingTime");
LoadingFailCounter = TBase::GetValue("Startup/" + type + "LoadingFailCount");
}

TLoadTimer StartGuard() const {
return TLoadTimer(*this, Type + "LoadingTime");
}

private:
void AddLoadingTime(ui64 microSeconds) const {
LoadingTimeCounter->Add(microSeconds);
}

void AddFailedLoadingTime(ui64 microSeconds) const {
FailedLoadingTimeCounter->Add(microSeconds);
}

void AddLoadingFail() const {
LoadingFailCounter->Add(1);
}
};

class TTableLoadTimeCounters {
public:
NColumnShard::TLoadTimeSignals TableLoadTimeCounters;
NColumnShard::TLoadTimeSignals SchemaPresetLoadTimeCounters;
NColumnShard::TLoadTimeSignals TableVersionsLoadTimeCounters;
NColumnShard::TLoadTimeSignals SchemaPresetVersionsLoadTimeCounters;

public:
TTableLoadTimeCounters()
: TableLoadTimeCounters("Tables")
, SchemaPresetLoadTimeCounters("SchemaPreset")
, TableVersionsLoadTimeCounters("TableVersionss")
, SchemaPresetVersionsLoadTimeCounters("SchemaPresetVersions")
{
}
};

}
3 changes: 3 additions & 0 deletions ydb/core/tx/columnshard/counters/engine_logs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ namespace NKikimr::NColumnShard {

TEngineLogsCounters::TEngineLogsCounters()
: TBase("EngineLogs")
, PortionsLoadingTimeCounters("PortionsLoading")
, ColumnsLoadingTimeCounters("ColumnsLoading")
, IndexesLoadingTimeCounters("IndexesLoading")
, GranuleDataAgent("EngineLogs")
{
const std::map<i64, TString> borders = {{0, "0"}, {512 * 1024, "512kb"}, {1024 * 1024, "1Mb"},
Expand Down
8 changes: 8 additions & 0 deletions ydb/core/tx/columnshard/counters/engine_logs.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
#pragma once

#include "common_data.h"
#include "common/owner.h"
#include "common/histogram.h"
#include <ydb/core/tx/columnshard/common/portion.h>
Expand All @@ -8,6 +10,7 @@

namespace NKikimr::NOlap {
class TPortionInfo;
class TColumnEngineForLogs;
}

namespace NKikimr::NColumnShard {
Expand Down Expand Up @@ -223,12 +226,17 @@ class TEngineLogsCounters: public TCommonCountersOwner {

NMonitoring::TDynamicCounters::TCounterPtr IndexMetadataUsageBytes;

NColumnShard::TLoadTimeSignals PortionsLoadingTimeCounters;
NColumnShard::TLoadTimeSignals ColumnsLoadingTimeCounters;
NColumnShard::TLoadTimeSignals IndexesLoadingTimeCounters;

TAgentGranuleDataCounters GranuleDataAgent;
std::vector<std::shared_ptr<TIncrementalHistogram>> BlobSizeDistribution;
std::vector<std::shared_ptr<TIncrementalHistogram>> PortionSizeDistribution;
std::vector<std::shared_ptr<TIncrementalHistogram>> PortionRecordsDistribution;

public:
friend class NKikimr::NOlap::TColumnEngineForLogs;

class TPortionsInfoGuard {
private:
Expand Down
1 change: 1 addition & 0 deletions ydb/core/tx/columnshard/counters/insert_table.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ TInsertTableCounters::TInsertTableCounters()
, Inserted("InsertTable", "Inserted")
, Committed("InsertTable", "Committed")
, Aborted("InsertTable", "Aborted")
, LoadCounters("InsertTable")
{
}

Expand Down
1 change: 1 addition & 0 deletions ydb/core/tx/columnshard/counters/insert_table.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ class TInsertTableCounters: public TCommonCountersOwner {
const TDataOwnerSignals Inserted;
const TDataOwnerSignals Committed;
const TDataOwnerSignals Aborted;
const TLoadTimeSignals LoadCounters;

TInsertTableCounters();

Expand Down
1 change: 1 addition & 0 deletions ydb/core/tx/columnshard/counters/ya.make
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ PEERDIR(
ydb/core/tx/columnshard/counters/aggregation
ydb/core/tx/columnshard/counters/common
ydb/core/base
ydb/library/actors/core
)

GENERATE_ENUM_SERIALIZATION(columnshard.h)
Expand Down
1 change: 1 addition & 0 deletions ydb/core/tx/columnshard/engines/column_engine.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include "scheme/versions/versioned_index.h"

#include <ydb/core/tx/columnshard/common/reverse_accessor.h>
#include <ydb/core/tx/columnshard/counters/common_data.h>

namespace NKikimr::NColumnShard {
class TTiersManager;
Expand Down
8 changes: 8 additions & 0 deletions ydb/core/tx/columnshard/engines/column_engine_logs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -208,36 +208,44 @@ bool TColumnEngineForLogs::Load(IDbWrapper& db) {
bool TColumnEngineForLogs::LoadColumns(IDbWrapper& db) {
TPortionConstructors constructors;
{
NColumnShard::TLoadTimeSignals::TLoadTimer timer = SignalCounters.PortionsLoadingTimeCounters.StartGuard();
TMemoryProfileGuard g("TTxInit/LoadColumns/Portions");
if (!db.LoadPortions([&](TPortionInfoConstructor&& portion, const NKikimrTxColumnShard::TIndexPortionMeta& metaProto) {
const TIndexInfo& indexInfo = portion.GetSchema(VersionedIndex)->GetIndexInfo();
AFL_VERIFY(portion.MutableMeta().LoadMetadata(metaProto, indexInfo));
AFL_VERIFY(constructors.AddConstructorVerified(std::move(portion)));
})) {
timer.AddLoadingFail();
return false;
}
}

{
NColumnShard::TLoadTimeSignals::TLoadTimer timer = SignalCounters.ColumnsLoadingTimeCounters.StartGuard();
TMemoryProfileGuard g("TTxInit/LoadColumns/Records");
TPortionInfo::TSchemaCursor schema(VersionedIndex);
if (!db.LoadColumns([&](TPortionInfoConstructor&& portion, const TColumnChunkLoadContext& loadContext) {
auto currentSchema = schema.GetSchema(portion);
auto* constructor = constructors.MergeConstructor(std::move(portion));
constructor->LoadRecord(currentSchema->GetIndexInfo(), loadContext);
})) {
timer.AddLoadingFail();
return false;
}
}

{
NColumnShard::TLoadTimeSignals::TLoadTimeSignals::TLoadTimer timer = SignalCounters.IndexesLoadingTimeCounters.StartGuard();
TMemoryProfileGuard g("TTxInit/LoadColumns/Indexes");
if (!db.LoadIndexes([&](const ui64 pathId, const ui64 portionId, const TIndexChunkLoadContext& loadContext) {
auto* constructor = constructors.GetConstructorVerified(pathId, portionId);
constructor->LoadIndex(loadContext);
})) {
timer.AddLoadingFail();
return false;
};
}

{
TMemoryProfileGuard g("TTxInit/LoadColumns/Constructors");
for (auto&& [granuleId, pathConstructors] : constructors) {
Expand Down
1 change: 1 addition & 0 deletions ydb/core/tx/columnshard/engines/column_engine_logs.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include <ydb/core/tx/columnshard/columnshard_ttl.h>
#include <ydb/core/tx/columnshard/common/limits.h>
#include <ydb/core/tx/columnshard/common/scalars.h>
#include <ydb/core/tx/columnshard/counters/common_data.h>
#include <ydb/core/tx/columnshard/counters/engine_logs.h>

namespace NKikimr::NArrow {
Expand Down
16 changes: 12 additions & 4 deletions ydb/core/tx/columnshard/engines/insert_table/insert_table.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -124,11 +124,19 @@ bool TInsertTable::Load(NIceDb::TNiceDb& db, IDbWrapper& dbTable, const TInstant
Y_ABORT_UNLESS(!Loaded);
Loaded = true;
LastWriteId = (TInsertWriteId)0;
if (!NColumnShard::Schema::GetSpecialValueOpt(db, NColumnShard::Schema::EValueIds::LastWriteId, LastWriteId)) {
return false;
}
{
NColumnShard::TLoadTimeSignals::TLoadTimer timer = Summary.GetCounters().LoadCounters.StartGuard();
if (!NColumnShard::Schema::GetSpecialValueOpt(db, NColumnShard::Schema::EValueIds::LastWriteId, LastWriteId)) {
timer.AddLoadingFail();
return false;
}

return dbTable.Load(*this, loadTime);
if (!dbTable.Load(*this, loadTime)) {
timer.AddLoadingFail();
return false;
}
return true;
}
}

std::vector<TCommittedBlob> TInsertTable::Read(ui64 pathId, const std::optional<ui64> lockId, const TSnapshot& reqSnapshot,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

#include <ydb/core/tablet_flat/flat_cxx_database.h>
#include <ydb/core/tablet_flat/tablet_flat_executor.h>
#include <ydb/core/tx/columnshard/counters/common_data.h>
#include <ydb/core/tx/columnshard/counters/insert_table.h>

namespace NKikimr::NOlap {
Expand Down
17 changes: 16 additions & 1 deletion ydb/core/tx/columnshard/tables_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,18 @@ bool TTablesManager::FillMonitoringReport(NTabletFlatExecutor::TTransactionConte
bool TTablesManager::InitFromDB(NIceDb::TNiceDb& db) {
THashMap<ui32, TSchemaPreset> schemaPresets;
{
TLoadTimeSignals::TLoadTimer timer = LoadTimeCounters->TableLoadTimeCounters.StartGuard();
TMemoryProfileGuard g("TTablesManager/InitFromDB::Tables");
auto rowset = db.Table<Schema::TableInfo>().Select();
if (!rowset.IsReady()) {
timer.AddLoadingFail();
return false;
}

while (!rowset.EndOfSet()) {
TTableInfo table;
if (!table.InitFromDB(rowset)) {
timer.AddLoadingFail();
return false;
}
if (table.IsDropped()) {
Expand All @@ -64,16 +67,19 @@ bool TTablesManager::InitFromDB(NIceDb::TNiceDb& db) {
AFL_VERIFY(Tables.emplace(table.GetPathId(), std::move(table)).second);

if (!rowset.Next()) {
timer.AddLoadingFail();
return false;
}
}
}

bool isFakePresetOnly = true;
{
TLoadTimeSignals::TLoadTimer timer = LoadTimeCounters->SchemaPresetLoadTimeCounters.StartGuard();
TMemoryProfileGuard g("TTablesManager/InitFromDB::SchemaPresets");
auto rowset = db.Table<Schema::SchemaPresetInfo>().Select();
if (!rowset.IsReady()) {
timer.AddLoadingFail();
return false;
}

Expand All @@ -90,15 +96,18 @@ bool TTablesManager::InitFromDB(NIceDb::TNiceDb& db) {
AFL_VERIFY(schemaPresets.emplace(preset.GetId(), preset).second);
AFL_VERIFY(SchemaPresetsIds.emplace(preset.GetId()).second);
if (!rowset.Next()) {
timer.AddLoadingFail();
return false;
}
}
}

{
TLoadTimeSignals::TLoadTimer timer = LoadTimeCounters->TableVersionsLoadTimeCounters.StartGuard();
TMemoryProfileGuard g("TTablesManager/InitFromDB::Versions");
auto rowset = db.Table<Schema::TableVersionInfo>().Select();
if (!rowset.IsReady()) {
timer.AddLoadingFail();
return false;
}

Expand Down Expand Up @@ -132,15 +141,18 @@ bool TTablesManager::InitFromDB(NIceDb::TNiceDb& db) {
}
table.AddVersion(version);
if (!rowset.Next()) {
timer.AddLoadingFail();
return false;
}
}
}

{
TLoadTimeSignals::TLoadTimer timer = LoadTimeCounters->SchemaPresetVersionsLoadTimeCounters.StartGuard();
TMemoryProfileGuard g("TTablesManager/InitFromDB::PresetVersions");
auto rowset = db.Table<Schema::SchemaPresetVersionInfo>().Select();
if (!rowset.IsReady()) {
timer.AddLoadingFail();
return false;
}

Expand All @@ -156,6 +168,7 @@ bool TTablesManager::InitFromDB(NIceDb::TNiceDb& db) {
AFL_DEBUG(NKikimrServices::TX_COLUMNSHARD)("event", "load_preset")("preset_id", id)("snapshot", version)("version", info.HasSchema() ? info.GetSchema().GetVersion() : -1);
preset.AddVersion(version, info);
if (!rowset.Next()) {
timer.AddLoadingFail();
return false;
}
}
Expand Down Expand Up @@ -340,7 +353,9 @@ void TTablesManager::AddTableVersion(const ui64 pathId, const NOlap::TSnapshot&

TTablesManager::TTablesManager(const std::shared_ptr<NOlap::IStoragesManager>& storagesManager, const ui64 tabletId)
: StoragesManager(storagesManager)
, TabletId(tabletId) {
, LoadTimeCounters(std::make_unique<TTableLoadTimeCounters>())
, TabletId(tabletId)
{
}

bool TTablesManager::TryFinalizeDropPathOnExecute(NTable::TDatabase& dbTable, const ui64 pathId) const {
Expand Down
1 change: 1 addition & 0 deletions ydb/core/tx/columnshard/tables_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ class TTablesManager {
TTtl Ttl;
std::unique_ptr<NOlap::IColumnEngine> PrimaryIndex;
std::shared_ptr<NOlap::IStoragesManager> StoragesManager;
std::unique_ptr<TTableLoadTimeCounters> LoadTimeCounters;
ui64 TabletId = 0;
public:
TTablesManager(const std::shared_ptr<NOlap::IStoragesManager>& storagesManager, const ui64 tabletId);
Expand Down

0 comments on commit 4d5a0f8

Please sign in to comment.