Skip to content

Commit e1703a0

Browse files
committed
clean up, test read twice
1 parent 55dd325 commit e1703a0

File tree

3 files changed

+47
-11
lines changed

3 files changed

+47
-11
lines changed

ydb/core/tablet_flat/shared_cache_s3fifo.h

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44
#include <ydb/library/yverify_stream/yverify_stream.h>
55
#include <library/cpp/monlib/counters/counters.h>
66
#include <library/cpp/monlib/dynamic_counters/counters.h>
7-
#include <util/generic/ptr.h>
8-
#include <util/generic/intrlist.h>
97

108
namespace NKikimr::NCache {
119

@@ -14,7 +12,7 @@ namespace NKikimr::NCache {
1412
template <typename TPageKey
1513
, typename TPageKeyHash
1614
, typename TPageKeyEqual>
17-
class TTS3FIFOGhostQueue {
15+
class TTS3FIFOGhostPageQueue {
1816
struct TGhostPage {
1917
TPageKey Key;
2018
ui64 Size; // zero size is tombstone
@@ -38,7 +36,7 @@ class TTS3FIFOGhostQueue {
3836
};
3937

4038
public:
41-
TTS3FIFOGhostQueue(ui64 limit)
39+
TTS3FIFOGhostPageQueue(ui64 limit)
4240
: Limit(limit)
4341
{}
4442

@@ -66,7 +64,7 @@ class TTS3FIFOGhostQueue {
6664
Y_DEBUG_ABORT_UNLESS(ghost->Size == size);
6765
Y_ABORT_UNLESS(Size >= ghost->Size);
6866
Size -= ghost->Size;
69-
ghost->Size = 0;// mark as deleted
67+
ghost->Size = 0; // mark as deleted
7068
GhostsSet.erase(it);
7169
return true;
7270
}
@@ -356,7 +354,7 @@ class TS3FIFOCache : public ICacheCache<TPage> {
356354
TLimit Limit;
357355
TQueue SmallQueue;
358356
TQueue MainQueue;
359-
TTS3FIFOGhostQueue<TPageKey, TPageKeyHash, TPageKeyEqual> GhostQueue;
357+
TTS3FIFOGhostPageQueue<TPageKey, TPageKeyHash, TPageKeyEqual> GhostQueue;
360358

361359
};
362360

ydb/core/tablet_flat/shared_cache_s3fifo_ut.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ namespace {
7676
Y_UNIT_TEST_SUITE(TS3FIFOGhostQueue) {
7777

7878
Y_UNIT_TEST(Add) {
79-
TTS3FIFOGhostQueue<TPageKey, TPageKeyHash, TPageKeyEqual> queue(100);
79+
TTS3FIFOGhostPageQueue<TPageKey, TPageKeyHash, TPageKeyEqual> queue(100);
8080
UNIT_ASSERT_VALUES_EQUAL(queue.Dump(), "");
8181

8282
queue.Add(1, 10);
@@ -96,7 +96,7 @@ Y_UNIT_TEST_SUITE(TS3FIFOGhostQueue) {
9696
}
9797

9898
Y_UNIT_TEST(Erase) {
99-
TTS3FIFOGhostQueue<TPageKey, TPageKeyHash, TPageKeyEqual> queue(100);
99+
TTS3FIFOGhostPageQueue<TPageKey, TPageKeyHash, TPageKeyEqual> queue(100);
100100
UNIT_ASSERT_VALUES_EQUAL(queue.Dump(), "");
101101

102102
queue.Add(1, 10);
@@ -118,7 +118,7 @@ Y_UNIT_TEST_SUITE(TS3FIFOGhostQueue) {
118118
}
119119

120120
Y_UNIT_TEST(Erase_Add) {
121-
TTS3FIFOGhostQueue<TPageKey, TPageKeyHash, TPageKeyEqual> queue(100);
121+
TTS3FIFOGhostPageQueue<TPageKey, TPageKeyHash, TPageKeyEqual> queue(100);
122122
UNIT_ASSERT_VALUES_EQUAL(queue.Dump(), "");
123123

124124
queue.Add(1, 10);
@@ -137,15 +137,15 @@ Y_UNIT_TEST_SUITE(TS3FIFOGhostQueue) {
137137
}
138138

139139
Y_UNIT_TEST(Add_Big) {
140-
TTS3FIFOGhostQueue<TPageKey, TPageKeyHash, TPageKeyEqual> queue(100);
140+
TTS3FIFOGhostPageQueue<TPageKey, TPageKeyHash, TPageKeyEqual> queue(100);
141141
UNIT_ASSERT_VALUES_EQUAL(queue.Dump(), "");
142142

143143
queue.Add(1, 101);
144144
UNIT_ASSERT_VALUES_EQUAL(queue.Dump(), "");
145145
}
146146

147147
Y_UNIT_TEST(UpdateLimit) {
148-
TTS3FIFOGhostQueue<TPageKey, TPageKeyHash, TPageKeyEqual> queue(100);
148+
TTS3FIFOGhostPageQueue<TPageKey, TPageKeyHash, TPageKeyEqual> queue(100);
149149
UNIT_ASSERT_VALUES_EQUAL(queue.Dump(), "");
150150

151151
queue.Add(1, 10);

ydb/core/tablet_flat/ut/ut_shared_sausagecache.cpp

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,25 @@ Y_UNIT_TEST(ThreeLeveledLRU) {
266266
retried = {};
267267
env.SendSync(new NFake::TEvExecute{ new TTxReadRow(0, retried) }, true);
268268
UNIT_ASSERT_VALUES_EQUAL(retried, (TVector<ui32>{1, 1, 1}));
269+
270+
RestartAndClearCache(env);
271+
272+
retried = {};
273+
for (i64 key = 0; key < 100; ++key) {
274+
env.SendSync(new NFake::TEvExecute{ new TTxReadRow(key, retried) }, true);
275+
env.SendSync(new NFake::TEvExecute{ new TTxReadRow(key, retried) }, true);
276+
}
277+
LogCounters(counters);
278+
UNIT_ASSERT_DOUBLES_EQUAL(counters->ActiveBytes->Val(), static_cast<i64>(8_MB / 3 * 2), static_cast<i64>(1_MB / 3)); // 2 full layers (fresh & staging)
279+
UNIT_ASSERT_VALUES_EQUAL(retried, (TVector<ui32>{200, 100, 14, 2}));
280+
281+
retried = {};
282+
for (i64 key = 0; key < 100; ++key) {
283+
env.SendSync(new NFake::TEvExecute{ new TTxReadRow(key, retried) }, true);
284+
}
285+
LogCounters(counters);
286+
UNIT_ASSERT_DOUBLES_EQUAL(counters->ActiveBytes->Val(), static_cast<i64>(8_MB / 3 * 2), static_cast<i64>(1_MB / 3)); // 2 full layers (fresh & staging)
287+
UNIT_ASSERT_VALUES_EQUAL(retried, (TVector<ui32>{100, 100, 14}));
269288
}
270289

271290
Y_UNIT_TEST(S3FIFO) {
@@ -346,6 +365,25 @@ Y_UNIT_TEST(S3FIFO) {
346365
retried = {};
347366
env.SendSync(new NFake::TEvExecute{ new TTxReadRow(0, retried) }, true);
348367
UNIT_ASSERT_VALUES_EQUAL(retried, (TVector<ui32>{1}));
368+
369+
RestartAndClearCache(env);
370+
371+
retried = {};
372+
for (i64 key = 0; key < 100; ++key) {
373+
env.SendSync(new NFake::TEvExecute{ new TTxReadRow(key, retried) }, true);
374+
env.SendSync(new NFake::TEvExecute{ new TTxReadRow(key, retried) }, true);
375+
}
376+
LogCounters(counters);
377+
UNIT_ASSERT_DOUBLES_EQUAL(counters->ActiveBytes->Val(), static_cast<i64>(8_MB), static_cast<i64>(1_MB / 3));
378+
UNIT_ASSERT_VALUES_EQUAL(retried, (TVector<ui32>{200, 100, 14, 2}));
379+
380+
retried = {};
381+
for (i64 key = 0; key < 100; ++key) {
382+
env.SendSync(new NFake::TEvExecute{ new TTxReadRow(key, retried) }, true);
383+
}
384+
LogCounters(counters);
385+
UNIT_ASSERT_DOUBLES_EQUAL(counters->ActiveBytes->Val(), static_cast<i64>(8_MB), static_cast<i64>(1_MB / 3));
386+
UNIT_ASSERT_VALUES_EQUAL(retried, (TVector<ui32>{100, 28}));
349387
}
350388

351389
Y_UNIT_TEST(ReplacementPolicySwitch) {

0 commit comments

Comments
 (0)