@@ -38,6 +38,8 @@ TSharedPageCacheCounters::TSharedPageCacheCounters(const TIntrusivePtr<::NMonito
38
38
namespace NKikimr {
39
39
namespace NTabletFlatExecutor {
40
40
41
+ using namespace NCache ;
42
+
41
43
static bool Satisfies (NLog::EPriority priority = NLog::PRI_DEBUG) {
42
44
if (NLog::TSettings *settings = TlsActivationContext->LoggerSettings ())
43
45
return settings->Satisfies (priority, NKikimrServices::TABLET_SAUSAGECACHE);
@@ -68,7 +70,6 @@ class TSharedPageCache : public TActorBootstrapped<TSharedPageCache> {
68
70
{
69
71
ui32 State : 4 ;
70
72
ui32 CacheGeneration : 3 ;
71
- ui32 InMemory : 1 ;
72
73
73
74
const ui32 PageId;
74
75
const size_t Size;
@@ -78,7 +79,6 @@ class TSharedPageCache : public TActorBootstrapped<TSharedPageCache> {
78
79
TPage (ui32 pageId, size_t size, TCollection* collection)
79
80
: State(PageStateNo)
80
81
, CacheGeneration(TCacheCacheConfig::CacheGenNone)
81
- , InMemory(false )
82
82
, PageId(pageId)
83
83
, Size(size)
84
84
, Collection(collection)
@@ -178,7 +178,7 @@ class TSharedPageCache : public TActorBootstrapped<TSharedPageCache> {
178
178
TRequestQueue ScanRequests;
179
179
180
180
THolder<TSharedPageCacheConfig> Config;
181
- TCacheCache<TPage, TPage::TWeight, TCacheCacheConfig::TDefaultGeneration <TPage>> Cache;
181
+ THolder<ICacheCache <TPage>> Cache;
182
182
183
183
ui64 StatBioReqs = 0 ;
184
184
ui64 StatHitPages = 0 ;
@@ -193,14 +193,18 @@ class TSharedPageCache : public TActorBootstrapped<TSharedPageCache> {
193
193
194
194
ui64 MemLimitBytes;
195
195
196
+ void CreateCache () {
197
+ TCacheCacheConfig cacheCacheConfig (1 , Config->Counters ->FreshBytes , Config->Counters ->StagingBytes , Config->Counters ->WarmBytes );
198
+ Cache = MakeHolder<TCacheCache<TPage, TPage::TWeight, TCacheCacheConfig::TDefaultGeneration<TPage>>>(std::move (cacheCacheConfig));
199
+ }
200
+
196
201
void ActualizeCacheSizeLimit () {
197
202
ui64 limitBytes = Min (Config->LimitBytes .value_or (Max<ui64>()), MemLimitBytes);
198
203
199
204
// limit of cache depends only on config and mem because passive pages may go in and out arbitrary
200
205
// we may have some passive bytes, so if we fully fill this Cache we may exceed the limit
201
206
// because of that DoGC should be called to ensure limits
202
- // unlimited cache is banned
203
- Cache.UpdateCacheSize (Max<ui64>(1 , limitBytes));
207
+ Cache->UpdateCacheSize (limitBytes);
204
208
205
209
if (Config->Counters ) {
206
210
Config->Counters ->ConfigLimitBytes ->Set (Config->LimitBytes .value_or (0 ));
@@ -219,7 +223,7 @@ class TSharedPageCache : public TActorBootstrapped<TSharedPageCache> {
219
223
THashSet<TCollection*> recheck;
220
224
while (GetStatAllBytes () > MemLimitBytes
221
225
|| GetStatAllBytes () > Config->LimitBytes .value_or (Max<ui64>()) && StatActiveBytes > configActiveReservedBytes) {
222
- auto page = Cache. EvictNext ();
226
+ auto page = Cache-> EvictNext ();
223
227
if (!page) {
224
228
break ;
225
229
}
@@ -366,7 +370,7 @@ class TSharedPageCache : public TActorBootstrapped<TSharedPageCache> {
366
370
++*Config->Counters ->CacheHitPages ;
367
371
*Config->Counters ->CacheHitBytes += page->Size ;
368
372
}
369
- Evict (Cache. Touch (page));
373
+ Evict (Cache-> Touch (page));
370
374
break ;
371
375
case PageStateNo:
372
376
++pagesToLoad;
@@ -648,7 +652,7 @@ class TSharedPageCache : public TActorBootstrapped<TSharedPageCache> {
648
652
AddActivePage (page);
649
653
[[fallthrough]];
650
654
case PageStateLoaded:
651
- Evict (Cache. Touch (page));
655
+ Evict (Cache-> Touch (page));
652
656
break ;
653
657
default :
654
658
Y_ABORT (" unknown load state" );
@@ -749,7 +753,7 @@ class TSharedPageCache : public TActorBootstrapped<TSharedPageCache> {
749
753
750
754
page->Initialize (std::move (paged.Data ));
751
755
BodyProvided (collection, paged.PageId , page);
752
- Evict (Cache. Touch (page));
756
+ Evict (Cache-> Touch (page));
753
757
}
754
758
}
755
759
@@ -882,7 +886,7 @@ class TSharedPageCache : public TActorBootstrapped<TSharedPageCache> {
882
886
const TLogoBlobID &pageCollectionId = collectionIt->first ;
883
887
884
888
if (auto logl = Logger->Log (ELnLev::Debug))
885
- logl << " droping pageCollection " << pageCollectionId;
889
+ logl << " dropping pageCollection " << pageCollectionId;
886
890
887
891
for (auto &expe : collection.Expectants ) {
888
892
for (auto &xpair : expe.second .SourceRequests ) {
@@ -901,7 +905,7 @@ class TSharedPageCache : public TActorBootstrapped<TSharedPageCache> {
901
905
for (const auto &kv : collection.PageMap ) {
902
906
auto * page = kv.second .Get ();
903
907
904
- Cache. Evict (page);
908
+ Cache-> Erase (page);
905
909
page->CacheGeneration = TCacheCacheConfig::CacheGenNone;
906
910
907
911
if (page->State == PageStateLoaded) {
@@ -1099,8 +1103,8 @@ class TSharedPageCache : public TActorBootstrapped<TSharedPageCache> {
1099
1103
public:
1100
1104
TSharedPageCache (THolder<TSharedPageCacheConfig> config)
1101
1105
: Config(std::move(config))
1102
- , Cache(TCacheCacheConfig(1 , Config->Counters->FreshBytes, Config->Counters->StagingBytes, Config->Counters->WarmBytes))
1103
1106
{
1107
+ CreateCache ();
1104
1108
AsyncRequests.Limit = Config->TotalAsyncQueueInFlyLimit ;
1105
1109
ScanRequests.Limit = Config->TotalScanQueueInFlyLimit ;
1106
1110
}
0 commit comments