forked from ydb-platform/nbs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpart2_actor.cpp
929 lines (750 loc) · 28.4 KB
/
part2_actor.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
#include "part2_actor.h"
#include <cloud/blockstore/libs/diagnostics/critical_events.h>
#include <cloud/blockstore/libs/storage/core/unimplemented.h>
#include <cloud/storage/core/libs/api/hive_proxy.h>
#include <cloud/storage/core/libs/common/verify.h>
#include <contrib/ydb/core/base/tablet_pipe.h>
#include <contrib/ydb/core/node_whiteboard/node_whiteboard.h>
#include <contrib/ydb/core/tablet/tablet_counters_aggregator.h>
namespace NCloud::NBlockStore::NStorage::NPartition2 {
using namespace NActors;
using namespace NKikimr;
using namespace NKikimr::NNodeWhiteboard;
using namespace NKikimr::NTabletFlatExecutor;
using namespace NCloud::NStorage;
////////////////////////////////////////////////////////////////////////////////
static constexpr TDuration YellowStateUpdateInterval = TDuration::Seconds(15);
static constexpr TDuration BackpressureReportSendInterval = TDuration::Seconds(5);
////////////////////////////////////////////////////////////////////////////////
const TPartitionActor::TStateInfo TPartitionActor::States[STATE_MAX] = {
{ "Boot", (IActor::TReceiveFunc)&TPartitionActor::StateBoot },
{ "Init", (IActor::TReceiveFunc)&TPartitionActor::StateInit },
{ "Work", (IActor::TReceiveFunc)&TPartitionActor::StateWork },
{ "Zombie", (IActor::TReceiveFunc)&TPartitionActor::StateZombie },
};
TPartitionActor::TPartitionActor(
const TActorId& owner,
TTabletStorageInfoPtr storage,
TStorageConfigPtr config,
TDiagnosticsConfigPtr diagnosticsConfig,
IProfileLogPtr profileLog,
IBlockDigestGeneratorPtr blockDigestGenerator,
NProto::TPartitionConfig partitionConfig,
EStorageAccessMode storageAccessMode,
ui32 siblingCount,
const TActorId& volumeActorId)
: TActor(&TThis::StateBoot)
, TTabletBase(owner, std::move(storage))
, Config(std::move(config))
, PartitionConfig(std::move(partitionConfig))
, DiagnosticsConfig(std::move(diagnosticsConfig))
, ProfileLog(std::move(profileLog))
, BlockDigestGenerator(std::move(blockDigestGenerator))
, StorageAccessMode(storageAccessMode)
, SiblingCount(siblingCount)
, VolumeActorId(volumeActorId)
, ChannelHistorySize(CalcChannelHistorySize())
{}
TPartitionActor::~TPartitionActor()
{
ReleaseTransactions();
}
TString TPartitionActor::GetStateName(ui32 state)
{
if (state < STATE_MAX) {
return States[state].Name;
}
return "<unknown>";
}
void TPartitionActor::Enqueue(STFUNC_SIG)
{
ALOG_ERROR(TBlockStoreComponents::PARTITION,
"[" << TabletID() << "]"
<< " IGNORING message type# " << ev->GetTypeRewrite()
<< " from Sender# " << ToString(ev->Sender)
<< " in StateBoot");
}
////////////////////////////////////////////////////////////////////////////////
void TPartitionActor::DefaultSignalTabletActive(const TActorContext& ctx)
{
Y_UNUSED(ctx); // postpone until LoadState transaction completes
}
void TPartitionActor::BecomeAux(const TActorContext& ctx, EState state)
{
Y_ABORT_UNLESS(state < STATE_MAX);
Become(States[state].Func);
CurrentState = state;
LOG_DEBUG(ctx, TBlockStoreComponents::PARTITION,
"[%lu] Switched to state %s (system: %s, user: %s, executor: %s)",
TabletID(),
States[state].Name.data(),
ToString(Tablet()).data(),
ToString(SelfId()).data(),
ToString(ExecutorID()).data());
ReportTabletState(ctx);
}
void TPartitionActor::ReportTabletState(const TActorContext& ctx)
{
auto service = MakeNodeWhiteboardServiceId(SelfId().NodeId());
auto request = std::make_unique<TEvWhiteboard::TEvTabletStateUpdate>(
TabletID(),
CurrentState);
NCloud::Send(ctx, service, std::move(request));
}
////////////////////////////////////////////////////////////////////////////////
void TPartitionActor::RegisterCounters(const TActorContext& ctx)
{
if (!Counters) {
auto counters = CreatePartitionCounters();
// LAME: ownership transferred to executor
Counters = counters.get();
Executor()->RegisterExternalTabletCounters(counters.release());
// only aggregated statistics will be reported by default
// (you can always turn on per-tablet statistics on monitoring page)
// TabletCountersAddTablet(TabletID(), ctx);
ScheduleCountersUpdate(ctx);
}
if (!PartCounters) {
PartCounters = CreatePartitionDiskCounters(
EPublishingPolicy::Repl,
DiagnosticsConfig->GetHistogramCounterOptions());
}
}
void TPartitionActor::ScheduleCountersUpdate(const TActorContext& ctx)
{
if (!UpdateCountersScheduled) {
ctx.Schedule(UpdateCountersInterval,
new TEvPartitionPrivate::TEvUpdateCounters());
UpdateCountersScheduled = true;
}
}
void TPartitionActor::UpdateCounters(const TActorContext& ctx)
{
Y_UNUSED(ctx);
if (!Counters || !PartCounters || !State) {
return;
}
const auto& stats = State->GetStats();
#define BLOCKSTORE_PARTITION2_UPDATE_COUNTER(name, category, ...) \
{ \
auto& counter = Counters->Cumulative() \
[TPartitionCounters::CUMULATIVE_COUNTER_##category##_##name]; \
ui64 value = stats.Get##category##Counters().Get##name(); \
Y_DEBUG_ABORT_UNLESS(value >= counter.Get()); \
if (value < counter.Get()) { \
ReportCounterUpdateRace(); \
} \
counter.Increment(value - counter.Get()); \
} \
// BLOCKSTORE_PARTITION2_UPDATE_COUNTER
BLOCKSTORE_PARTITION2_IO_COUNTERS(BLOCKSTORE_PARTITION2_UPDATE_COUNTER)
#undef BLOCKSTORE_PARTITION2_UPDATE_COUNTER
SendStatsToService(ctx);
}
////////////////////////////////////////////////////////////////////////////////
void TPartitionActor::ScheduleYellowStateUpdate(const TActorContext& ctx)
{
if (!UpdateYellowStateScheduled) {
ctx.Schedule(YellowStateUpdateInterval,
new TEvPartitionPrivate::TEvUpdateYellowState());
UpdateYellowStateScheduled = true;
}
}
void TPartitionActor::UpdateYellowState(const TActorContext& ctx)
{
ctx.Register(CreateTabletDSChecker(SelfId(), Info()));
}
void TPartitionActor::ReassignChannelsIfNeeded(const NActors::TActorContext& ctx)
{
const auto timeout = Config->GetReassignRequestRetryTimeout();
if (ReassignRequestSentTs.GetValue()
&& ReassignRequestSentTs + timeout >= ctx.Now())
{
return;
}
auto channels = State->GetChannelsToReassign();
if (channels.empty()) {
return;
}
if (ReassignRequestSentTs.GetValue()) {
LOG_WARN(ctx, TBlockStoreComponents::PARTITION,
"[%lu] Retrying reassign request (timeout: %lu milliseconds)",
TabletID(),
timeout.MilliSeconds());
}
{
TStringBuilder sb;
for (const auto channel: channels) {
if (sb.size()) {
sb << ", ";
}
sb << channel;
}
LOG_WARN(ctx, TBlockStoreComponents::PARTITION,
"[%lu] Reassign request sent for channels: %s",
TabletID(),
sb.c_str());
}
NCloud::Send<TEvHiveProxy::TEvReassignTabletRequest>(
ctx,
MakeHiveProxyServiceId(),
0, // cookie
TabletID(),
std::move(channels));
ReportReassignTablet();
ReassignRequestSentTs = ctx.Now();
}
////////////////////////////////////////////////////////////////////////////////
bool TPartitionActor::OnRenderAppHtmlPage(
NMon::TEvRemoteHttpInfo::TPtr ev,
const TActorContext& ctx)
{
if (!Executor() || !Executor()->GetStats().IsActive) {
return false;
}
if (ev) {
HandleHttpInfo(ev, ctx);
}
return true;
}
void TPartitionActor::OnActivateExecutor(const TActorContext& ctx)
{
LOG_INFO(ctx, TBlockStoreComponents::PARTITION,
"[%lu] Activated executor",
TabletID());
BecomeAux(ctx, STATE_INIT);
RegisterCounters(ctx);
ctx.Schedule(BackpressureReportSendInterval,
new TEvPartitionPrivate::TEvSendBackpressureReport());
if (!Executor()->GetStats().IsFollower) {
ExecuteTx<TInitSchema>(ctx);
}
}
void TPartitionActor::Activate(const TActorContext& ctx)
{
BecomeAux(ctx, STATE_WORK);
// allow pipes to connect
SignalTabletActive(ctx);
// resend pending requests
SendPendingRequests(ctx, PendingRequests);
if (!Config->GetRunV2SoftGcAtStartup()) {
State->CollectGarbageHardRequested = true;
}
if (!Config->GetDontEnqueueCollectGarbageUponPartitionStartup()) {
EnqueueCollectGarbageIfNeeded(ctx);
}
EnqueueFlushIfNeeded(ctx);
EnqueueCompactionIfNeeded(ctx);
State->FinishLoadState();
LOG_INFO(ctx, TBlockStoreComponents::PARTITION,
"[%lu] State initialization finished",
TabletID());
}
void TPartitionActor::Suicide(const TActorContext& ctx)
{
NCloud::Send<TEvents::TEvPoisonPill>(ctx, Tablet());
BecomeAux(ctx, STATE_ZOMBIE);
}
void TPartitionActor::OnDetach(const TActorContext& ctx)
{
Counters = nullptr;
BeforeDie(ctx);
Die(ctx);
}
void TPartitionActor::OnTabletDead(
TEvTablet::TEvTabletDead::TPtr& ev,
const TActorContext& ctx)
{
Y_UNUSED(ev);
BeforeDie(ctx);
Die(ctx);
}
void TPartitionActor::BeforeDie(const TActorContext& ctx)
{
TerminateTransactions(ctx);
KillActors(ctx);
ClearWriteQueue(ctx);
CancelPendingRequests(ctx, PendingRequests);
}
void TPartitionActor::KillActors(const TActorContext& ctx)
{
for (const auto& actor: Actors) {
NCloud::Send<TEvents::TEvPoisonPill>(ctx, actor);
}
}
void TPartitionActor::AddTransaction(
TRequestInfo& transaction,
TRequestInfo::TCancelRoutine cancelRoutine)
{
transaction.CancelRoutine = cancelRoutine;
transaction.Ref();
STORAGE_VERIFY(
transaction.Empty(),
TWellKnownEntityTypes::TABLET,
TabletID());
ActiveTransactions.PushBack(&transaction);
}
void TPartitionActor::RemoveTransaction(TRequestInfo& requestInfo)
{
STORAGE_VERIFY(
!requestInfo.Empty(),
TWellKnownEntityTypes::TABLET,
TabletID());
requestInfo.Unlink();
STORAGE_VERIFY(
requestInfo.RefCount() > 1,
TWellKnownEntityTypes::TABLET,
TabletID());
requestInfo.UnRef();
}
void TPartitionActor::ReleaseTransactions()
{
while (ActiveTransactions) {
TRequestInfo* requestInfo = ActiveTransactions.PopFront();
STORAGE_VERIFY(
requestInfo->RefCount() >= 1,
TWellKnownEntityTypes::TABLET,
TabletID());
requestInfo->UnRef();
}
}
void TPartitionActor::TerminateTransactions(const TActorContext& ctx)
{
while (ActiveTransactions) {
auto* requestInfo = ActiveTransactions.PopFront();
STORAGE_VERIFY(
requestInfo->RefCount() >= 1,
TWellKnownEntityTypes::TABLET,
TabletID());
requestInfo->CancelRequest(ctx);
requestInfo->UnRef();
}
}
void TPartitionActor::ProcessIOQueue(const TActorContext& ctx, ui32 channel)
{
while (auto requestActor = State->DequeueIORequest(channel)) {
auto actorId = NCloud::Register(ctx, std::move(requestActor));
Actors.insert(actorId);
}
}
void TPartitionActor::ProcessCCCRequestQueue(
const TActorContext& ctx)
{
if (State->HasCCCRequestInProgress()) {
// already in progress
return;
}
auto& queue = State->GetCCCRequestQueue();
if (queue.empty()) {
// nothing to process
return;
}
auto& front = queue.front();
if (State->HasFreshBlocksInFlightUntil(front.CommitId)) {
// wait for inflight fresh to complete
return;
}
if (front.OnStartProcessing) {
front.OnStartProcessing(ctx);
}
auto tx = std::move(front.Tx);
queue.pop_front();
State->StartProcessingCCCRequest();
ExecuteTx(ctx, std::move(tx));
}
bool TPartitionActor::InitReadWriteBlockRange(
ui64 blockIndex,
ui32 blockCount,
TBlockRange64* range) const
{
if (!blockCount) {
return false;
}
*range = TBlockRange64::WithLength(blockIndex, blockCount);
return
State->CheckBlockRange(*range) &&
(range->Size() <= Config->GetMaxReadWriteRangeSize() / State->GetBlockSize());
}
bool TPartitionActor::InitChangedBlocksRange(
ui64 blockIndex,
ui32 blockCount,
TBlockRange64* range) const
{
if (!blockCount) {
return false;
}
*range = TBlockRange64::WithLength(blockIndex, blockCount);
return
State->CheckBlockRange(*range) &&
(range->Size() <= Config->GetMaxChangedBlocksRangeBlocksCount());
}
void TPartitionActor::UpdateChannelPermissions(
const TActorContext& ctx,
ui32 channel,
EChannelPermissions permissions)
{
if (State->UpdatePermissions(channel, permissions)) {
SendBackpressureReport(ctx);
}
}
void TPartitionActor::SendBackpressureReport(const TActorContext& ctx) const
{
NCloud::Send(
ctx,
LauncherID(),
std::make_unique<TEvPartition::TEvBackpressureReport>(
MakeIntrusive<TCallContext>(),
State->CalculateCurrentBackpressure()
)
);
}
////////////////////////////////////////////////////////////////////////////////
ui64 TPartitionActor::CalcChannelHistorySize() const
{
ui64 sum = 0;
for (const auto& ch: Info()->Channels) {
sum += ch.History.size();
}
return sum;
}
void TPartitionActor::UpdateExecutorStats(const TActorContext& ctx)
{
auto& metrics = *Executor()->GetResourceMetrics();
metrics.TryUpdate(ctx);
}
void TPartitionActor::UpdateNetworkStats(const TActorContext& ctx, ui64 value)
{
auto& metrics = Executor()->GetResourceMetrics()->Network;
metrics.Increment(value, ctx.Now());
}
void TPartitionActor::UpdateStorageStats(const TActorContext& ctx, i64 value)
{
Y_UNUSED(ctx);
auto& metrics = Executor()->GetResourceMetrics()->StorageUser;
metrics.Increment(value);
}
void TPartitionActor::UpdateCPUUsageStats(const TActorContext& ctx, TDuration value)
{
UserCPUConsumption += value.MicroSeconds();
auto& metrics = Executor()->GetResourceMetrics()->CPU;
metrics.Increment(value.MicroSeconds(), ctx.Now());
}
void TPartitionActor::UpdateWriteThroughput(
const TActorContext& ctx,
const NKikimr::NMetrics::TChannel& channel,
const NKikimr::NMetrics::TGroupId& group,
ui64 value)
{
auto& metrics = Executor()->GetResourceMetrics()->WriteThroughput[
std::make_pair(channel, group)];
metrics.Increment(value, ctx.Now());
auto& iops = Executor()->GetResourceMetrics()->WriteIops[
std::make_pair(channel, group)];
iops.Increment(1, ctx.Now());
}
void TPartitionActor::UpdateReadThroughput(
const TActorContext& ctx,
const NKikimr::NMetrics::TChannel& channel,
const NKikimr::NMetrics::TGroupId& group,
ui64 value,
bool isOverlayDisk)
{
if (isOverlayDisk) {
const TString& overlayKind = Config->GetCommonOverlayPrefixPoolKind();
auto& tabletOps = OverlayMetrics.PoolKind2TabletOps
[overlayKind][std::make_pair(channel, group)];
tabletOps.ReadOperations.ByteCount += value;
tabletOps.ReadOperations.Iops += 1;
} else {
auto& metrics = Executor()->GetResourceMetrics()->ReadThroughput[
std::make_pair(channel, group)];
metrics.Increment(value, ctx.Now());
auto& iops = Executor()->GetResourceMetrics()->ReadIops[
std::make_pair(channel, group)];
iops.Increment(1, ctx.Now());
}
}
////////////////////////////////////////////////////////////////////////////////
void TPartitionActor::HandlePoisonPill(
const TEvents::TEvPoisonPill::TPtr& ev,
const TActorContext& ctx)
{
Y_UNUSED(ev);
LOG_INFO(ctx, TBlockStoreComponents::PARTITION,
"[%lu] Stop tablet because of PoisonPill request",
TabletID());
Suicide(ctx);
}
void TPartitionActor::HandleUpdateCounters(
const TEvPartitionPrivate::TEvUpdateCounters::TPtr& ev,
const TActorContext& ctx)
{
Y_UNUSED(ev);
UpdateCountersScheduled = false;
UpdateCounters(ctx);
ScheduleCountersUpdate(ctx);
}
void TPartitionActor::HandleUpdateYellowState(
const TEvPartitionPrivate::TEvUpdateYellowState::TPtr& ev,
const TActorContext& ctx)
{
Y_UNUSED(ev);
UpdateYellowStateScheduled = false;
UpdateYellowState(ctx);
}
void TPartitionActor::HandleSendBackpressureReport(
const TEvPartitionPrivate::TEvSendBackpressureReport::TPtr& ev,
const TActorContext& ctx)
{
Y_UNUSED(ev);
if (State) {
SendBackpressureReport(ctx);
}
ctx.Schedule(BackpressureReportSendInterval,
new TEvPartitionPrivate::TEvSendBackpressureReport());
}
void TPartitionActor::RebootPartitionOnCommitIdOverflow(
const TActorContext& ctx,
const TStringBuf& requestName)
{
LOG_ERROR_S(ctx, TBlockStoreComponents::PARTITION,
"[" << TabletID() << "]"
<< " CommitId overflow in " << requestName << ". Restarting partition");
ReportTabletCommitIdOverflow();
Suicide(ctx);
}
void TPartitionActor::RebootPartitionOnCollectCounterOverflow(
const TActorContext& ctx,
const TStringBuf& requestName)
{
LOG_ERROR_S(ctx, TBlockStoreComponents::PARTITION,
"[" << TabletID() << "]"
<< " CollectCounter overflow in " << requestName << ". Restarting partition");
ReportTabletCollectCounterOverflow();
Suicide(ctx);
}
void TPartitionActor::HandleCheckBlobstorageStatusResult(
const TEvTablet::TEvCheckBlobstorageStatusResult::TPtr& ev,
const TActorContext& ctx)
{
const auto* msg = ev->Get();
bool anyChannelYellow = false;
for (const auto& channel: Info()->Channels) {
bool diskSpaceYellowMove = false;
bool diskSpaceYellowStop = false;
if (auto latestEntry = channel.LatestEntry()) {
diskSpaceYellowMove = IsIn(msg->LightYellowMoveGroups, latestEntry->GroupID);
diskSpaceYellowStop = IsIn(msg->YellowStopGroups, latestEntry->GroupID);
}
EChannelPermissions permissions = EChannelPermission::SystemWritesAllowed;
if (!diskSpaceYellowStop) {
permissions |= EChannelPermission::UserWritesAllowed;
}
UpdateChannelPermissions(ctx, channel.Channel, permissions);
anyChannelYellow |= diskSpaceYellowMove;
}
if (anyChannelYellow) {
ScheduleYellowStateUpdate(ctx);
}
}
void TPartitionActor::HandleReassignTabletResponse(
const TEvHiveProxy::TEvReassignTabletResponse::TPtr& ev,
const TActorContext& ctx)
{
const auto* msg = ev->Get();
if (FAILED(msg->GetStatus())) {
LOG_WARN_S(ctx, TBlockStoreComponents::PARTITION,
"[" << TabletID() << "]"
<< " Reassign request failed");
ReassignRequestSentTs = TInstant::Zero();
}
}
void TPartitionActor::HandleDrain(
const TEvPartition::TEvDrainRequest::TPtr& ev,
const TActorContext& ctx)
{
DrainActorCompanion.HandleDrain(ev, ctx);
}
////////////////////////////////////////////////////////////////////////////////
#define BLOCKSTORE_HANDLE_UNIMPLEMENTED_REQUEST(name, ns) \
void TPartitionActor::Handle##name( \
const ns::TEv##name##Request::TPtr& ev, \
const TActorContext& ctx) \
{ \
RejectUnimplementedRequest<ns::T##name##Method>(ev, ctx); \
} \
\
// BLOCKSTORE_HANDLE_UNIMPLEMENTED_REQUEST
BLOCKSTORE_HANDLE_UNIMPLEMENTED_REQUEST(RebuildMetadata, TEvVolume);
BLOCKSTORE_HANDLE_UNIMPLEMENTED_REQUEST(GetRebuildMetadataStatus, TEvVolume);
BLOCKSTORE_HANDLE_UNIMPLEMENTED_REQUEST(ScanDisk, TEvVolume);
BLOCKSTORE_HANDLE_UNIMPLEMENTED_REQUEST(GetScanDiskStatus, TEvVolume);
////////////////////////////////////////////////////////////////////////////////
bool TPartitionActor::HandleRequests(STFUNC_SIG)
{
switch (ev->GetTypeRewrite()) {
BLOCKSTORE_PARTITION_REQUESTS(BLOCKSTORE_HANDLE_REQUEST, TEvPartition)
BLOCKSTORE_PARTITION2_REQUESTS_PRIVATE(
BLOCKSTORE_HANDLE_REQUEST,
TEvPartitionPrivate)
BLOCKSTORE_PARTITION_COMMON_REQUESTS_PRIVATE(
BLOCKSTORE_HANDLE_REQUEST,
TEvPartitionCommonPrivate)
BLOCKSTORE_PARTITION_REQUESTS_FWD_SERVICE(
BLOCKSTORE_HANDLE_REQUEST,
TEvService)
BLOCKSTORE_PARTITION_REQUESTS_FWD_VOLUME(
BLOCKSTORE_HANDLE_REQUEST,
TEvVolume)
default:
return false;
}
return true;
}
bool TPartitionActor::RejectRequests(STFUNC_SIG)
{
switch (ev->GetTypeRewrite()) {
BLOCKSTORE_PARTITION_REQUESTS(BLOCKSTORE_REJECT_REQUEST, TEvPartition)
BLOCKSTORE_PARTITION2_REQUESTS_PRIVATE(
BLOCKSTORE_REJECT_REQUEST,
TEvPartitionPrivate)
BLOCKSTORE_PARTITION_COMMON_REQUESTS_PRIVATE(
BLOCKSTORE_REJECT_REQUEST,
TEvPartitionCommonPrivate)
BLOCKSTORE_PARTITION_REQUESTS_FWD_SERVICE(
BLOCKSTORE_REJECT_REQUEST,
TEvService)
BLOCKSTORE_PARTITION_REQUESTS_FWD_VOLUME(
BLOCKSTORE_REJECT_REQUEST,
TEvVolume)
default:
return false;
}
return true;
}
////////////////////////////////////////////////////////////////////////////////
STFUNC(TPartitionActor::StateBoot)
{
UpdateActorStatsSampled(ActorContext());
switch (ev->GetTypeRewrite()) {
HFunc(TEvents::TEvPoisonPill, HandlePoisonPill);
IgnoreFunc(TEvTabletPipe::TEvServerConnected);
IgnoreFunc(TEvTabletPipe::TEvServerDisconnected);
HFunc(TEvPartitionPrivate::TEvUpdateCounters, HandleUpdateCounters);
HFunc(TEvPartitionPrivate::TEvSendBackpressureReport, HandleSendBackpressureReport);
BLOCKSTORE_HANDLE_REQUEST(WaitReady, TEvPartition)
IgnoreFunc(TEvHiveProxy::TEvReassignTabletResponse);
default:
if (!RejectRequests(ev)) {
StateInitImpl(ev, SelfId());
}
break;
}
}
STFUNC(TPartitionActor::StateInit)
{
UpdateActorStatsSampled(ActorContext());
switch (ev->GetTypeRewrite()) {
HFunc(TEvents::TEvPoisonPill, HandlePoisonPill);
IgnoreFunc(TEvTabletPipe::TEvServerConnected);
IgnoreFunc(TEvTabletPipe::TEvServerDisconnected);
HFunc(TEvPartitionPrivate::TEvUpdateCounters, HandleUpdateCounters);
HFunc(TEvPartitionPrivate::TEvSendBackpressureReport, HandleSendBackpressureReport);
HFunc(TEvPartitionCommonPrivate::TEvLoadFreshBlobsCompleted, HandleLoadFreshBlobsCompleted);
HFunc(TEvPartitionPrivate::TEvInitFreshZonesCompleted, HandleInitFreshZonesCompleted);
BLOCKSTORE_HANDLE_REQUEST(WaitReady, TEvPartition)
BLOCKSTORE_HANDLE_REQUEST(InitIndex, TEvPartitionPrivate)
IgnoreFunc(TEvHiveProxy::TEvReassignTabletResponse);
default:
if (!RejectRequests(ev) && !HandleDefaultEvents(ev, SelfId())) {
HandleUnexpectedEvent(ev, TBlockStoreComponents::PARTITION);
}
break;
}
}
STFUNC(TPartitionActor::StateWork)
{
UpdateActorStatsSampled(ActorContext());
switch (ev->GetTypeRewrite()) {
HFunc(TEvents::TEvPoisonPill, HandlePoisonPill);
HFunc(TEvTablet::TEvCheckBlobstorageStatusResult, HandleCheckBlobstorageStatusResult);
IgnoreFunc(TEvTabletPipe::TEvServerConnected);
IgnoreFunc(TEvTabletPipe::TEvServerDisconnected);
HFunc(TEvPartitionPrivate::TEvUpdateCounters, HandleUpdateCounters);
HFunc(TEvPartitionPrivate::TEvUpdateYellowState, HandleUpdateYellowState);
HFunc(TEvPartitionPrivate::TEvSendBackpressureReport, HandleSendBackpressureReport);
HFunc(TEvPartitionPrivate::TEvProcessWriteQueue, HandleProcessWriteQueue);
HFunc(TEvPartitionPrivate::TEvReadBlobCompleted, HandleReadBlobCompleted);
HFunc(TEvPartitionPrivate::TEvWriteBlobCompleted, HandleWriteBlobCompleted);
HFunc(TEvPartitionPrivate::TEvReadBlocksCompleted, HandleReadBlocksCompleted);
HFunc(TEvPartitionPrivate::TEvWriteBlocksCompleted, HandleWriteBlocksCompleted);
HFunc(TEvPartitionPrivate::TEvZeroBlocksCompleted, HandleZeroBlocksCompleted);
HFunc(TEvPartitionPrivate::TEvFlushCompleted, HandleFlushCompleted);
HFunc(TEvPartitionPrivate::TEvCompactionCompleted, HandleCompactionCompleted);
HFunc(TEvPartitionPrivate::TEvCollectGarbageCompleted, HandleCollectGarbageCompleted);
HFunc(TEvPartitionPrivate::TEvForcedCompactionCompleted, HandleForcedCompactionCompleted);
HFunc(TEvPartitionCommonPrivate::TEvTrimFreshLogCompleted, HandleTrimFreshLogCompleted);
HFunc(TEvPartitionPrivate::TEvGetChangedBlocksCompleted, HandleGetChangedBlocksCompleted);
HFunc(TEvHiveProxy::TEvReassignTabletResponse, HandleReassignTabletResponse);
IgnoreFunc(TEvPartitionPrivate::TEvCleanupResponse);
IgnoreFunc(TEvPartitionPrivate::TEvCollectGarbageResponse);
IgnoreFunc(TEvPartitionPrivate::TEvCompactionResponse);
IgnoreFunc(TEvPartitionPrivate::TEvUpdateIndexStructuresResponse);
IgnoreFunc(TEvPartitionPrivate::TEvFlushResponse);
IgnoreFunc(TEvPartitionCommonPrivate::TEvTrimFreshLogResponse);
default:
if (!HandleRequests(ev) && !HandleDefaultEvents(ev, SelfId())) {
HandleUnexpectedEvent(ev, TBlockStoreComponents::PARTITION);
}
break;
}
}
STFUNC(TPartitionActor::StateZombie)
{
UpdateActorStatsSampled(ActorContext());
switch (ev->GetTypeRewrite()) {
HFunc(TEvTablet::TEvTabletDead, HandleTabletDead);
IgnoreFunc(TEvTablet::TEvTabletStop);
IgnoreFunc(TEvents::TEvPoisonPill);
IgnoreFunc(TEvTabletPipe::TEvServerConnected);
IgnoreFunc(TEvTabletPipe::TEvServerDisconnected);
IgnoreFunc(TEvPartitionPrivate::TEvUpdateCounters);
IgnoreFunc(TEvPartitionPrivate::TEvUpdateYellowState);
IgnoreFunc(TEvPartitionPrivate::TEvSendBackpressureReport);
IgnoreFunc(TEvPartitionPrivate::TEvProcessWriteQueue);
IgnoreFunc(TEvPartitionPrivate::TEvReadBlobCompleted);
IgnoreFunc(TEvPartitionPrivate::TEvWriteBlobCompleted);
IgnoreFunc(TEvPartitionPrivate::TEvReadBlocksCompleted);
IgnoreFunc(TEvPartitionPrivate::TEvWriteBlocksCompleted);
IgnoreFunc(TEvPartitionPrivate::TEvZeroBlocksCompleted);
IgnoreFunc(TEvPartitionPrivate::TEvFlushCompleted);
IgnoreFunc(TEvPartitionPrivate::TEvCompactionCompleted);
IgnoreFunc(TEvPartitionPrivate::TEvCollectGarbageCompleted);
IgnoreFunc(TEvPartitionPrivate::TEvForcedCompactionCompleted);
IgnoreFunc(TEvPartitionPrivate::TEvGetChangedBlocksCompleted);
IgnoreFunc(TEvPartitionPrivate::TEvCleanupResponse);
IgnoreFunc(TEvPartitionPrivate::TEvCollectGarbageResponse);
IgnoreFunc(TEvPartitionPrivate::TEvCompactionResponse);
IgnoreFunc(TEvPartitionPrivate::TEvUpdateIndexStructuresResponse);
IgnoreFunc(TEvPartitionPrivate::TEvFlushResponse);
IgnoreFunc(TEvHiveProxy::TEvReassignTabletResponse);
default:
if (!RejectRequests(ev)) {
HandleUnexpectedEvent(ev, TBlockStoreComponents::PARTITION);
}
break;
}
}
////////////////////////////////////////////////////////////////////////////////
void TPartitionActor::HandleGetPartitionInfo(
const TEvVolume::TEvGetPartitionInfoRequest::TPtr& ev,
const TActorContext& ctx)
{
LOG_DEBUG(ctx, TBlockStoreComponents::PARTITION, "GetPartitionInfo request");
auto json = State->AsJson();
auto response = std::make_unique<TEvVolume::TEvGetPartitionInfoResponse>();
response->Record.SetPayload(json.GetStringRobust());
NCloud::Send(ctx, ev->Sender, std::move(response), ev->Cookie);
}
////////////////////////////////////////////////////////////////////////////////
} // namespace NCloud::NBlockStore::NStorage::NPartition2