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
|
#include "tablet_helpers.h"
#include <ydb/core/tablet_flat/tablet_flat_executed.h>
#include <ydb/core/tablet_flat/flat_dbase_scheme.h>
#include <ydb/core/tablet_flat/flat_cxx_database.h>
#include <ydb/core/engine/minikql/flat_local_tx_factory.h>
#include <ydb/core/base/appdata.h>
#include <library/cpp/actors/core/hfunc.h>
namespace NKikimr {
namespace {
class TDummyFlatTablet : public TActor<TDummyFlatTablet>, public NTabletFlatExecutor::TTabletExecutedFlat {
struct Schema : NIceDb::Schema {
struct Snaps : Table<1> {
struct SourceTableId : Column<1, NScheme::NTypeIds::Uint32> {};
struct DestinationTablet : Column<2, NScheme::NTypeIds::Uint64> {};
struct Delivered : Column<3, NScheme::NTypeIds::Bool> {};
using TKey = TableKey<SourceTableId, DestinationTablet>;
using TColumns = TableColumns<SourceTableId, DestinationTablet, Delivered>;
};
struct t_by_ui64 : Table<32> {
struct key : Column<32, NScheme::NTypeIds::Uint64> {};
struct v_bytes : Column<33, NScheme::NTypeIds::String4k> {};
struct v_ui64 : Column<34, NScheme::NTypeIds::Uint64> {};
using TKey = TableKey<key>;
using TColumns = TableColumns<key, v_bytes, v_ui64>;
};
struct t_by_bytes : Table<33> {
struct key : Column<32, NScheme::NTypeIds::String4k> {};
struct v_bytes : Column<33, NScheme::NTypeIds::String4k> {};
struct v_ui64 : Column<34, NScheme::NTypeIds::Uint64> {};
using TKey = TableKey<key>;
using TColumns = TableColumns<key, v_bytes, v_ui64>;
};
using TTables = SchemaTables<Snaps, t_by_ui64, t_by_bytes>;
};
struct TTxSchemeInit : public NTabletFlatExecutor::ITransaction {
TDummyFlatTablet * const Self;
TTxSchemeInit(TDummyFlatTablet *self)
: Self(self)
{}
bool Execute(TTransactionContext &txc, const TActorContext &ctx) override {
Y_UNUSED(ctx);
NIceDb::TNiceDb(txc.DB).Materialize<Schema>();
return true;
}
void Complete(const TActorContext &ctx) override {
Self->Execute(new TTxInit(Self), ctx);
}
};
struct TTxInit : public NTabletFlatExecutor::ITransaction {
TDummyFlatTablet * const Self;
TTxInit(TDummyFlatTablet *self)
: Self(self)
{}
bool Execute(TTransactionContext &txc, const TActorContext &ctx) override {
Y_UNUSED(txc);
Y_UNUSED(ctx);
return true;
}
void Complete(const TActorContext &ctx) override {
Self->SignalTabletActive(ctx);
}
};
friend struct TTxSchemeInit;
friend struct TTxInit;
void Handle(TEvents::TEvPoisonPill::TPtr &ev, const TActorContext &ctx) {
Y_UNUSED(ev);
Become(&TThis::StateBroken);
ctx.Send(Tablet(), new TEvents::TEvPoisonPill);
}
void OnActivateExecutor(const TActorContext &ctx) override {
Become(&TThis::StateWork);
if (Executor()->GetStats().IsFollower)
SignalTabletActive(ctx);
else
Execute(new TTxSchemeInit(this), ctx);
}
void OnDetach(const TActorContext &ctx) override {
Die(ctx);
}
void OnTabletDead(TEvTablet::TEvTabletDead::TPtr &ev, const TActorContext &ctx) override {
Y_UNUSED(ev);
Die(ctx);
}
void DefaultSignalTabletActive(const TActorContext &ctx) override {
Y_UNUSED(ctx);
}
public:
static constexpr NKikimrServices::TActivity::EType ActorActivityType() {
return NKikimrServices::TActivity::TEST_ACTOR_RUNTIME;
}
TDummyFlatTablet(const TActorId &tablet, TTabletStorageInfo *info)
: TActor(&TThis::StateInit)
, TTabletExecutedFlat(info, tablet, new NMiniKQL::TMiniKQLFactory)
{}
STFUNC(StateInit) {
StateInitImpl(ev, ctx);
}
STFUNC(StateWork) {
switch (ev->GetTypeRewrite()) {
HFunc(TEvents::TEvPoisonPill, Handle);
default:
HandleDefaultEvents(ev, ctx);
break;
}
}
STFUNC(StateBroken) {
switch (ev->GetTypeRewrite()) {
HFunc(TEvTablet::TEvTabletDead, HandleTabletDead)
}
}
};
} // namespace
IActor* CreateFlatDummyTablet(const TActorId &tablet, TTabletStorageInfo *info) {
return new TDummyFlatTablet(tablet, info);
}}
|