From 89d2518b33145c66ffa16bc7e24669c547c72e9a Mon Sep 17 00:00:00 2001 From: Aleksei Borzenkov Date: Thu, 23 May 2024 09:56:39 +0000 Subject: [PATCH] Make max commit size configurable with icb --- ydb/core/protos/config.proto | 9 +++++++++ ydb/core/tablet_flat/flat_database.cpp | 16 ---------------- ydb/core/tablet_flat/flat_database.h | 1 - ydb/core/tablet_flat/flat_executor.cpp | 19 +++++++++++++------ ydb/core/tablet_flat/flat_executor.h | 1 + 5 files changed, 23 insertions(+), 23 deletions(-) diff --git a/ydb/core/protos/config.proto b/ydb/core/protos/config.proto index 17049b6f0f76..2293d861341e 100644 --- a/ydb/core/protos/config.proto +++ b/ydb/core/protos/config.proto @@ -1256,6 +1256,14 @@ message TImmediateControlsConfig { DefaultValue: 10 }]; } + message TTabletControls { + optional uint64 MaxCommitRedoMB = 1 [(ControlOptions) = { + Description: "Maximum redo size per commit in megabytes", + MinValue: 8, + MaxValue: 4096, + DefaultValue: 256 }]; + } + optional TDataShardControls DataShardControls = 1; optional TTxLimitControls TxLimitControls = 2; optional TCoordinatorControls CoordinatorControls = 3; @@ -1263,6 +1271,7 @@ message TImmediateControlsConfig { optional TTCMallocControls TCMallocControls = 5; reserved 6; optional TVDiskControls VDiskControls = 7; + optional TTabletControls TabletControls = 8; }; message TMeteringConfig { diff --git a/ydb/core/tablet_flat/flat_database.cpp b/ydb/core/tablet_flat/flat_database.cpp index e6290f1a0314..8f36d068db12 100644 --- a/ydb/core/tablet_flat/flat_database.cpp +++ b/ydb/core/tablet_flat/flat_database.cpp @@ -15,10 +15,6 @@ #include #include - -#define MAX_REDO_BYTES_PER_COMMIT 268435456U // 256MB - - namespace NKikimr { namespace NTable { @@ -672,18 +668,6 @@ size_t TDatabase::GetCommitRedoBytes() const return Redo->Bytes(); } -bool TDatabase::ValidateCommit(TString &err) -{ - if (*Redo && Redo->Bytes() > MAX_REDO_BYTES_PER_COMMIT) { - err = TStringBuilder() - << "Redo commit of " << Redo->Bytes() - << " bytes is more than the allowed limit"; - return false; - } - - return true; -} - bool TDatabase::HasChanges() const { Y_ABORT_UNLESS(Redo, "Transaction is not in progress"); diff --git a/ydb/core/tablet_flat/flat_database.h b/ydb/core/tablet_flat/flat_database.h index 0e75fedec0f9..8b22577e2c6d 100644 --- a/ydb/core/tablet_flat/flat_database.h +++ b/ydb/core/tablet_flat/flat_database.h @@ -257,7 +257,6 @@ class TDatabase { void RollUpRemoveRowVersions(ui32 table, const TRowVersion& lower, const TRowVersion& upper); size_t GetCommitRedoBytes() const; - bool ValidateCommit(TString&); TCompactionStats GetCompactionStats(ui32 table) const; diff --git a/ydb/core/tablet_flat/flat_executor.cpp b/ydb/core/tablet_flat/flat_executor.cpp index f5b4c7458fc4..0de6639b0eda 100644 --- a/ydb/core/tablet_flat/flat_executor.cpp +++ b/ydb/core/tablet_flat/flat_executor.cpp @@ -136,6 +136,7 @@ TExecutor::TExecutor( , CounterEventsInFlight(new TEvTabletCounters::TInFlightCookie) , Stats(new TExecutorStatsImpl()) , LogFlushDelayOverrideUsec(-1, -1, 60*1000*1000) + , MaxCommitRedoMB(256, 1, 4096) {} TExecutor::~TExecutor() { @@ -159,6 +160,7 @@ void TExecutor::Registered(TActorSystem *sys, const TActorId&) Memory = new TMemory(Logger.Get(), this, Emitter, Sprintf(" at tablet %" PRIu64, Owner->TabletID())); TString myTabletType = TTabletTypes::TypeToStr(Owner->TabletType()); AppData()->Icb->RegisterSharedControl(LogFlushDelayOverrideUsec, myTabletType + "_LogFlushDelayOverrideUsec"); + AppData()->Icb->RegisterSharedControl(MaxCommitRedoMB, "TabletControls.MaxCommitRedoMB"); // instantiate alert counters so even never reported alerts are created GetServiceCounters(AppData()->Counters, "tablets")->GetCounter("alerts_pending_nodata", true); @@ -1724,12 +1726,17 @@ void TExecutor::ExecuteTransaction(TAutoPtr seat, const TActorContext &ct } bool failed = false; - TString failureReason; - if (done && (failed = !Database->ValidateCommit(failureReason))) { - if (auto logl = Logger->Log(ELnLev::Crit)) { - logl - << NFmt::Do(*this) << " " << NFmt::Do(*seat) - << " fatal commit failure: " << failureReason; + if (done) { + ui64 commitRedoBytes = Database->GetCommitRedoBytes(); + ui64 maxCommitRedoBytes = ui64(MaxCommitRedoMB) << 20; // MB to bytes + if (commitRedoBytes > maxCommitRedoBytes) { + if (auto logl = Logger->Log(ELnLev::Crit)) { + logl + << NFmt::Do(*this) << " " << NFmt::Do(*seat) + << " fatal commit failure: Redo commit of " << commitRedoBytes + << " bytes is more than the allowed limit"; + } + failed = true; } } diff --git a/ydb/core/tablet_flat/flat_executor.h b/ydb/core/tablet_flat/flat_executor.h index a8feffc9ddad..47c0ede8b1e7 100644 --- a/ydb/core/tablet_flat/flat_executor.h +++ b/ydb/core/tablet_flat/flat_executor.h @@ -483,6 +483,7 @@ class TExecutor TActorContext OwnerCtx() const; TControlWrapper LogFlushDelayOverrideUsec; + TControlWrapper MaxCommitRedoMB; ui64 Stamp() const noexcept; void Registered(TActorSystem*, const TActorId&) override;