3
3
#include < ydb/core/util/stlog.h>
4
4
#include < ydb/core/util/interval_set.h>
5
5
6
+ #include < ydb/core/blobstorage/pdisk/blobstorage_pdisk_quota_record.h>
6
7
#include < ydb/core/blobstorage/pdisk/blobstorage_pdisk_util_space_color.h>
7
8
8
9
namespace NKikimr {
@@ -50,7 +51,12 @@ struct TPDiskMockState::TImpl {
50
51
NPDisk::EDeviceType DeviceType;
51
52
std::optional<TRcBuf> Metadata;
52
53
53
- TImpl (ui32 nodeId, ui32 pdiskId, ui64 pdiskGuid, ui64 size, ui32 chunkSize, bool isDiskReadOnly, NPDisk::EDeviceType deviceType)
54
+ ESpaceColorPolicy SpaceColorPolicy;
55
+ std::shared_ptr<NPDisk::TQuotaRecord> ChunkSharedQuota;
56
+ double Occupancy = 0 ;
57
+
58
+ TImpl (ui32 nodeId, ui32 pdiskId, ui64 pdiskGuid, ui64 size, ui32 chunkSize, bool isDiskReadOnly, NPDisk::EDeviceType deviceType,
59
+ ESpaceColorPolicy spaceColorPolicy)
54
60
: NodeId(nodeId)
55
61
, PDiskId(pdiskId)
56
62
, PDiskGuid(pdiskGuid)
@@ -62,7 +68,20 @@ struct TPDiskMockState::TImpl {
62
68
, NextFreeChunk(1 )
63
69
, StatusFlags(NPDisk::TStatusFlags{})
64
70
, DeviceType(deviceType)
65
- {}
71
+ , SpaceColorPolicy(spaceColorPolicy)
72
+ {
73
+ switch (SpaceColorPolicy) {
74
+ case ESpaceColorPolicy::SharedQuota: {
75
+ ChunkSharedQuota = std::make_shared<NPDisk::TQuotaRecord>();
76
+ // 13% for CYAN is default value in prod
77
+ ChunkSharedQuota->ForceHardLimit (TotalChunks, NPDisk::TColorLimits::MakeChunkLimits (130 ));
78
+ break ;
79
+ }
80
+ case ESpaceColorPolicy::None:
81
+ default :
82
+ break ;
83
+ }
84
+ }
66
85
67
86
TImpl (const TImpl&) = default ;
68
87
@@ -76,6 +95,25 @@ struct TPDiskMockState::TImpl {
76
95
}
77
96
}
78
97
98
+ void UpdateStatusFlags (i64 chunksDelta) {
99
+ switch (SpaceColorPolicy) {
100
+ case ESpaceColorPolicy::SharedQuota: {
101
+ NKikimrBlobStorage::TPDiskSpaceColor::E newColor =
102
+ ChunkSharedQuota->EstimateSpaceColor (chunksDelta, &Occupancy);
103
+ if (chunksDelta < 0 ) {
104
+ ChunkSharedQuota->Release (-chunksDelta);
105
+ } else if (chunksDelta > 0 ) {
106
+ ChunkSharedQuota->ForceAllocate (chunksDelta);
107
+ }
108
+ SetStatusFlags (SpaceColorToStatusFlag (newColor));
109
+ break ;
110
+ }
111
+ case ESpaceColorPolicy::None:
112
+ default :
113
+ break ;
114
+ }
115
+ }
116
+
79
117
ui32 AllocateChunk (TOwner& to) {
80
118
ui32 chunkIdx = TotalChunks;
81
119
@@ -89,6 +127,8 @@ struct TPDiskMockState::TImpl {
89
127
}
90
128
91
129
Y_ABORT_UNLESS (chunkIdx != TotalChunks);
130
+
131
+ UpdateStatusFlags (1 );
92
132
return chunkIdx;
93
133
}
94
134
@@ -172,6 +212,8 @@ struct TPDiskMockState::TImpl {
172
212
for (const TChunkIdx chunkIdx : owner.ReservedChunks ) {
173
213
owner.ChunkData .erase (chunkIdx);
174
214
}
215
+
216
+ UpdateStatusFlags (-(i64 )owner.ReservedChunks .size ());
175
217
FreeChunks.merge (owner.ReservedChunks );
176
218
AdjustFreeChunks ();
177
219
}
@@ -189,6 +231,8 @@ struct TPDiskMockState::TImpl {
189
231
owner.ChunkData .erase (chunkIdx);
190
232
const bool inserted = FreeChunks.insert (chunkIdx).second ;
191
233
Y_ABORT_UNLESS (inserted);
234
+
235
+ UpdateStatusFlags (-1 );
192
236
AdjustFreeChunks ();
193
237
}
194
238
@@ -286,8 +330,9 @@ struct TPDiskMockState::TImpl {
286
330
};
287
331
288
332
TPDiskMockState::TPDiskMockState (ui32 nodeId, ui32 pdiskId, ui64 pdiskGuid, ui64 size, ui32 chunkSize, bool isDiskReadOnly,
289
- NPDisk::EDeviceType deviceType)
290
- : TPDiskMockState(std::make_unique<TImpl>(nodeId, pdiskId, pdiskGuid, size, chunkSize, isDiskReadOnly, deviceType))
333
+ NPDisk::EDeviceType deviceType, ESpaceColorPolicy spaceColorPolicy)
334
+ : TPDiskMockState(std::make_unique<TImpl>(nodeId, pdiskId, pdiskGuid, size, chunkSize, isDiskReadOnly, deviceType,
335
+ spaceColorPolicy))
291
336
{}
292
337
293
338
TPDiskMockState::TPDiskMockState (std::unique_ptr<TImpl>&& impl)
@@ -475,6 +520,8 @@ class TPDiskMockActor : public TActorBootstrapped<TPDiskMockActor> {
475
520
break ;
476
521
} else {
477
522
owner.Slain = true ;
523
+ Impl.UpdateStatusFlags (-(i64 )owner.ReservedChunks .size ());
524
+ Impl.UpdateStatusFlags (-(i64 )owner.CommittedChunks .size ());
478
525
Impl.FreeChunks .merge (owner.ReservedChunks );
479
526
Impl.FreeChunks .merge (owner.CommittedChunks );
480
527
Impl.AdjustFreeChunks ();
@@ -676,6 +723,7 @@ class TPDiskMockActor : public TActorBootstrapped<TPDiskMockActor> {
676
723
for (ui32 i = 0 ; i < msg->SizeChunks ; ++i) {
677
724
res->ChunkIds .push_back (Impl.AllocateChunk (*owner));
678
725
}
726
+ res->StatusFlags = GetStatusFlags ();
679
727
PDISK_MOCK_LOG (DEBUG, PDM10, " sending TEvChunkReserveResult" , (Msg, res->ToString ()));
680
728
}
681
729
}
@@ -848,7 +896,7 @@ class TPDiskMockActor : public TActorBootstrapped<TPDiskMockActor> {
848
896
auto res = std::make_unique<NPDisk::TEvCheckSpaceResult>(NKikimrProto::OK, GetStatusFlags (),
849
897
Impl.GetNumFreeChunks (), Impl.TotalChunks , Impl.TotalChunks - Impl.GetNumFreeChunks (),
850
898
Impl.Owners .size (), TString ());
851
- res->Occupancy = ( double )res-> UsedChunks / res-> TotalChunks ;
899
+ res->Occupancy = GetOccupancy () ;
852
900
Impl.FindOwner (msg, res); // to ensure correct owner/round
853
901
Send (ev->Sender , res.release ());
854
902
}
@@ -886,6 +934,12 @@ class TPDiskMockActor : public TActorBootstrapped<TPDiskMockActor> {
886
934
return Impl.StatusFlags ;
887
935
}
888
936
937
+ double GetOccupancy () {
938
+ return (Impl.Occupancy == 0 )
939
+ ? ((double )(Impl.TotalChunks - Impl.GetNumFreeChunks ()) / Impl.TotalChunks )
940
+ : Impl.Occupancy ;
941
+ }
942
+
889
943
void ErrorHandle (NPDisk::TEvYardInit::TPtr &ev) {
890
944
Send (ev->Sender , new NPDisk::TEvYardInitResult (NKikimrProto::CORRUPTED, State->GetStateErrorReason ()));
891
945
}
0 commit comments