@@ -208,6 +208,7 @@ void TExecutor::Broken() {
208
208
void TExecutor::RecreatePageCollectionsCache () noexcept
209
209
{
210
210
PrivatePageCache = MakeHolder<TPrivatePageCache>();
211
+ StickyPagesMemory = 0 ;
211
212
212
213
Stats->PacksMetaBytes = 0 ;
213
214
@@ -611,6 +612,10 @@ void TExecutor::AddSingleCache(const TIntrusivePtr<TPrivatePageCache::TInfo> &in
611
612
{
612
613
PrivatePageCache->RegisterPageCollection (info);
613
614
Send (MakeSharedPageCacheId (), new NSharedCache::TEvAttach (info->PageCollection , SelfId ()));
615
+
616
+ StickyPagesMemory += info->GetStickySize ();
617
+
618
+ Counters->Simple ()[TExecutorCounters::CACHE_TOTAL_STICKY] = StickyPagesMemory;
614
619
}
615
620
616
621
void TExecutor::DropCachesOfBundle (const NTable::TPart &part) noexcept
@@ -633,13 +638,20 @@ void TExecutor::DropCachesOfBundle(const NTable::TPart &part) noexcept
633
638
634
639
void TExecutor::DropSingleCache (const TLogoBlobID &label) noexcept
635
640
{
636
- auto toActivate = PrivatePageCache->ForgetPageCollection (label);
641
+ auto pageCollection = PrivatePageCache->GetPageCollection (label);
642
+
643
+ ui64 stickySize = pageCollection->GetStickySize ();
644
+ Y_ABORT_UNLESS (StickyPagesMemory >= stickySize);
645
+ StickyPagesMemory -= stickySize;
646
+
647
+ auto toActivate = PrivatePageCache->ForgetPageCollection (pageCollection);
637
648
ActivateWaitingTransactions (toActivate);
638
649
if (!PrivatePageCache->Info (label))
639
650
Send (MakeSharedPageCacheId (), new NSharedCache::TEvInvalidate (label));
640
651
641
652
Counters->Simple ()[TExecutorCounters::CACHE_PINNED_SET] = PrivatePageCache->GetStats ().PinnedSetSize ;
642
653
Counters->Simple ()[TExecutorCounters::CACHE_PINNED_LOAD] = PrivatePageCache->GetStats ().PinnedLoadSize ;
654
+ Counters->Simple ()[TExecutorCounters::CACHE_TOTAL_STICKY] = StickyPagesMemory;
643
655
}
644
656
645
657
void TExecutor::TranslateCacheTouchesToSharedCache () {
@@ -667,6 +679,28 @@ void TExecutor::RequestInMemPagesForDatabase(bool pendingOnly) {
667
679
}
668
680
}
669
681
682
+ void TExecutor::StickInMemPages (NSharedCache::TEvResult *msg) {
683
+ const auto & scheme = Scheme ();
684
+ for (auto & pr : scheme.Tables ) {
685
+ const ui32 tid = pr.first ;
686
+ auto subset = Database->Subset (tid, NTable::TEpoch::Max (), { } , { });
687
+ for (auto &partView : subset->Flatten ) {
688
+ auto partStore = partView.As <NTable::TPartStore>();
689
+ for (auto &pageCollection : partStore->PageCollections ) {
690
+ // Note: page collection search optimization seems useless
691
+ if (pageCollection->PageCollection == msg->Origin ) {
692
+ ui64 stickySizeBefore = pageCollection->GetStickySize ();
693
+ for (auto & loaded : msg->Loaded ) {
694
+ pageCollection->AddSticky (loaded.PageId , loaded.Page );
695
+ }
696
+ StickyPagesMemory += pageCollection->GetStickySize () - stickySizeBefore;
697
+ }
698
+ }
699
+ }
700
+ }
701
+ // Note: the next call of ProvideBlock will also fill pages bodies
702
+ }
703
+
670
704
TExecutorCaches TExecutor::CleanupState () {
671
705
TExecutorCaches caches;
672
706
@@ -1347,14 +1381,8 @@ void TExecutor::RequestInMemPagesForPartStore(ui32 tableId, const NTable::TPartV
1347
1381
1348
1382
if (stickyGroup) {
1349
1383
auto req = partView.As <NTable::TPartStore>()->GetPages (groupIndex);
1350
-
1351
- TPrivatePageCache::TInfo *info = PrivatePageCache->Info (req->PageCollection ->Label ());
1352
- Y_ABORT_UNLESS (info);
1353
- for (ui32 pageId : req->Pages )
1354
- PrivatePageCache->MarkSticky (pageId, info);
1355
-
1356
1384
// TODO: only request missing pages
1357
- RequestFromSharedCache (req, NBlockIO::EPriority::Bkgr, EPageCollectionRequest::CacheSync );
1385
+ RequestFromSharedCache (req, NBlockIO::EPriority::Bkgr, EPageCollectionRequest::InMemPages );
1358
1386
}
1359
1387
}
1360
1388
}
@@ -1792,13 +1820,17 @@ void TExecutor::ExecuteTransaction(TAutoPtr<TSeat> seat, const TActorContext &ct
1792
1820
}
1793
1821
1794
1822
void TExecutor::UnpinTransactionPages (TSeat &seat) {
1823
+ Y_ABORT_UNLESS (TransactionPagesMemory >= seat.MemoryTouched );
1824
+ TransactionPagesMemory -= seat.MemoryTouched ;
1825
+
1795
1826
size_t unpinnedPages = 0 ;
1796
1827
PrivatePageCache->UnpinPages (seat.Pinned , unpinnedPages);
1797
1828
seat.Pinned .clear ();
1798
1829
seat.MemoryTouched = 0 ;
1799
1830
1800
1831
Counters->Simple ()[TExecutorCounters::CACHE_PINNED_SET] = PrivatePageCache->GetStats ().PinnedSetSize ;
1801
1832
Counters->Simple ()[TExecutorCounters::CACHE_PINNED_LOAD] = PrivatePageCache->GetStats ().PinnedLoadSize ;
1833
+ Counters->Simple ()[TExecutorCounters::CACHE_TOTAL_USED] = TransactionPagesMemory;
1802
1834
}
1803
1835
1804
1836
void TExecutor::ReleaseTxData (TSeat &seat, ui64 requested, const TActorContext &ctx)
@@ -1830,12 +1862,14 @@ void TExecutor::PostponeTransaction(TAutoPtr<TSeat> seat, TPageCollectionTxEnv &
1830
1862
ui64 prevTouched = seat->MemoryTouched ;
1831
1863
1832
1864
PrivatePageCache->PinTouches (seat->Pinned , touchedPages, newPinnedPages, seat->MemoryTouched );
1865
+ TransactionPagesMemory += seat->MemoryTouched - prevTouched;
1833
1866
1834
1867
ui32 newTouchedPages = newPinnedPages;
1835
1868
ui64 newTouchedBytes = seat->MemoryTouched - prevTouched;
1836
1869
prevTouched = seat->MemoryTouched ;
1837
1870
1838
1871
PrivatePageCache->PinToLoad (seat->Pinned , newPinnedPages, seat->MemoryTouched );
1872
+ TransactionPagesMemory += seat->MemoryTouched - prevTouched;
1839
1873
1840
1874
if (seat->AttachedMemory )
1841
1875
Memory->AttachMemory (*seat);
@@ -1978,6 +2012,7 @@ void TExecutor::PostponeTransaction(TAutoPtr<TSeat> seat, TPageCollectionTxEnv &
1978
2012
1979
2013
Counters->Simple ()[TExecutorCounters::CACHE_PINNED_SET] = PrivatePageCache->GetStats ().PinnedSetSize ;
1980
2014
Counters->Simple ()[TExecutorCounters::CACHE_PINNED_LOAD] = PrivatePageCache->GetStats ().PinnedLoadSize ;
2015
+ Counters->Simple ()[TExecutorCounters::CACHE_TOTAL_USED] = TransactionPagesMemory;
1981
2016
}
1982
2017
1983
2018
void TExecutor::CommitTransactionLog (TAutoPtr<TSeat> seat, TPageCollectionTxEnv &env,
@@ -2665,20 +2700,19 @@ void TExecutor::Handle(TEvents::TEvFlushLog::TPtr &ev) {
2665
2700
}
2666
2701
2667
2702
void TExecutor::Handle (NSharedCache::TEvResult::TPtr &ev) {
2668
- const bool failed = (ev->Get ()->Status != NKikimrProto::OK);
2703
+ NSharedCache::TEvResult *msg = ev->Get ();
2704
+ const bool failed = (msg->Status != NKikimrProto::OK);
2669
2705
2670
2706
if (auto logl = Logger->Log (failed ? ELnLev::Info : ELnLev::Debug)) {
2671
2707
logl
2672
2708
<< NFmt::Do (*this ) << " got result " << NFmt::Do (*ev->Get ())
2673
2709
<< " , category " << ev->Cookie ;
2674
2710
}
2675
2711
2676
- switch (EPageCollectionRequest (ev->Cookie )) {
2712
+ switch (auto requestType = EPageCollectionRequest (ev->Cookie )) {
2677
2713
case EPageCollectionRequest::Cache:
2678
- case EPageCollectionRequest::CacheSync :
2714
+ case EPageCollectionRequest::InMemPages :
2679
2715
{
2680
- auto *msg = ev->CastAsLocal <NSharedCache::TEvResult>();
2681
-
2682
2716
TPrivatePageCache::TInfo *collectionInfo = PrivatePageCache->Info (msg->Origin ->Label ());
2683
2717
if (!collectionInfo) // collection could be outdated
2684
2718
return ;
@@ -2695,6 +2729,9 @@ void TExecutor::Handle(NSharedCache::TEvResult::TPtr &ev) {
2695
2729
return Broken ();
2696
2730
}
2697
2731
2732
+ if (requestType == EPageCollectionRequest::InMemPages) {
2733
+ StickInMemPages (msg);
2734
+ }
2698
2735
for (auto & loaded : msg->Loaded ) {
2699
2736
TPrivatePageCache::TPage::TWaitQueuePtr transactionsToActivate = PrivatePageCache->ProvideBlock (std::move (loaded), collectionInfo);
2700
2737
ActivateWaitingTransactions (transactionsToActivate);
@@ -2704,8 +2741,6 @@ void TExecutor::Handle(NSharedCache::TEvResult::TPtr &ev) {
2704
2741
2705
2742
case EPageCollectionRequest::PendingInit:
2706
2743
{
2707
- auto *msg = ev->CastAsLocal <NSharedCache::TEvResult>();
2708
-
2709
2744
const auto *pageCollection = msg->Origin .Get ();
2710
2745
TPendingPartSwitch *foundSwitch = nullptr ;
2711
2746
TPendingPartSwitch::TNewBundle *foundBundle = nullptr ;
@@ -2756,6 +2791,7 @@ void TExecutor::Handle(NSharedCache::TEvResult::TPtr &ev) {
2756
2791
return ;
2757
2792
2758
2793
default :
2794
+ Y_DEBUG_ABORT_S (" Unexpected request " << ev->Cookie );
2759
2795
break ;
2760
2796
}
2761
2797
}
@@ -3460,8 +3496,8 @@ void TExecutor::Handle(NOps::TEvResult *ops, TProdCompact *msg, bool cancelled)
3460
3496
3461
3497
CompactionLogic->UpdateLogUsage (LogicRedo->GrabLogUsage ());
3462
3498
3463
- const ui64 partSwitchCpuuS = ui64 (1000000 . * partSwitchCpuTimer.Passed ());
3464
- Counters->Percentile ()[TExecutorCounters::TX_PERCENTILE_PARTSWITCH_CPUTIME].IncrementFor (partSwitchCpuuS );
3499
+ const ui64 partSwitchCpuUs = ui64 (1000000 . * partSwitchCpuTimer.Passed ());
3500
+ Counters->Percentile ()[TExecutorCounters::TX_PERCENTILE_PARTSWITCH_CPUTIME].IncrementFor (partSwitchCpuUs );
3465
3501
3466
3502
if (msg->YellowMoveChannels || msg->YellowStopChannels ) {
3467
3503
CheckYellow (std::move (msg->YellowMoveChannels ), std::move (msg->YellowStopChannels ));
@@ -3490,13 +3526,11 @@ void TExecutor::Handle(NOps::TEvResult *ops, TProdCompact *msg, bool cancelled)
3490
3526
3491
3527
void TExecutor::UpdateUsedTabletMemory () {
3492
3528
// Estimate memory usage for internal executor structures:
3493
- UsedTabletMemory = 50 << 10 ; // 50kb
3529
+ UsedTabletMemory = 50_KB;
3494
3530
3495
- // Count the number of bytes kept in private cache (can't be offloaded right now):
3496
- if (PrivatePageCache) {
3497
- UsedTabletMemory += PrivatePageCache->GetStats ().TotalPinnedBody ;
3498
- UsedTabletMemory += PrivatePageCache->GetStats ().PinnedLoadSize ;
3499
- }
3531
+ // Count the number of bytes that can't be offloaded right now:
3532
+ UsedTabletMemory += StickyPagesMemory;
3533
+ UsedTabletMemory += TransactionPagesMemory;
3500
3534
3501
3535
// Estimate memory used by internal database structures:
3502
3536
auto &counters = Database->Counters ();
@@ -3589,8 +3623,9 @@ void TExecutor::UpdateCounters(const TActorContext &ctx) {
3589
3623
Counters->Simple ()[TExecutorCounters::CACHE_TOTAL_SHARED_BODY].Set (stats.TotalSharedBody );
3590
3624
Counters->Simple ()[TExecutorCounters::CACHE_TOTAL_PINNED_BODY].Set (stats.TotalPinnedBody );
3591
3625
Counters->Simple ()[TExecutorCounters::CACHE_TOTAL_EXCLUSIVE].Set (stats.TotalExclusive );
3592
- Counters->Simple ()[TExecutorCounters::CACHE_TOTAL_STICKY].Set (stats.TotalSticky );
3593
3626
}
3627
+ Counters->Simple ()[TExecutorCounters::CACHE_TOTAL_STICKY].Set (StickyPagesMemory);
3628
+ Counters->Simple ()[TExecutorCounters::CACHE_TOTAL_USED].Set (TransactionPagesMemory);
3594
3629
3595
3630
const auto &memory = Memory->Stats ();
3596
3631
@@ -4108,7 +4143,8 @@ void TExecutor::RenderHtmlPage(NMon::TEvRemoteHttpInfo::TPtr &ev) const {
4108
4143
DIV_CLASS (" row" ) {str << " Total bytes in shared cache: " << PrivatePageCache->GetStats ().TotalSharedBody ; }
4109
4144
DIV_CLASS (" row" ) {str << " Total bytes in local cache: " << PrivatePageCache->GetStats ().TotalPinnedBody ; }
4110
4145
DIV_CLASS (" row" ) {str << " Total bytes exclusive to local cache: " << PrivatePageCache->GetStats ().TotalExclusive ; }
4111
- DIV_CLASS (" row" ) {str << " Total bytes marked as sticky: " << PrivatePageCache->GetStats ().TotalSticky ; }
4146
+ DIV_CLASS (" row" ) {str << " Total bytes marked as sticky: " << StickyPagesMemory; }
4147
+ DIV_CLASS (" row" ) {str << " Total bytes currently in use: " << TransactionPagesMemory; }
4112
4148
4113
4149
if (GcLogic) {
4114
4150
TAG (TH3) {str << " Gc logic:" ;}
0 commit comments