2
2
#include " flat_executor.h"
3
3
#include " flat_executor_counters.h"
4
4
#include < ydb/core/base/appdata.h>
5
+ #include < ydb/core/base/counters.h>
5
6
#include < library/cpp/monlib/service/pages/templates.h>
6
7
7
8
namespace NKikimr {
@@ -16,6 +17,28 @@ TTabletExecutedFlat::TTabletExecutedFlat(TTabletStorageInfo *info, const TActorI
16
17
, StartTime0(TAppData::TimeProvider->Now ())
17
18
{}
18
19
20
+ bool TTabletExecutedFlat::OnUnhandledException (const std::exception & e) {
21
+ if (AppData ()->FeatureFlags .GetEnableTabletRestartOnUnhandledExceptions ()) {
22
+ // Tablets have a weird inheritence where subclass is always an actor,
23
+ // but we don't know the exact type at compile time. This dynamic_cast
24
+ // is expected to always succeed.
25
+ if (auto * actor = dynamic_cast <IActor*>(this )) {
26
+ auto ctx = TActivationContext::ActorContextFor (actor->SelfId ());
27
+ LOG_CRIT_S (*TlsActivationContext, NKikimrServices::TABLET_EXECUTOR,
28
+ " Tablet " << TabletID () << " unhandled exception " << TypeName (e) << " : " << e.what ()
29
+ << ' \n ' << TBackTrace::FromCurrentException ().PrintToString ());
30
+
31
+ GetServiceCounters (AppData (ctx)->Counters , " tablets" )->GetCounter (" alerts_broken" , true )->Inc ();
32
+
33
+ HandlePoison (ctx);
34
+ return true ;
35
+ }
36
+ }
37
+
38
+ // Exception will propagate and cause the process to crash
39
+ return false ;
40
+ }
41
+
19
42
IExecutor* TTabletExecutedFlat::CreateExecutor (const TActorContext &ctx) {
20
43
if (!Executor ()) {
21
44
IActor *executor = NFlatExecutorSetup::CreateExecutor (this , ctx.SelfID );
@@ -123,9 +146,9 @@ void TTabletExecutedFlat::OnTabletStop(TEvTablet::TEvTabletStop::TPtr &ev, const
123
146
ctx.Send (Tablet (), new TEvTablet::TEvTabletStopped ());
124
147
}
125
148
126
- void TTabletExecutedFlat::HandlePoison (const TActorContext & ctx) {
149
+ void TTabletExecutedFlat::HandlePoison (const TActorContext& ctx) {
127
150
if (Executor0) {
128
- Executor0->DetachTablet (ExecutorCtx (ctx) );
151
+ Executor0->DetachTablet ();
129
152
Executor0 = nullptr ;
130
153
}
131
154
@@ -142,7 +165,7 @@ void TTabletExecutedFlat::HandleTabletStop(TEvTablet::TEvTabletStop::TPtr &ev, c
142
165
143
166
void TTabletExecutedFlat::HandleTabletDead (TEvTablet::TEvTabletDead::TPtr &ev, const TActorContext &ctx) {
144
167
if (Executor0) {
145
- Executor0->DetachTablet (ExecutorCtx (ctx) );
168
+ Executor0->DetachTablet ();
146
169
Executor0 = nullptr ;
147
170
}
148
171
0 commit comments