1
1
#include " schemeshard__operation_common.h"
2
- #include " schemeshard__operation_common_streaming_query.h"
3
2
#include " schemeshard_impl.h"
4
3
4
+ #define LOG_I (stream ) LOG_INFO_S(context.Ctx, NKikimrServices::FLAT_TX_SCHEMESHARD, " [" << context.SS->TabletID () << "] " << stream)
5
+ #define LOG_N (stream ) LOG_NOTICE_S(context.Ctx, NKikimrServices::FLAT_TX_SCHEMESHARD, " [" << context.SS->TabletID () << "] " << stream)
6
+ #define RETURN_RESULT_UNLESS (x ) if (!(x)) return result;
7
+
5
8
namespace NKikimr ::NSchemeShard {
6
9
7
10
namespace NStreamingQuery {
@@ -24,13 +27,9 @@ class TPropose : public TSubOperationState {
24
27
25
28
const TPathId& pathId = txState->TargetPathId ;
26
29
const TPath& path = TPath::Init (pathId, context.SS );
27
- const TPathElement::TPtr pathPtr = context.SS ->PathsById .at (pathId);
28
-
29
30
NIceDb::TNiceDb db (context.GetDB ());
30
31
31
32
IncParentDirAlterVersionWithRepublish (OperationId, path, context);
32
- context.SS ->ClearDescribePathCaches (pathPtr);
33
- context.OnComplete .PublishToSchemeBoard (OperationId, pathId);
34
33
35
34
context.SS ->ChangeTxState (db, OperationId, TTxState::Done);
36
35
return true ;
@@ -57,6 +56,8 @@ class TPropose : public TSubOperationState {
57
56
};
58
57
59
58
class TAlterStreamingQuery : public TSubOperation {
59
+ static constexpr ui64 MAX_PROTOBUF_SIZE = 2_MB;
60
+
60
61
static TTxState::ETxState NextState () {
61
62
return TTxState::Propose;
62
63
}
@@ -83,9 +84,25 @@ class TAlterStreamingQuery : public TSubOperation {
83
84
}
84
85
}
85
86
87
+ static bool IsParentPathValid (const THolder<TProposeResponse>& result, const TPath& parentPath) {
88
+ const auto checks = parentPath.Check ();
89
+ checks.NotUnderDomainUpgrade ()
90
+ .IsAtLocalSchemeShard ()
91
+ .IsResolved ()
92
+ .NotDeleted ()
93
+ .NotUnderDeleting ()
94
+ .IsCommonSensePath ()
95
+ .IsLikeDirectory ();
96
+
97
+ if (!checks) {
98
+ result->SetError (checks.GetStatus (), checks.GetError ());
99
+ }
100
+
101
+ return static_cast <bool >(checks);
102
+ }
103
+
86
104
static bool IsDestinationPathValid (const THolder<TProposeResponse>& result, const TPath& dstPath) {
87
105
const auto checks = dstPath.Check ();
88
-
89
106
checks.IsAtLocalSchemeShard ()
90
107
.IsResolved ()
91
108
.NotUnderDeleting ()
@@ -103,13 +120,78 @@ class TAlterStreamingQuery : public TSubOperation {
103
120
return static_cast <bool >(checks);
104
121
}
105
122
106
- TPathElement::TPtr ReplaceStreamingQueryPathElement (const TPath& dstPath) const {
123
+ bool IsApplyIfChecksPassed (const THolder<TProposeResponse>& result, const TOperationContext& context) const {
124
+ if (TString errorStr; !context.SS ->CheckApplyIf (Transaction, errorStr)) {
125
+ result->SetError (NKikimrScheme::StatusPreconditionFailed, errorStr);
126
+ return false ;
127
+ }
128
+
129
+ return true ;
130
+ }
131
+
132
+ TStreamingQueryInfo::TPtr GetAlteredQueryInfo (const TPath& dstPath, const TOperationContext& context) const {
133
+ const auto & oldStreamingQueryInfo = context.SS ->StreamingQueries .Value (dstPath->PathId , nullptr );
134
+ Y_ABORT_UNLESS (oldStreamingQueryInfo);
135
+ auto streamingQueryInfo = MakeIntrusive<TStreamingQueryInfo>(TStreamingQueryInfo{
136
+ .AlterVersion = oldStreamingQueryInfo->AlterVersion + 1 ,
137
+ .Properties = Transaction.GetCreateStreamingQuery ().GetProperties (),
138
+ });
139
+
140
+ auto & properties = *streamingQueryInfo->Properties .MutableProperties ();
141
+ for (const auto & [property, value] : oldStreamingQueryInfo->Properties .GetProperties ()) {
142
+ properties.emplace (property, value);
143
+ }
144
+
145
+ return streamingQueryInfo;
146
+ }
147
+
148
+ bool IsDescriptionValid (const THolder<TProposeResponse>& result, TStreamingQueryInfo::TPtr queryInfo) const {
149
+ if (const ui64 propertiesSize = queryInfo->Properties .ByteSizeLong (); propertiesSize > MAX_PROTOBUF_SIZE) {
150
+ result->SetError (NKikimrScheme::StatusSchemeError, TStringBuilder () << " Maximum size of properties must be less or equal equal to " << MAX_PROTOBUF_SIZE << " but got " << propertiesSize << " after alter" );
151
+ return false ;
152
+ }
153
+
154
+ return true ;
155
+ }
156
+
157
+ void PersistAlterStreamingQuery (const TPath& dstPath, const TOperationContext& context) const {
158
+ const TPathId& pathId = dstPath.Base ()->PathId ;
159
+
160
+ context.MemChanges .GrabPath (context.SS , dstPath->ParentPathId );
161
+ context.MemChanges .GrabStreamingQuery (context.SS , pathId);
162
+ context.MemChanges .GrabNewTxState (context.SS , OperationId);
163
+
164
+ context.DbChanges .PersistPath (pathId);
165
+ context.DbChanges .PersistStreamingQuery (pathId);
166
+ context.DbChanges .PersistTxState (OperationId);
167
+ }
168
+
169
+ void CreateTransaction (const TPath& dstPath, const TOperationContext& context) const {
170
+ Y_ABORT_UNLESS (!context.SS ->FindTx (OperationId));
171
+
172
+ TTxState& txState = context.SS ->CreateTx (OperationId, TTxState::TxAlterStreamingQuery, dstPath.Base ()->PathId );
173
+ txState.Shards .clear ();
174
+ txState.State = TTxState::Propose;
175
+ txState.MinStep = TStepId (1 );
176
+ context.OnComplete .ActivateTx (OperationId);
177
+
178
+ if (const auto parent = dstPath.Parent ().Base (); parent->HasActiveChanges ()) {
179
+ const TTxId parentTxId = parent->PlannedToCreate () ? parent->CreateTxId : parent->LastTxId ;
180
+ context.OnComplete .Dependence (parentTxId, OperationId.GetTxId ());
181
+ }
182
+ }
183
+
184
+ void AlterStreamingQueryPathElement (const TPath& dstPath, TStreamingQueryInfo::TPtr queryInfo, const TOperationContext& context) const {
107
185
TPathElement::TPtr streamingQuery = dstPath.Base ();
108
186
109
187
streamingQuery->PathState = TPathElement::EPathState::EPathStateAlter;
110
188
streamingQuery->LastTxId = OperationId.GetTxId ();
111
189
112
- return streamingQuery;
190
+ if (const auto & acl = Transaction.GetModifyACL ().GetDiffACL ()) {
191
+ streamingQuery->ApplyACL (acl);
192
+ }
193
+
194
+ context.SS ->StreamingQueries [dstPath.Base ()->PathId ] = queryInfo;
113
195
}
114
196
115
197
public:
@@ -128,36 +210,27 @@ class TAlterStreamingQuery : public TSubOperation {
128
210
static_cast <ui64>(context.SS ->SelfTabletId ()));
129
211
130
212
const TPath& parentPath = TPath::Resolve (parentPathStr, context.SS );
131
- RETURN_RESULT_UNLESS (IsParentPathValid (result, parentPath, /* isCreate */ false ));
213
+ RETURN_RESULT_UNLESS (IsParentPathValid (result, parentPath));
132
214
133
215
const TPath& dstPath = parentPath.Child (name);
134
216
RETURN_RESULT_UNLESS (IsDestinationPathValid (result, dstPath));
135
- RETURN_RESULT_UNLESS (IsApplyIfChecksPassed (result, Transaction, context));
136
- RETURN_RESULT_UNLESS (IsDescriptionValid (result, streamingQueryDescription));
137
-
138
- const auto & oldStreamingQueryInfo = context.SS ->StreamingQueries .Value (dstPath->PathId , nullptr );
139
- Y_ABORT_UNLESS (oldStreamingQueryInfo);
140
- const auto streamingQueryInfo = CreateModifyStreamingQuery (streamingQueryDescription, oldStreamingQueryInfo);
141
- Y_ABORT_UNLESS (streamingQueryInfo);
217
+ RETURN_RESULT_UNLESS (IsApplyIfChecksPassed (result, context));
218
+ const auto queryInfo = GetAlteredQueryInfo (dstPath, context);
219
+ RETURN_RESULT_UNLESS (IsDescriptionValid (result, queryInfo));
142
220
143
221
result->SetPathId (dstPath.Base ()->PathId .LocalPathId );
144
- const TPathElement::TPtr streamingQuery = ReplaceStreamingQueryPathElement (dstPath);
145
- CreateTransaction (OperationId, context, streamingQuery->PathId , TTxState::TxAlterStreamingQuery);
146
- RegisterParentPathDependencies (OperationId, context, parentPath);
147
-
148
- NIceDb::TNiceDb db (context.GetDB ());
149
- AdvanceTransactionStateToPropose (OperationId, context, db);
150
- PersistStreamingQuery (OperationId, context, db, streamingQuery, streamingQueryInfo, /* acl */ TString ());
151
222
152
- IncParentDirAlterVersionWithRepublishSafeWithUndo (OperationId, dstPath, context.SS , context.OnComplete );
223
+ const auto guard = context.DbGuard ();
224
+ PersistAlterStreamingQuery (dstPath, context);
225
+ CreateTransaction (dstPath, context);
226
+ AlterStreamingQueryPathElement (dstPath, queryInfo, context);
153
227
154
228
SetState (NextState ());
155
229
return result;
156
230
}
157
231
158
232
void AbortPropose (TOperationContext& context) override {
159
233
LOG_N (" TAlterStreamingQuery AbortPropose: opId# " << OperationId);
160
- Y_ABORT (" no AbortPropose for TAlterStreamingQuery" );
161
234
}
162
235
163
236
void AbortUnsafe (TTxId forceDropTxId, TOperationContext& context) override {
0 commit comments