@@ -92,6 +92,10 @@ class TMemoryResource : public TAtomicRefCount<TMemoryResource> {
92
92
SpillingCookie->SpillingPercentReached .store (Available () < OverLimit);
93
93
}
94
94
95
+ ui64 GetUsed () const {
96
+ return Used;
97
+ }
98
+
95
99
void Release (ui64 value) {
96
100
if (Used > value) {
97
101
Used -= value;
@@ -103,7 +107,7 @@ class TMemoryResource : public TAtomicRefCount<TMemoryResource> {
103
107
}
104
108
105
109
void SetNewLimit (ui64 baseLimit, double memoryPoolPercent, double overPercent) {
106
- if (abs (memoryPoolPercent - MemoryPoolPercent) < MYEPS && baseLimit ! = BaseLimit)
110
+ if (abs (memoryPoolPercent - MemoryPoolPercent) < MYEPS && baseLimit = = BaseLimit)
107
111
return ;
108
112
109
113
BaseLimit = baseLimit;
@@ -256,7 +260,7 @@ class TKqpResourceManager : public IKqpResourceManager {
256
260
task->TotalMemoryCookie = TotalMemoryResource->GetSpillingCookie ();
257
261
258
262
if (hasScanQueryMemory && !tx->PoolId .empty () && tx->MemoryPoolPercent > 0 ) {
259
- auto [it, success] = MemoryNamedPools.emplace (tx->PoolId , nullptr );
263
+ auto [it, success] = MemoryNamedPools.emplace (tx->MakePoolId () , nullptr );
260
264
261
265
if (success) {
262
266
it->second = MakeIntrusive<TMemoryResource>(TotalMemoryResource->GetLimit (), tx->MemoryPoolPercent , SpillingPercent.load ());
@@ -291,9 +295,15 @@ class TKqpResourceManager : public IKqpResourceManager {
291
295
Counters->RmNotEnoughMemory ->Inc ();
292
296
with_lock (Lock) {
293
297
TotalMemoryResource->Release (resources.Memory );
294
- auto it = MemoryNamedPools.find (tx->PoolId );
295
- if (it != MemoryNamedPools.end ()) {
296
- it->second ->Release (resources.Memory );
298
+ if (!tx->PoolId .empty ()) {
299
+ auto it = MemoryNamedPools.find (tx->MakePoolId ());
300
+ if (it != MemoryNamedPools.end ()) {
301
+ it->second ->Release (resources.Memory );
302
+ }
303
+
304
+ if (it->second ->GetUsed () == 0 ) {
305
+ MemoryNamedPools.erase (it);
306
+ }
297
307
}
298
308
}
299
309
}
@@ -356,9 +366,15 @@ class TKqpResourceManager : public IKqpResourceManager {
356
366
if (resources.Memory > 0 ) {
357
367
with_lock (Lock) {
358
368
TotalMemoryResource->Release (resources.Memory );
359
- auto it = MemoryNamedPools.find (tx->PoolId );
360
- if (it != MemoryNamedPools.end ()) {
361
- it->second ->Release (resources.Memory );
369
+ if (!tx->PoolId .empty ()) {
370
+ auto it = MemoryNamedPools.find (tx->MakePoolId ());
371
+ if (it != MemoryNamedPools.end ()) {
372
+ it->second ->Release (resources.Memory );
373
+
374
+ if (it->second ->GetUsed () == 0 ) {
375
+ MemoryNamedPools.erase (it);
376
+ }
377
+ }
362
378
}
363
379
}
364
380
}
@@ -509,7 +525,7 @@ class TKqpResourceManager : public IKqpResourceManager {
509
525
std::shared_ptr<TResourceSnapshotState> ResourceSnapshotState;
510
526
TActorId ResourceInfoExchanger = TActorId();
511
527
512
- absl::flat_hash_map<TString, TIntrusivePtr<TMemoryResource>> MemoryNamedPools;
528
+ absl::flat_hash_map<std::pair< TString, TString>, TIntrusivePtr<TMemoryResource>, THash<std::pair<TString, TString> >> MemoryNamedPools;
513
529
};
514
530
515
531
struct TResourceManagers {
0 commit comments