diff options
author | Ivan Nikolaev <[email protected]> | 2025-08-29 21:46:40 +0300 |
---|---|---|
committer | GitHub <[email protected]> | 2025-08-29 18:46:40 +0000 |
commit | bef2d2667d72fa0934f89bc42d3a83044eac507c (patch) | |
tree | f8faaa4c0c0cc3051f7f0e5406a186256101df37 | |
parent | e4456769bc03366fe1c30a820b962bb8447c6a42 (diff) |
SharedCache: Notify tablet about loaded pages (#23761)
-rw-r--r-- | ydb/core/tablet_flat/flat_executor.cpp | 33 | ||||
-rw-r--r-- | ydb/core/tablet_flat/flat_executor.h | 10 | ||||
-rw-r--r-- | ydb/core/tablet_flat/flat_executor_bootlogic.cpp | 4 | ||||
-rw-r--r-- | ydb/core/tablet_flat/flat_executor_ut.cpp | 59 | ||||
-rw-r--r-- | ydb/core/tablet_flat/shared_cache_events.h | 9 | ||||
-rw-r--r-- | ydb/core/tablet_flat/shared_sausagecache.cpp | 114 | ||||
-rw-r--r-- | ydb/core/tablet_flat/ut/ut_shared_sausagecache.cpp | 16 | ||||
-rw-r--r-- | ydb/core/tablet_flat/ut/ut_shared_sausagecache_actor.cpp | 69 |
8 files changed, 199 insertions, 115 deletions
diff --git a/ydb/core/tablet_flat/flat_executor.cpp b/ydb/core/tablet_flat/flat_executor.cpp index 6bb94cc9be8..f3665fcc6ae 100644 --- a/ydb/core/tablet_flat/flat_executor.cpp +++ b/ydb/core/tablet_flat/flat_executor.cpp @@ -786,7 +786,7 @@ void TExecutor::UpdateCachePagesForDatabase(bool pendingOnly) { UpdateCacheModesForPartStore(partView, cacheModes); } if (requestStickyColumns) { - RequestInMemPagesForPartStore(partView, stickyColumns); + RequestStickyPagesForPartStore(partView, stickyColumns); } } } @@ -1311,7 +1311,7 @@ bool TExecutor::PrepareExternalPart(TPendingPartSwitch &partSwitch, TPendingPart Send(MakeSharedPageCacheId(), new NSharedCache::TEvRequest( NBlockIO::EPriority::Fast, std::move(fetch.PageCollection), std::move(fetch.Pages)), - 0, ui64(ESharedCacheRequestType::PendingInit)); + 0, ui64(ERequestTypeCookie::PendingInit)); ++partSwitch.PendingLoads; return true; @@ -1476,7 +1476,7 @@ void TExecutor::UpdateCacheModesForPartStore(NTable::TPartView& partView, const } } -void TExecutor::RequestInMemPagesForPartStore(NTable::TPartView& partView, const THashSet<NTable::TTag>& stickyColumns) { +void TExecutor::RequestStickyPagesForPartStore(NTable::TPartView& partView, const THashSet<NTable::TTag>& stickyColumns) { Y_DEBUG_ABORT_UNLESS(stickyColumns); for (size_t groupIndex : xrange(partView->GroupsCount)) { @@ -1492,7 +1492,7 @@ void TExecutor::RequestInMemPagesForPartStore(NTable::TPartView& partView, const auto partStore = partView.As<NTable::TPartStore>(); Send(MakeSharedPageCacheId(), new NSharedCache::TEvRequest( NBlockIO::EPriority::Bkgr, partStore->PageCollections[groupIndex]->PageCollection, partStore->GetPages(groupIndex)), - 0, ui64(ESharedCacheRequestType::InMemPages)); + 0, ui64(ERequestTypeCookie::StickyPages)); } } } @@ -1554,7 +1554,7 @@ void TExecutor::ApplyExternalPartSwitch(TPendingPartSwitch &partSwitch) { Y_ENSURE(stage && stage->PartView, "Missing bundle result in part switch"); AddPartStorePageCollections(stage->PartView, cacheModes); if (stickyColumns) { - RequestInMemPagesForPartStore(stage->PartView, stickyColumns); + RequestStickyPagesForPartStore(stage->PartView, stickyColumns); } newParts.push_back(std::move(stage->PartView)); } @@ -2230,7 +2230,7 @@ void TExecutor::PostponeTransaction(TSeat* seat, TPageCollectionTxEnv &env, request->TraceId = waitPad->GetWaitingTraceId(); request->WaitPad = waitPad; ++waitPad->PendingRequests; - Send(MakeSharedPageCacheId(), request, 0, ui64(ESharedCacheRequestType::Transaction)); + Send(MakeSharedPageCacheId(), request, 0, ui64(ERequestTypeCookie::Transaction)); } if (auto logl = Logger->Log(ELnLev::Debug)) { @@ -3005,7 +3005,7 @@ void TExecutor::Handle(TEvents::TEvFlushLog::TPtr &ev) { void TExecutor::Handle(NSharedCache::TEvResult::TPtr &ev) { NSharedCache::TEvResult *msg = ev->Get(); const bool failed = (msg->Status != NKikimrProto::OK); - const auto requestType = ESharedCacheRequestType(ev->Cookie); + const auto requestType = ERequestTypeCookie(ev->Cookie); if (auto logl = Logger->Log(failed ? ELnLev::Info : ELnLev::Debug)) { logl @@ -3014,12 +3014,13 @@ void TExecutor::Handle(NSharedCache::TEvResult::TPtr &ev) { } switch (requestType) { - case ESharedCacheRequestType::Transaction: - case ESharedCacheRequestType::InMemPages: + case ERequestTypeCookie::Transaction: + case ERequestTypeCookie::StickyPages: + case ERequestTypeCookie::TryKeepInMemPages: { TPrivatePageCache::TPageCollection *pageCollection = PrivatePageCache->FindPageCollection(msg->PageCollection->Label()); if (!pageCollection) { - if (requestType == ESharedCacheRequestType::Transaction) { + if (requestType == ERequestTypeCookie::Transaction) { TryActivateWaitingTransaction(std::move(msg->WaitPad), std::move(msg->Pages), pageCollection); } return; @@ -3037,20 +3038,22 @@ void TExecutor::Handle(NSharedCache::TEvResult::TPtr &ev) { return Broken(); } - if (requestType == ESharedCacheRequestType::InMemPages) { + if (requestType == ERequestTypeCookie::StickyPages) { for (auto& loaded : msg->Pages) { PrivatePageCache->AddStickyPage(loaded.PageId, std::move(loaded.Page), pageCollection); } - } else { // requestType == ESharedCacheRequestType::Transaction + } else { // requestType == ERequestTypeCookie::Transaction or ERequestTypeCookie::TryKeepInMemPages for (auto& loaded : msg->Pages) { PrivatePageCache->AddPage(loaded.PageId, loaded.Page, pageCollection); } - TryActivateWaitingTransaction(std::move(msg->WaitPad), std::move(msg->Pages), pageCollection); + if (requestType == ERequestTypeCookie::Transaction) { + TryActivateWaitingTransaction(std::move(msg->WaitPad), std::move(msg->Pages), pageCollection); + } } } return; - case ESharedCacheRequestType::PendingInit: + case ERequestTypeCookie::PendingInit: { const auto *pageCollection = msg->PageCollection.Get(); TPendingPartSwitch *foundSwitch = nullptr; @@ -3102,7 +3105,7 @@ void TExecutor::Handle(NSharedCache::TEvResult::TPtr &ev) { } return; - case ESharedCacheRequestType::BootLogic: + case ERequestTypeCookie::BootLogic: // ignore outdated replies return; diff --git a/ydb/core/tablet_flat/flat_executor.h b/ydb/core/tablet_flat/flat_executor.h index 6bb922331ff..d4f0a585f75 100644 --- a/ydb/core/tablet_flat/flat_executor.h +++ b/ydb/core/tablet_flat/flat_executor.h @@ -279,14 +279,6 @@ struct TPendingPartSwitch { } }; -enum class ESharedCacheRequestType : ui64 { - Undefined = 0, - Transaction = 1, - InMemPages, - PendingInit, - BootLogic, -}; - struct TExecutorStatsImpl : public TExecutorStats { TInstant YellowLastChecked; ui64 PacksMetaBytes = 0; /* Memory occupied by NPageCollection::TMeta */ @@ -557,7 +549,7 @@ class TExecutor void UpdateCacheModesForPartStore(NTable::TPartView& partView, const THashMap<NTable::TTag, ECacheMode>& cacheModes); void UpdateCachePagesForDatabase(bool pendingOnly = false); - void RequestInMemPagesForPartStore(NTable::TPartView& partView, const THashSet<NTable::TTag>& stickyColumns); + void RequestStickyPagesForPartStore(NTable::TPartView& partView, const THashSet<NTable::TTag>& stickyColumns); THashSet<NTable::TTag> GetStickyColumns(ui32 tableId); THashMap<NTable::TTag, ECacheMode> GetCacheModes(ui32 tableId); ECacheMode GetCacheMode(const TVector<NTable::TPartScheme::TColumn>& columns, const THashMap<NTable::TTag, ECacheMode>& cacheModes); diff --git a/ydb/core/tablet_flat/flat_executor_bootlogic.cpp b/ydb/core/tablet_flat/flat_executor_bootlogic.cpp index 3667363afad..0733e4567e1 100644 --- a/ydb/core/tablet_flat/flat_executor_bootlogic.cpp +++ b/ydb/core/tablet_flat/flat_executor_bootlogic.cpp @@ -189,7 +189,7 @@ NBoot::TSpawned TExecutorBootLogic::LoadPages(NBoot::IStep *step, NTable::TLoade std::move(fetch.PageCollection), std::move(fetch.Pages), BootAttempt), - 0, (ui64)ESharedCacheRequestType::BootLogic); + 0, (ui64)ERequestTypeCookie::BootLogic); return NBoot::TSpawned(true); } @@ -271,7 +271,7 @@ TExecutorBootLogic::EOpResult TExecutorBootLogic::Receive(::NActors::IEventHandl return OpResultBroken; } else if (auto *msg = ev.CastAsLocal<NSharedCache::TEvResult>()) { - if (ESharedCacheRequestType(ev.Cookie) != ESharedCacheRequestType::BootLogic) + if (ERequestTypeCookie(ev.Cookie) != ERequestTypeCookie::BootLogic) return OpResultUnhandled; if (msg->Cookie != BootAttempt) diff --git a/ydb/core/tablet_flat/flat_executor_ut.cpp b/ydb/core/tablet_flat/flat_executor_ut.cpp index 8d990ed71ad..deae010fc24 100644 --- a/ydb/core/tablet_flat/flat_executor_ut.cpp +++ b/ydb/core/tablet_flat/flat_executor_ut.cpp @@ -6850,23 +6850,18 @@ Y_UNIT_TEST_SUITE(TFlatTableExecutor_TryKeepInMemory) { }; struct TTxCachingFamily : public ITransaction { - using ECache = NTable::NPage::ECache; using ECacheMode = NSharedCache::ECacheMode; ui32 Family; - NTable::NPage::ECache Cache; ECacheMode CacheMode; - TTxCachingFamily(ui32 family, ECache cache, ECacheMode cacheMode) + TTxCachingFamily(ui32 family, ECacheMode cacheMode) : Family(family) - , Cache(cache) , CacheMode(cacheMode) {} bool Execute(TTransactionContext &txc, const TActorContext &) override { - txc.DB.Alter() - .SetFamilyCacheMode(TRowsModel::TableId, Family, CacheMode) - .SetFamilyCache(TRowsModel::TableId, Family, Cache); + txc.DB.Alter().SetFamilyCacheMode(TRowsModel::TableId, Family, CacheMode); return true; } @@ -6935,7 +6930,7 @@ Y_UNIT_TEST_SUITE(TFlatTableExecutor_TryKeepInMemory) { auto cacheCounters = GetSharedPageCounters(env); env.SendSync(rows.MakeScheme(new TCompactionPolicy())); - env.SendSync(new NFake::TEvExecute{ new TTxCachingFamily(0, NTable::NPage::ECache::Once, ECacheMode::Regular) }); + env.SendSync(new NFake::TEvExecute{ new TTxCachingFamily(0, ECacheMode::Regular) }); // 10 history pages env.SendSync(rows.VersionTo(TRowVersion(1, 10)).RowTo(0).MakeRows(70, 950)); @@ -6971,7 +6966,7 @@ Y_UNIT_TEST_SUITE(TFlatTableExecutor_TryKeepInMemory) { auto cacheCounters = GetSharedPageCounters(env); env.SendSync(rows.MakeScheme(new TCompactionPolicy())); - env.SendSync(new NFake::TEvExecute{ new TTxCachingFamily(0, NTable::NPage::ECache::Once, ECacheMode::TryKeepInMemory) }); + env.SendSync(new NFake::TEvExecute{ new TTxCachingFamily(0, ECacheMode::TryKeepInMemory) }); // 10 history pages env.SendSync(rows.VersionTo(TRowVersion(1, 10)).RowTo(0).MakeRows(70, 950)); @@ -6993,7 +6988,7 @@ Y_UNIT_TEST_SUITE(TFlatTableExecutor_TryKeepInMemory) { // should be preloaded DoFullScan(env, failedAttempts, true); - UNIT_ASSERT_VALUES_EQUAL(failedAttempts, 20); // TODO: preload + UNIT_ASSERT_VALUES_EQUAL(failedAttempts, 0); UNIT_ASSERT_VALUES_EQUAL(cacheCounters->CacheMissPages->Val(), 4); // should be no more cache misses } @@ -7007,7 +7002,7 @@ Y_UNIT_TEST_SUITE(TFlatTableExecutor_TryKeepInMemory) { auto cacheCounters = GetSharedPageCounters(env); env.SendSync(rows.MakeScheme(new TCompactionPolicy(), true)); - env.SendSync(new NFake::TEvExecute{ new TTxCachingFamily(0, NTable::NPage::ECache::Once, ECacheMode::TryKeepInMemory) }); + env.SendSync(new NFake::TEvExecute{ new TTxCachingFamily(0, ECacheMode::TryKeepInMemory) }); // 1 historic[0] + 10 historic[1] pages env.SendSync(rows.VersionTo(TRowVersion(1, 10)).RowTo(0).MakeRows(70, 950)); @@ -7028,7 +7023,7 @@ Y_UNIT_TEST_SUITE(TFlatTableExecutor_TryKeepInMemory) { UNIT_ASSERT_VALUES_EQUAL(cacheCounters->CacheMissPages->Val(), 4); // cache misses before preloading DoFullScan(env, failedAttempts, true); - UNIT_ASSERT_VALUES_EQUAL(failedAttempts, 12); // TODO: preload, should be: 10 historic[1] pages + UNIT_ASSERT_VALUES_EQUAL(failedAttempts, 10); // 10 historic[1] pages UNIT_ASSERT_VALUES_EQUAL(cacheCounters->CacheMissPages->Val(), 14); // 10 historic[1] pages, 4 cache misses before preloading } @@ -7043,7 +7038,7 @@ Y_UNIT_TEST_SUITE(TFlatTableExecutor_TryKeepInMemory) { env.SendSync(rows.MakeScheme(new TCompactionPolicy(), true)); - env.SendSync(new NFake::TEvExecute{ new TTxCachingFamily(TRowsModel::AltFamilyId, NTable::NPage::ECache::Once, ECacheMode::TryKeepInMemory) }); + env.SendSync(new NFake::TEvExecute{ new TTxCachingFamily(TRowsModel::AltFamilyId, ECacheMode::TryKeepInMemory) }); // 1 historic[0] + 10 historic[1] pages env.SendSync(rows.VersionTo(TRowVersion(1, 10)).RowTo(0).MakeRows(70, 950)); @@ -7064,7 +7059,7 @@ Y_UNIT_TEST_SUITE(TFlatTableExecutor_TryKeepInMemory) { UNIT_ASSERT_VALUES_EQUAL(cacheCounters->CacheMissPages->Val(), 6); // cache misses before preloading DoFullScan(env, failedAttempts, true); - UNIT_ASSERT_VALUES_EQUAL(failedAttempts, 12); // TODO: preload, should be: 1 groups[0], 1 historic[0], 3 index pages are sticky + UNIT_ASSERT_VALUES_EQUAL(failedAttempts, 2); // 1 groups[0], 1 historic[0], 3 index pages are sticky UNIT_ASSERT_VALUES_EQUAL(cacheCounters->CacheMissPages->Val(), 8); // 1 groups[0], 1 historic[0], 6 cache misses before preloading, 3 index pages are sticky } @@ -7079,7 +7074,7 @@ Y_UNIT_TEST_SUITE(TFlatTableExecutor_TryKeepInMemory) { env.SendSync(rows.MakeScheme(new TCompactionPolicy(), true)); - env.SendSync(new NFake::TEvExecute{ new TTxCachingFamily(TRowsModel::AltFamilyId, NTable::NPage::ECache::Once, ECacheMode::TryKeepInMemory) }); + env.SendSync(new NFake::TEvExecute{ new TTxCachingFamily(TRowsModel::AltFamilyId, ECacheMode::TryKeepInMemory) }); // 1 historic[0] + 10 historic[1] pages env.SendSync(rows.VersionTo(TRowVersion(1, 10)).RowTo(0).MakeRows(70, 950)); @@ -7100,7 +7095,7 @@ Y_UNIT_TEST_SUITE(TFlatTableExecutor_TryKeepInMemory) { UNIT_ASSERT_VALUES_EQUAL(cacheCounters->CacheMissPages->Val(), 4); // cache misses before preloading DoFullScan(env, failedAttempts, true); - UNIT_ASSERT_VALUES_EQUAL(failedAttempts, 12); // TODO: preload, should be: index root nodes, 1 groups[0], 1 historic[0] + UNIT_ASSERT_VALUES_EQUAL(failedAttempts, 2); // index root nodes, 1 groups[0], 1 historic[0] UNIT_ASSERT_VALUES_EQUAL(cacheCounters->CacheMissPages->Val(), 6); // 1 groups[0], 1 historic[0], 4 cache misses before preloading, should be index root nodes? } @@ -7114,8 +7109,8 @@ Y_UNIT_TEST_SUITE(TFlatTableExecutor_TryKeepInMemory) { auto cacheCounters = GetSharedPageCounters(env); env.SendSync(rows.MakeScheme(new TCompactionPolicy(), true)); - env.SendSync(new NFake::TEvExecute{ new TTxCachingFamily(0, NTable::NPage::ECache::Once, ECacheMode::TryKeepInMemory) }); - env.SendSync(new NFake::TEvExecute{ new TTxCachingFamily(TRowsModel::AltFamilyId, NTable::NPage::ECache::Once, ECacheMode::TryKeepInMemory) }); + env.SendSync(new NFake::TEvExecute{ new TTxCachingFamily(0, ECacheMode::TryKeepInMemory) }); + env.SendSync(new NFake::TEvExecute{ new TTxCachingFamily(TRowsModel::AltFamilyId, ECacheMode::TryKeepInMemory) }); // 1 historic[0] + 10 historic[1] pages env.SendSync(rows.VersionTo(TRowVersion(1, 10)).RowTo(0).MakeRows(70, 950)); @@ -7137,7 +7132,7 @@ Y_UNIT_TEST_SUITE(TFlatTableExecutor_TryKeepInMemory) { // should have the same behaviour DoFullScan(env, failedAttempts, true); - UNIT_ASSERT_VALUES_EQUAL(failedAttempts, 12); // TODO: preload, should be 0 + UNIT_ASSERT_VALUES_EQUAL(failedAttempts, 0); UNIT_ASSERT_VALUES_EQUAL(cacheCounters->CacheMissPages->Val(), 4); // should be no more cache misses } @@ -7163,8 +7158,8 @@ Y_UNIT_TEST_SUITE(TFlatTableExecutor_TryKeepInMemory) { // add family, old parts won't have it env.SendSync(new NFake::TEvExecute{ new TTxAddFamily() }); - env.SendSync(new NFake::TEvExecute{ new TTxCachingFamily(0, NTable::NPage::ECache::Once, ECacheMode::TryKeepInMemory) }); - env.SendSync(new NFake::TEvExecute{ new TTxCachingFamily(TRowsModel::AltFamilyId, NTable::NPage::ECache::Once, ECacheMode::TryKeepInMemory) }); + env.SendSync(new NFake::TEvExecute{ new TTxCachingFamily(0, ECacheMode::TryKeepInMemory) }); + env.SendSync(new NFake::TEvExecute{ new TTxCachingFamily(TRowsModel::AltFamilyId, ECacheMode::TryKeepInMemory) }); int failedAttempts = 0; DoFullScan(env, failedAttempts); @@ -7176,7 +7171,7 @@ Y_UNIT_TEST_SUITE(TFlatTableExecutor_TryKeepInMemory) { UNIT_ASSERT_VALUES_EQUAL(cacheCounters->CacheMissPages->Val(), 4); // cache misses before preloading DoFullScan(env, failedAttempts, true); - UNIT_ASSERT_VALUES_EQUAL(failedAttempts, 20); // TODO: preload, should be 0 + UNIT_ASSERT_VALUES_EQUAL(failedAttempts, 0); // 4 cache misses before preloading, all old and new colums in try-keep-in-memory family sould be preloaded UNIT_ASSERT_VALUES_EQUAL(cacheCounters->CacheMissPages->Val(), 4); } @@ -7203,7 +7198,7 @@ Y_UNIT_TEST_SUITE(TFlatTableExecutor_TryKeepInMemory) { // add family, old parts won't have it env.SendSync(new NFake::TEvExecute{ new TTxAddFamily() }); - env.SendSync(new NFake::TEvExecute{ new TTxCachingFamily(0, NTable::NPage::ECache::Once, ECacheMode::TryKeepInMemory) }); + env.SendSync(new NFake::TEvExecute{ new TTxCachingFamily(0, ECacheMode::TryKeepInMemory) }); int failedAttempts = 0; DoFullScan(env, failedAttempts); @@ -7215,7 +7210,7 @@ Y_UNIT_TEST_SUITE(TFlatTableExecutor_TryKeepInMemory) { UNIT_ASSERT_VALUES_EQUAL(cacheCounters->CacheMissPages->Val(), 4); // cache misses before preloading DoFullScan(env, failedAttempts, true); - UNIT_ASSERT_VALUES_EQUAL(failedAttempts, 20); // TODO: preload, should be 0 + UNIT_ASSERT_VALUES_EQUAL(failedAttempts, 0); // 4 cache misses before preloading, if at least one family of a group is for memory load it UNIT_ASSERT_VALUES_EQUAL(cacheCounters->CacheMissPages->Val(), 4); } @@ -7230,8 +7225,8 @@ Y_UNIT_TEST_SUITE(TFlatTableExecutor_TryKeepInMemory) { auto cacheCounters = GetSharedPageCounters(env); env.SendSync(rows.MakeScheme(new TCompactionPolicy(), true)); - env.SendSync(new NFake::TEvExecute{ new TTxCachingFamily(0, NTable::NPage::ECache::Once, ECacheMode::TryKeepInMemory) }); - env.SendSync(new NFake::TEvExecute{ new TTxCachingFamily(TRowsModel::AltFamilyId, NTable::NPage::ECache::Once, ECacheMode::TryKeepInMemory) }); + env.SendSync(new NFake::TEvExecute{ new TTxCachingFamily(0, ECacheMode::TryKeepInMemory) }); + env.SendSync(new NFake::TEvExecute{ new TTxCachingFamily(TRowsModel::AltFamilyId, ECacheMode::TryKeepInMemory) }); // 1 historic[0] + 10 historic[1] pages env.SendSync(rows.VersionTo(TRowVersion(1, 10)).RowTo(0).MakeRows(70, 950)); @@ -7243,8 +7238,8 @@ Y_UNIT_TEST_SUITE(TFlatTableExecutor_TryKeepInMemory) { env.WaitFor<NFake::TEvCompacted>(); // Disable TryKeepInMemory mode - env.SendSync(new NFake::TEvExecute{ new TTxCachingFamily(0, NTable::NPage::ECache::Once, ECacheMode::Regular) }); - env.SendSync(new NFake::TEvExecute{ new TTxCachingFamily(TRowsModel::AltFamilyId, NTable::NPage::ECache::Once, ECacheMode::Regular) }); + env.SendSync(new NFake::TEvExecute{ new TTxCachingFamily(0, ECacheMode::Regular) }); + env.SendSync(new NFake::TEvExecute{ new TTxCachingFamily(TRowsModel::AltFamilyId, ECacheMode::Regular) }); int failedAttempts = 0; DoFullScan(env, failedAttempts); @@ -7271,8 +7266,8 @@ Y_UNIT_TEST_SUITE(TFlatTableExecutor_TryKeepInMemory) { auto cacheCounters = GetSharedPageCounters(env); env.SendSync(rows.MakeScheme(new TCompactionPolicy(), true)); - env.SendSync(new NFake::TEvExecute{ new TTxCachingFamily(0, NTable::NPage::ECache::Once, ECacheMode::TryKeepInMemory) }); - env.SendSync(new NFake::TEvExecute{ new TTxCachingFamily(TRowsModel::AltFamilyId, NTable::NPage::ECache::Once, ECacheMode::TryKeepInMemory) }); + env.SendSync(new NFake::TEvExecute{ new TTxCachingFamily(0, ECacheMode::TryKeepInMemory) }); + env.SendSync(new NFake::TEvExecute{ new TTxCachingFamily(TRowsModel::AltFamilyId, ECacheMode::TryKeepInMemory) }); // 1 historic[0] + 10 historic[1] pages env.SendSync(rows.VersionTo(TRowVersion(1, 10)).RowTo(0).MakeRows(70, 950)); @@ -7284,7 +7279,7 @@ Y_UNIT_TEST_SUITE(TFlatTableExecutor_TryKeepInMemory) { env.WaitFor<NFake::TEvCompacted>(); // Disable TryKeepInMemory mode only in default family - env.SendSync(new NFake::TEvExecute{ new TTxCachingFamily(0, NTable::NPage::ECache::Once, ECacheMode::Regular) }); + env.SendSync(new NFake::TEvExecute{ new TTxCachingFamily(0, ECacheMode::Regular) }); int failedAttempts = 0; DoFullScan(env, failedAttempts); @@ -7297,7 +7292,7 @@ Y_UNIT_TEST_SUITE(TFlatTableExecutor_TryKeepInMemory) { // should not be preloaded DoFullScan(env, failedAttempts, true); - UNIT_ASSERT_VALUES_EQUAL(failedAttempts, 12); // TODO: preload, should be 6 + UNIT_ASSERT_VALUES_EQUAL(failedAttempts, 2); // 1 groups[0], 1 historic[0] UNIT_ASSERT_VALUES_EQUAL(cacheCounters->CacheMissPages->Val(), 6); // 1 groups[0], 1 historic[0], 4 cache misses before preloading } } diff --git a/ydb/core/tablet_flat/shared_cache_events.h b/ydb/core/tablet_flat/shared_cache_events.h index 8e18c17afc2..422fb2c2145 100644 --- a/ydb/core/tablet_flat/shared_cache_events.h +++ b/ydb/core/tablet_flat/shared_cache_events.h @@ -37,6 +37,15 @@ namespace NKikimr::NSharedCache { /* +1024 range is reserved for scan events */ }; + enum class ERequestTypeCookie : ui64 { + Undefined = 0, + Transaction = 1, + StickyPages, + PendingInit, + BootLogic, + TryKeepInMemPages, + }; + static_assert(EvEnd < EventSpaceEnd(TKikimrEvents::ES_FLAT_EXECUTOR), ""); struct TEvUnregister : public TEventLocal<TEvUnregister, EvUnregister> { diff --git a/ydb/core/tablet_flat/shared_sausagecache.cpp b/ydb/core/tablet_flat/shared_sausagecache.cpp index 3e541d5beb8..674d7bc6ce8 100644 --- a/ydb/core/tablet_flat/shared_sausagecache.cpp +++ b/ydb/core/tablet_flat/shared_sausagecache.cpp @@ -113,7 +113,20 @@ struct TPageTraits { } }; +enum class EBlockIOFetchTypeCookie { + NoQueue = 1, + AsyncQueue = 2, + ScanQueue = 3, + TryKeepInMemoryPreload = 4, +}; + struct TRequestQueue { + explicit TRequestQueue(EBlockIOFetchTypeCookie cookie) + : Cookie(cookie) + {} + + EBlockIOFetchTypeCookie Cookie; + TMap<TActorId, TDeque<TIntrusivePtr<TRequest>>> Requests; ui64 Limit = 0; @@ -134,10 +147,6 @@ static bool DoTraceLog() { class TSharedPageCache : public TActorBootstrapped<TSharedPageCache> { using ELnLev = NUtil::ELnLev; - static const ui64 NO_QUEUE_COOKIE = 1; - static const ui64 ASYNC_QUEUE_COOKIE = 2; - static const ui64 SCAN_QUEUE_COOKIE = 3; - TActorId Owner; TIntrusivePtr<NMemory::IMemoryConsumer> MemoryConsumer; NSharedCache::TSharedCachePages* SharedCachePages; @@ -146,8 +155,8 @@ class TSharedPageCache : public TActorBootstrapped<TSharedPageCache> { THashMap<TLogoBlobID, TCollection> Collections; THashMap<TActorId, THashMap<TCollection*, TIntrusiveList<TRequest>>> Owners; - TRequestQueue AsyncRequests; - TRequestQueue ScanRequests; + TRequestQueue AsyncRequests{EBlockIOFetchTypeCookie::AsyncQueue}; + TRequestQueue ScanRequests{EBlockIOFetchTypeCookie::ScanQueue}; TTieredCache<TPage, TPageTraits> Cache; @@ -469,7 +478,7 @@ class TSharedPageCache : public TActorBootstrapped<TSharedPageCache> { if (queue) { RequestFromQueue(*queue); } else { - SendRequest(*request, std::move(pagesToRequest), pagesToRequestBytes, nullptr); + SendRequest(*request, std::move(pagesToRequest), pagesToRequestBytes, EBlockIOFetchTypeCookie::NoQueue); } } } else { @@ -542,7 +551,7 @@ class TSharedPageCache : public TActorBootstrapped<TSharedPageCache> { << (&queue == &AsyncRequests ? " async" : " scan") << " queue" << " pages " << toLoad); - SendRequest(request, std::move(toLoad), sizeToLoad, &queue); + SendRequest(request, std::move(toLoad), sizeToLoad, queue.Cookie); } } @@ -704,13 +713,19 @@ class TSharedPageCache : public TActorBootstrapped<TSharedPageCache> { RemoveInFlyPages(msg->Pages.size(), msg->Cookie); + auto fetchType = static_cast<EBlockIOFetchTypeCookie>(ev->Cookie); TRequestQueue *queue = nullptr; - if (ev->Cookie == ASYNC_QUEUE_COOKIE) { - queue = &AsyncRequests; - } else if (ev->Cookie == SCAN_QUEUE_COOKIE) { - queue = &ScanRequests; - } else { - Y_ENSURE(ev->Cookie == NO_QUEUE_COOKIE); + switch (fetchType) { + case EBlockIOFetchTypeCookie::NoQueue: + break; + case EBlockIOFetchTypeCookie::AsyncQueue: + queue = &AsyncRequests; + break; + case EBlockIOFetchTypeCookie::ScanQueue: + queue = &ScanRequests; + break; + case EBlockIOFetchTypeCookie::TryKeepInMemoryPreload: + break; } if (queue) { Y_ENSURE(queue->InFly >= msg->Cookie); @@ -728,6 +743,8 @@ class TSharedPageCache : public TActorBootstrapped<TSharedPageCache> { if (msg->Status != NKikimrProto::OK) { DropCollection(*collection, msg->Status); } else { + bool needNotifyOwners = fetchType == EBlockIOFetchTypeCookie::TryKeepInMemoryPreload && collection->InMemoryOwners; + auto loadedPages = needNotifyOwners ? TVector<TPage*>(::Reserve(msg->Pages.size())) : TVector<TPage*>(); for (auto &paged : msg->Pages) { Y_ENSURE(paged.PageId < collection->PageMap.size()); auto* page = collection->PageMap[paged.PageId].Get(); @@ -737,6 +754,15 @@ class TSharedPageCache : public TActorBootstrapped<TSharedPageCache> { page->ProvideBody(std::move(paged.Data)); BodyProvided(*collection, page); + if (needNotifyOwners) { + loadedPages.push_back(page); + } + } + + if (loadedPages) { + for (const auto& owner : collection->InMemoryOwners) { + NotifyOwners(msg->PageCollection, loadedPages, owner); + } } } @@ -958,26 +984,35 @@ class TSharedPageCache : public TActorBootstrapped<TSharedPageCache> { request.MarkResponded(); } - void SendRequest(TRequest& request, TVector<TPageId>&& pages, ui64 bytes, TRequestQueue *queue) { - AddInFlyPages(pages.size(), bytes); + void NotifyOwners(TIntrusiveConstPtr<NPageCollection::IPageCollection> pageCollection, const TVector<TPage*>& readyPages, const TActorId& owner) { + TVector<TEvResult::TLoaded> readyLoadedPages; - auto queueCookie = NO_QUEUE_COOKIE; - if (queue) { - queueCookie = queue == &AsyncRequests - ? ASYNC_QUEUE_COOKIE - : SCAN_QUEUE_COOKIE; + for (auto* page : readyPages) { + if (page->State == PageStateLoaded) { // page may be evicted before NotifyOwners call + readyLoadedPages.emplace_back(page->PageId, TSharedPageRef::MakeUsed(page, SharedCachePages->GCList)); + } } + if (readyLoadedPages) { + TAutoPtr<NSharedCache::TEvResult> result = new NSharedCache::TEvResult(std::move(pageCollection), NKikimrProto::OK, 0); + result->Pages = std::move(readyLoadedPages); + Send(owner, result.Release(), 0, static_cast<ui64>(ERequestTypeCookie::TryKeepInMemPages)); + } + } + + void SendRequest(TRequest& request, TVector<TPageId>&& pages, ui64 bytes, EBlockIOFetchTypeCookie cookie) { + AddInFlyPages(pages.size(), bytes); + // fetch cookie -> requested size // event cookie -> queue type auto *fetch = new NBlockIO::TEvFetch(request.Priority, request.PageCollection, std::move(pages), bytes); - if (queue) { + if (cookie == EBlockIOFetchTypeCookie::AsyncQueue || cookie == EBlockIOFetchTypeCookie::ScanQueue) { // Note: queued requests can fetch multiple times, so copy trace id fetch->TraceId = request.TraceId.GetTraceId(); } else { fetch->TraceId = std::move(request.TraceId); } - NBlockIO::Start(this, request.Sender, queueCookie, fetch); + NBlockIO::Start(this, request.Sender, static_cast<ui64>(cookie), fetch); } void DropCollection(TCollection &collection, NKikimrProto::EReplyStatus blobStorageError) { @@ -1064,34 +1099,49 @@ class TSharedPageCache : public TActorBootstrapped<TSharedPageCache> { if (!collection.InMemoryOwners.insert(owner).second) { return; } - if (collection.InMemoryOwners.size() > 1) { - return; + + if (collection.InMemoryOwners.size() == 1) { + LOG_DEBUG_S(*TlsActivationContext, NKikimrServices::TABLET_SAUSAGECACHE, "Change mode of page collection " << collection.Id + << " to " << ECacheMode::TryKeepInMemory); + TryKeepInMemoryBytes += collection.TotalSize; + Counters.TryKeepInMemoryBytes->Set(TryKeepInMemoryBytes); + ActualizeCacheSizeLimit(); } - LOG_DEBUG_S(*TlsActivationContext, NKikimrServices::TABLET_SAUSAGECACHE, "Change mode of page collection " << collection.Id - << " to " << ECacheMode::TryKeepInMemory); - TryKeepInMemoryBytes += collection.TotalSize; - Counters.TryKeepInMemoryBytes->Set(TryKeepInMemoryBytes); - ActualizeCacheSizeLimit(); // TODO: pages async and batched and re-request when evicted TVector<TPageId> pagesToRequest(::Reserve(pageCollection->Total())); + TVector<TPage*> loadedPages; ui64 pagesToRequestBytes = 0; + ui64 remainBytes = Cache.GetLimit(); for (const auto& pageId : xrange(pageCollection->Total())) { auto* page = EnsurePage(*pageCollection, collection, pageId, ECacheMode::TryKeepInMemory); TryChangeCacheMode(page, ECacheMode::TryKeepInMemory); switch (page->State) { + case PageStateLoaded: + loadedPages.push_back(page); + break; case PageStateEvicted: ReloadEvictedPage(page); + loadedPages.push_back(page); break; case PageStateNo: + // Prevent loading out-of-memory pages. TODO: Load the remaining pages when there is enough memory available. + if (TPageTraits::GetSize(page) > remainBytes) { + collection.PageMap.erase(pageId); + continue; + } + remainBytes -= TPageTraits::GetSize(page); page->State = PageStateRequestedAsync; pagesToRequest.push_back(pageId); pagesToRequestBytes += page->Size; - break; } } + if (loadedPages) { + NotifyOwners(pageCollection, loadedPages, owner); + } + if (pagesToRequest) { TRequest request; request.PageCollection = std::move(pageCollection); @@ -1104,7 +1154,7 @@ class TSharedPageCache : public TActorBootstrapped<TSharedPageCache> { << " pages " << pagesToRequest); // TODO: add some counters for these fetches? - SendRequest(request, std::move(pagesToRequest), pagesToRequestBytes, nullptr); + SendRequest(request, std::move(pagesToRequest), pagesToRequestBytes, EBlockIOFetchTypeCookie::TryKeepInMemoryPreload); } } diff --git a/ydb/core/tablet_flat/ut/ut_shared_sausagecache.cpp b/ydb/core/tablet_flat/ut/ut_shared_sausagecache.cpp index 5ea63beb97e..462fc8c698a 100644 --- a/ydb/core/tablet_flat/ut/ut_shared_sausagecache.cpp +++ b/ydb/core/tablet_flat/ut/ut_shared_sausagecache.cpp @@ -988,19 +988,19 @@ Y_UNIT_TEST(TryKeepInMemoryMode_Basics) { UNIT_ASSERT_VALUES_EQUAL(counters->CacheMissPages->Val(), 232); UNIT_ASSERT_DOUBLES_EQUAL(counters->TryKeepInMemoryBytes->Val(), static_cast<i64>(10_MB), static_cast<i64>(1_MB / 3)); - // read from in-memory table, should be no more cache misses + // read from in-memory table, should be no more cache misses and all read should be from private cache (no more CacheHit*) retried = {}; for (i64 key = 99; key >= 0; --key) { env.SendSync(new NFake::TEvExecute{ new TTxReadRows(TableId, key, retried) }, true); } LogCounters(counters); - UNIT_ASSERT_VALUES_EQUAL(retried, (TVector<ui32>{100, 100, 14, 2})); + UNIT_ASSERT_VALUES_EQUAL(retried, (TVector<ui32>{100})); UNIT_ASSERT_DOUBLES_EQUAL(counters->ActiveBytes->Val(), static_cast<i64>(10_MB), static_cast<i64>(1_MB / 3)); UNIT_ASSERT_VALUES_EQUAL(counters->ActivePages->Val(), 138); UNIT_ASSERT_DOUBLES_EQUAL(counters->PassiveBytes->Val(), static_cast<i64>(0_MB), static_cast<i64>(1_MB / 3)); UNIT_ASSERT_VALUES_EQUAL(counters->PassivePages->Val(), 1); - UNIT_ASSERT_DOUBLES_EQUAL(counters->CacheHitBytes->Val(), static_cast<i64>(10_MB), static_cast<i64>(1_MB / 3)); - UNIT_ASSERT_VALUES_EQUAL(counters->CacheHitPages->Val(), 116); + UNIT_ASSERT_DOUBLES_EQUAL(counters->CacheHitBytes->Val(), static_cast<i64>(0_MB), static_cast<i64>(1_MB / 3)); + UNIT_ASSERT_VALUES_EQUAL(counters->CacheHitPages->Val(), 0); UNIT_ASSERT_DOUBLES_EQUAL(counters->CacheMissBytes->Val(), static_cast<i64>(20'000_KB), static_cast<i64>(1_MB / 3)); UNIT_ASSERT_VALUES_EQUAL(counters->CacheMissPages->Val(), 232); UNIT_ASSERT_DOUBLES_EQUAL(counters->TryKeepInMemoryBytes->Val(), static_cast<i64>(10_MB), static_cast<i64>(1_MB / 3)); @@ -1105,19 +1105,19 @@ Y_UNIT_TEST(TryKeepInMemoryMode_Enabling) { UNIT_ASSERT_VALUES_EQUAL(counters->CacheMissPages->Val(), 232); UNIT_ASSERT_DOUBLES_EQUAL(counters->TryKeepInMemoryBytes->Val(), static_cast<i64>(10_MB), static_cast<i64>(1_MB / 3)); - // read from previously-in-memory table, should not be preloaded + // read from in-memory table, should be preloaded retried = {}; for (i64 key = 99; key >= 0; --key) { env.SendSync(new NFake::TEvExecute{ new TTxReadRows(TableId, key, retried) }, true); } LogCounters(counters); - UNIT_ASSERT_VALUES_EQUAL(retried, (TVector<ui32>{100, 100, 14, 2})); + UNIT_ASSERT_VALUES_EQUAL(retried, (TVector<ui32>{100})); UNIT_ASSERT_DOUBLES_EQUAL(counters->ActiveBytes->Val(), static_cast<i64>(10_MB), static_cast<i64>(1_MB / 3)); UNIT_ASSERT_VALUES_EQUAL(counters->ActivePages->Val(), 138); UNIT_ASSERT_DOUBLES_EQUAL(counters->PassiveBytes->Val(), static_cast<i64>(0_MB), static_cast<i64>(1_MB / 3)); UNIT_ASSERT_VALUES_EQUAL(counters->PassivePages->Val(), 1); - UNIT_ASSERT_DOUBLES_EQUAL(counters->CacheHitBytes->Val(), static_cast<i64>(10_MB), static_cast<i64>(1_MB / 3)); - UNIT_ASSERT_VALUES_EQUAL(counters->CacheHitPages->Val(), 116); + UNIT_ASSERT_DOUBLES_EQUAL(counters->CacheHitBytes->Val(), static_cast<i64>(0_MB), static_cast<i64>(1_MB / 3)); + UNIT_ASSERT_VALUES_EQUAL(counters->CacheHitPages->Val(), 0); UNIT_ASSERT_DOUBLES_EQUAL(counters->CacheMissBytes->Val(), static_cast<i64>(20'000_KB), static_cast<i64>(1_MB / 3)); UNIT_ASSERT_VALUES_EQUAL(counters->CacheMissPages->Val(), 232); UNIT_ASSERT_DOUBLES_EQUAL(counters->TryKeepInMemoryBytes->Val(), static_cast<i64>(10_MB), static_cast<i64>(1_MB / 3)); diff --git a/ydb/core/tablet_flat/ut/ut_shared_sausagecache_actor.cpp b/ydb/core/tablet_flat/ut/ut_shared_sausagecache_actor.cpp index ae0ba43656b..e7c758c6025 100644 --- a/ydb/core/tablet_flat/ut/ut_shared_sausagecache_actor.cpp +++ b/ydb/core/tablet_flat/ut/ut_shared_sausagecache_actor.cpp @@ -16,6 +16,7 @@ using namespace NPageCollection; static const ui64 NO_QUEUE_COOKIE = 1; static const ui64 ASYNC_QUEUE_COOKIE = 2; +static const ui64 TRY_KEEP_IN_MEMORY_PRELOAD_COOKIE = 4; static const ui64 DefaultMemoryLimit = 4 * (sizeof(TPage) + 10); @@ -1381,8 +1382,11 @@ Y_UNIT_TEST_SUITE(TSharedPageCache_Actor) { UNIT_ASSERT_VALUES_EQUAL(sharedCache.Counters->TryKeepInMemoryBytes->Val(), collection1TotalSize); UNIT_ASSERT_VALUES_EQUAL(sharedCache.Counters->ActiveLimitBytes->Val(), DefaultMemoryLimit); - sharedCache.Provide(sharedCache.Collection1, {0, 1, 2, 3}); + sharedCache.Provide(sharedCache.Collection1, {0, 1, 2, 3}, TRY_KEEP_IN_MEMORY_PRELOAD_COOKIE); sharedCache.CheckFetches({}); + sharedCache.CheckResults({ + TFetch{0, sharedCache.Collection1, {0, 1, 2, 3}} + }); UNIT_ASSERT_VALUES_EQUAL(sharedCache.Counters->LoadInFlyPages->Val(), 0); UNIT_ASSERT_VALUES_EQUAL(sharedCache.Counters->CacheHitPages->Val(), 0); @@ -1437,8 +1441,10 @@ Y_UNIT_TEST_SUITE(TSharedPageCache_Actor) { sharedCache.CheckFetches({ TFetch{40, sharedCache.Collection1, {0, 1, 2, 3}} }); - sharedCache.Provide(sharedCache.Collection1, {0, 1, 2, 3}); - sharedCache.CheckResults({}); + sharedCache.Provide(sharedCache.Collection1, {0, 1, 2, 3}, TRY_KEEP_IN_MEMORY_PRELOAD_COOKIE); + sharedCache.CheckResults({ + TFetch{0, sharedCache.Collection1, {0, 1, 2, 3}} + }); sharedCache.CheckFetches({}); UNIT_ASSERT_VALUES_EQUAL(sharedCache.Counters->CacheHitPages->Val(), 0); @@ -1478,13 +1484,16 @@ Y_UNIT_TEST_SUITE(TSharedPageCache_Actor) { // only 4 pages should be in memory cache sharedCache.Attach(sharedCache.Sender1, sharedCache.Collection1, ECacheMode::TryKeepInMemory); sharedCache.CheckFetches({ - TFetch{60, sharedCache.Collection1, {0, 1, 2, 3, 4, 5}} + TFetch{40, sharedCache.Collection1, {0, 1, 2, 3}} + }); + sharedCache.Provide(sharedCache.Collection1, {0, 1, 2, 3}, TRY_KEEP_IN_MEMORY_PRELOAD_COOKIE); + sharedCache.CheckResults({ + TFetch{0, sharedCache.Collection1, {0, 1, 2, 3}} }); - sharedCache.Provide(sharedCache.Collection1, {0, 1, 2, 3, 4, 5}); - sharedCache.CheckResults({}); sharedCache.CheckFetches({}); UNIT_ASSERT_VALUES_EQUAL(sharedCache.Counters->ActivePages->Val(), 4); + UNIT_ASSERT_VALUES_EQUAL(sharedCache.Counters->PassivePages->Val(), 0); UNIT_ASSERT_VALUES_EQUAL(sharedCache.Counters->TryKeepInMemoryBytes->Val(), collection1TotalSize); UNIT_ASSERT_VALUES_EQUAL(sharedCache.Counters->ActiveLimitBytes->Val(), DefaultMemoryLimit); @@ -1518,8 +1527,11 @@ Y_UNIT_TEST_SUITE(TSharedPageCache_Actor) { sharedCache.CheckFetches({ TFetch{30, sharedCache.Collection1, {0, 1, 3}} }); - sharedCache.Provide(sharedCache.Collection1, {0, 1, 3}); - sharedCache.CheckResults({}); + sharedCache.Provide(sharedCache.Collection1, {0, 1, 3}, TRY_KEEP_IN_MEMORY_PRELOAD_COOKIE); + sharedCache.CheckResults({ + TFetch{0, sharedCache.Collection1, {2}}, // already in cache + TFetch{0, sharedCache.Collection1, {0, 1, 3}}, // preloaded + }); sharedCache.CheckFetches({}); UNIT_ASSERT_VALUES_EQUAL(sharedCache.Counters->CacheMissPages->Val(), 1); @@ -1555,6 +1567,9 @@ Y_UNIT_TEST_SUITE(TSharedPageCache_Actor) { UNIT_ASSERT_VALUES_EQUAL(sharedCache.Counters->ActiveLimitBytes->Val(), DefaultMemoryLimit); sharedCache.Attach(sharedCache.Sender1, sharedCache.Collection1, ECacheMode::TryKeepInMemory); + sharedCache.CheckResults({ + TFetch{0, sharedCache.Collection1, {0, 1, 2, 3}} + }); sharedCache.CheckFetches({}); UNIT_ASSERT_VALUES_EQUAL(sharedCache.Counters->CacheMissPages->Val(), 4); @@ -1577,8 +1592,10 @@ Y_UNIT_TEST_SUITE(TSharedPageCache_Actor) { sharedCache.CheckFetches({ TFetch{40, sharedCache.Collection1, {0, 1, 2, 3}} }); - sharedCache.Provide(sharedCache.Collection1, {0, 1, 2, 3}); - sharedCache.CheckResults({}); + sharedCache.Provide(sharedCache.Collection1, {0, 1, 2, 3}, TRY_KEEP_IN_MEMORY_PRELOAD_COOKIE); + sharedCache.CheckResults({ + TFetch{0, sharedCache.Collection1, {0, 1, 2, 3}} + }); sharedCache.CheckFetches({}); UNIT_ASSERT_VALUES_EQUAL(sharedCache.Counters->CacheMissPages->Val(), 0); @@ -1609,8 +1626,10 @@ Y_UNIT_TEST_SUITE(TSharedPageCache_Actor) { sharedCache.CheckFetches({ TFetch{40, sharedCache.Collection1, {0, 1, 2, 3}} }); - sharedCache.Provide(sharedCache.Collection1, {0, 1, 2, 3}); - sharedCache.CheckResults({}); + sharedCache.Provide(sharedCache.Collection1, {0, 1, 2, 3}, TRY_KEEP_IN_MEMORY_PRELOAD_COOKIE); + sharedCache.CheckResults({ + TFetch{0, sharedCache.Collection1, {0, 1, 2, 3}} + }); sharedCache.CheckFetches({}); UNIT_ASSERT_VALUES_EQUAL(sharedCache.Counters->ActivePages->Val(), 4); @@ -1618,6 +1637,9 @@ Y_UNIT_TEST_SUITE(TSharedPageCache_Actor) { UNIT_ASSERT_VALUES_EQUAL(sharedCache.Counters->ActiveLimitBytes->Val(), DefaultMemoryLimit); sharedCache.Attach(sharedCache.Sender2, sharedCache.Collection1, ECacheMode::TryKeepInMemory); + sharedCache.CheckResults({ + TFetch{0, sharedCache.Collection1, {0, 1, 2, 3}} + }); sharedCache.CheckFetches({}); UNIT_ASSERT_VALUES_EQUAL(sharedCache.Counters->ActivePages->Val(), 4); @@ -1650,8 +1672,10 @@ Y_UNIT_TEST_SUITE(TSharedPageCache_Actor) { sharedCache.CheckFetches({ TFetch{40, sharedCache.Collection1, {0, 1, 2, 3}} }); - sharedCache.Provide(sharedCache.Collection1, {0, 1, 2, 3}); - sharedCache.CheckResults({}); + sharedCache.Provide(sharedCache.Collection1, {0, 1, 2, 3}, TRY_KEEP_IN_MEMORY_PRELOAD_COOKIE); + sharedCache.CheckResults({ + TFetch{0, sharedCache.Collection1, {0, 1, 2, 3}} + }); sharedCache.CheckFetches({}); UNIT_ASSERT_VALUES_EQUAL(sharedCache.Counters->ActivePages->Val(), 4); @@ -1659,6 +1683,9 @@ Y_UNIT_TEST_SUITE(TSharedPageCache_Actor) { UNIT_ASSERT_VALUES_EQUAL(sharedCache.Counters->ActiveLimitBytes->Val(), DefaultMemoryLimit); sharedCache.Attach(sharedCache.Sender2, sharedCache.Collection1, ECacheMode::TryKeepInMemory); + sharedCache.CheckResults({ + TFetch{0, sharedCache.Collection1, {0, 1, 2, 3}} + }); sharedCache.CheckFetches({}); UNIT_ASSERT_VALUES_EQUAL(sharedCache.Counters->ActivePages->Val(), 4); @@ -1734,6 +1761,9 @@ Y_UNIT_TEST_SUITE(TSharedPageCache_Actor) { sharedCache.Attach(sharedCache.Sender1, sharedCache.Collection1, ECacheMode::TryKeepInMemory); sharedCache.CheckFetches({}); // all collection#1 pages already loaded + sharedCache.CheckResults({ + TFetch{0, sharedCache.Collection1, {0, 1}} + }); collection1Pages.clear(); // release refs and allow collection#1 pages eviction // request next 4 pages from collection#2 to try preempt collection#1 pages @@ -1763,8 +1793,10 @@ Y_UNIT_TEST_SUITE(TSharedPageCache_Actor) { sharedCache.CheckFetches({ TFetch{20, sharedCache.Collection1, {0, 1}} }); - sharedCache.Provide(sharedCache.Collection1, {0, 1}); - sharedCache.CheckResults({}); + sharedCache.Provide(sharedCache.Collection1, {0, 1}, TRY_KEEP_IN_MEMORY_PRELOAD_COOKIE); + sharedCache.CheckResults({ + TFetch{0, sharedCache.Collection1, {0, 1}} + }); sharedCache.CheckFetches({}); sharedCache.Request(sharedCache.Sender1, sharedCache.Collection1, {0, 1}); @@ -1784,7 +1816,10 @@ Y_UNIT_TEST_SUITE(TSharedPageCache_Actor) { sharedCache.CheckFetches({ TFetch{40, sharedCache.Collection2, {0, 1, 2, 3}} }); - sharedCache.Provide(sharedCache.Collection2, {0, 1, 2, 3}); + sharedCache.Provide(sharedCache.Collection2, {0, 1, 2, 3}, TRY_KEEP_IN_MEMORY_PRELOAD_COOKIE); + sharedCache.CheckResults({ + TFetch{0, sharedCache.Collection2, {2, 3}} + }); // collection#1 pages has reads and prioritized, read collection#2 again to evict their pages sharedCache.Request(sharedCache.Sender1, sharedCache.Collection2, {0, 1, 2, 3}); |