@@ -2343,6 +2343,74 @@ bool TPartition::ExecUserActionOrTransaction(TSimpleSharedPtr<TTransaction>& t,
2343
2343
return true ;
2344
2344
}
2345
2345
2346
+ std::pair<bool , bool > TPartition::ValidatePartitionOperation (const NKikimrPQ::TPartitionOperation& operation) {
2347
+ const TString& consumer = operation.GetConsumer ();
2348
+
2349
+ if (AffectedUsers.contains (consumer) && !GetPendingUserIfExists (consumer)) {
2350
+ PQ_LOG_D (" Partition " << Partition <<
2351
+ " Consumer '" << consumer << " ' has been removed" );
2352
+ return {false , false };
2353
+ }
2354
+
2355
+ if (!UsersInfoStorage->GetIfExists (consumer)) {
2356
+ PQ_LOG_D (" Partition " << Partition <<
2357
+ " Unknown consumer '" << consumer << " '" );
2358
+ return {false , false };
2359
+ }
2360
+
2361
+ TUserInfoBase& userInfo = GetOrCreatePendingUser (consumer);
2362
+
2363
+ PQ_LOG_D (" CommitOperation Partition " << Partition <<
2364
+ " Consumer '" << consumer << " '" <<
2365
+ " RequestSessionId '" << operation.GetReadSessionId () <<
2366
+ " ' CurrentSessionId '" << userInfo.Session <<
2367
+ " ' OffsetBegin " << operation.GetCommitOffsetsBegin () <<
2368
+ " ' OffsetEnd " << operation.GetCommitOffsetsEnd () <<
2369
+ " OnlyCheckCommitedToFinish " << operation.GetOnlyCheckCommitedToFinish () <<
2370
+ " KillReadSession " << operation.GetKillReadSession ()
2371
+ );
2372
+
2373
+ if (!operation.GetReadSessionId ().empty () && operation.GetReadSessionId () != userInfo.Session ) {
2374
+ PQ_LOG_D (" Partition " << Partition <<
2375
+ " Consumer '" << consumer << " '" <<
2376
+ " Bad request (session already dead) " <<
2377
+ " RequestSessionId '" << operation.GetReadSessionId () <<
2378
+ " ' CurrentSessionId '" << userInfo.Session <<
2379
+ " '" );
2380
+ return {false , false };
2381
+ } else if (operation.GetOnlyCheckCommitedToFinish ()) {
2382
+ if (IsActive () || static_cast <ui64>(userInfo.Offset ) != EndOffset) {
2383
+ return {false , false };
2384
+ } else {
2385
+ return {true , false };
2386
+ }
2387
+ } else {
2388
+ if (!operation.GetForceCommit () && operation.GetCommitOffsetsBegin () > operation.GetCommitOffsetsEnd ()) {
2389
+ PQ_LOG_D (" Partition " << Partition <<
2390
+ " Consumer '" << consumer << " '" <<
2391
+ " Bad request (invalid range) " <<
2392
+ " Begin " << operation.GetCommitOffsetsBegin () <<
2393
+ " End " << operation.GetCommitOffsetsEnd ());
2394
+ return {false , true };
2395
+ } else if (!operation.GetForceCommit () && userInfo.Offset != (i64 )operation.GetCommitOffsetsBegin ()) {
2396
+ PQ_LOG_D (" Partition " << Partition <<
2397
+ " Consumer '" << consumer << " '" <<
2398
+ " Bad request (gap) " <<
2399
+ " Offset " << userInfo.Offset <<
2400
+ " Begin " << operation.GetCommitOffsetsBegin ());
2401
+ return {false , true };
2402
+ } else if (!operation.GetForceCommit () && operation.GetCommitOffsetsEnd () > EndOffset) {
2403
+ PQ_LOG_D (" Partition " << Partition <<
2404
+ " Consumer '" << consumer << " '" <<
2405
+ " Bad request (behind the last offset) " <<
2406
+ " EndOffset " << EndOffset <<
2407
+ " End " << operation.GetCommitOffsetsEnd ());
2408
+ return {false , true };
2409
+ }
2410
+ return {true , true };
2411
+ }
2412
+ }
2413
+
2346
2414
TPartition::EProcessResult TPartition::BeginTransaction (const TEvPQ::TEvTxCalcPredicate& tx, TMaybe<bool >& predicateOut)
2347
2415
{
2348
2416
if (tx.ForcePredicateFalse ) {
@@ -2361,68 +2429,25 @@ TPartition::EProcessResult TPartition::BeginTransaction(const TEvPQ::TEvTxCalcPr
2361
2429
return EProcessResult::Blocked;
2362
2430
}
2363
2431
2364
- if (AffectedUsers.contains (consumer) && !GetPendingUserIfExists (consumer)) {
2365
- PQ_LOG_D (" Partition " << Partition <<
2366
- " Consumer '" << consumer << " ' has been removed" );
2367
- result = false ;
2368
- break ;
2369
- }
2370
-
2371
- if (!UsersInfoStorage->GetIfExists (consumer)) {
2372
- PQ_LOG_D (" Partition " << Partition <<
2373
- " Unknown consumer '" << consumer << " '" );
2374
- result = false ;
2375
- break ;
2376
- }
2432
+ auto [r, real] = ValidatePartitionOperation (operation);
2433
+ result = r;
2377
2434
2378
- bool isAffectedConsumer = AffectedUsers.contains (consumer);
2379
- TUserInfoBase& userInfo = GetOrCreatePendingUser (consumer);
2380
-
2381
- if (!operation.GetReadSessionId ().empty () && operation.GetReadSessionId () != userInfo.Session ) {
2382
- PQ_LOG_D (" Partition " << Partition <<
2383
- " Consumer '" << consumer << " '" <<
2384
- " Bad request (session already dead) " <<
2385
- " RequestSessionId '" << operation.GetReadSessionId () <<
2386
- " CurrentSessionId '" << userInfo.Session <<
2387
- " '" );
2388
- result = false ;
2389
- } else if (operation.GetOnlyCheckCommitedToFinish ()) {
2390
- if (IsActive () || static_cast <ui64>(userInfo.Offset ) != EndOffset) {
2391
- result = false ;
2392
- }
2393
- } else {
2394
- if (!operation.GetForceCommit () && operation.GetCommitOffsetsBegin () > operation.GetCommitOffsetsEnd ()) {
2395
- PQ_LOG_D (" Partition " << Partition <<
2396
- " Consumer '" << consumer << " '" <<
2397
- " Bad request (invalid range) " <<
2398
- " Begin " << operation.GetCommitOffsetsBegin () <<
2399
- " End " << operation.GetCommitOffsetsEnd ());
2400
- result = false ;
2401
- } else if (!operation.GetForceCommit () && userInfo.Offset != (i64 )operation.GetCommitOffsetsBegin ()) {
2402
- PQ_LOG_D (" Partition " << Partition <<
2403
- " Consumer '" << consumer << " '" <<
2404
- " Bad request (gap) " <<
2405
- " Offset " << userInfo.Offset <<
2406
- " Begin " << operation.GetCommitOffsetsBegin ());
2407
- result = false ;
2408
- } else if (!operation.GetForceCommit () && operation.GetCommitOffsetsEnd () > EndOffset) {
2409
- PQ_LOG_D (" Partition " << Partition <<
2410
- " Consumer '" << consumer << " '" <<
2411
- " Bad request (behind the last offset) " <<
2412
- " EndOffset " << EndOffset <<
2413
- " End " << operation.GetCommitOffsetsEnd ());
2414
- result = false ;
2415
- }
2435
+ if (real) {
2436
+ if (!r) {
2437
+ bool isAffectedConsumer = AffectedUsers.contains (consumer);
2416
2438
2417
- if (!result) {
2418
2439
if (!isAffectedConsumer) {
2419
2440
AffectedUsers.erase (consumer);
2420
2441
}
2421
2442
break ;
2422
2443
}
2423
2444
consumers.insert (consumer);
2424
2445
}
2446
+ if (!r) {
2447
+ break ;
2448
+ }
2425
2449
}
2450
+
2426
2451
if (result) {
2427
2452
TxAffectedConsumers.insert (consumers.begin (), consumers.end ());
2428
2453
}
@@ -2586,6 +2611,9 @@ void TPartition::CommitTransaction(TSimpleSharedPtr<TTransaction>& t)
2586
2611
Y_ABORT_UNLESS (t->Predicate .Defined () && *t->Predicate );
2587
2612
2588
2613
for (auto & operation : t->Tx ->Operations ) {
2614
+
2615
+ Cerr << " >>>>> CommitTransaction " << Endl << Flush;
2616
+
2589
2617
if (operation.GetOnlyCheckCommitedToFinish ()) {
2590
2618
continue ;
2591
2619
}
@@ -2913,6 +2941,16 @@ TPartition::EProcessResult TPartition::PreProcessImmediateTx(const NKikimrPQ::TE
2913
2941
" incorrect offset range (begin > end)" );
2914
2942
return EProcessResult::ContinueDrop;
2915
2943
}
2944
+
2945
+ auto [r, _] = ValidatePartitionOperation (operation);
2946
+ if (!r) {
2947
+ ScheduleReplyPropose (tx,
2948
+ NKikimrPQ::TEvProposeTransactionResult::BAD_REQUEST,
2949
+ NKikimrPQ::TError::BAD_REQUEST,
2950
+ " incorrect request" );
2951
+ return EProcessResult::ContinueDrop;
2952
+ }
2953
+
2916
2954
consumers.insert (user);
2917
2955
}
2918
2956
SetOffsetAffectedConsumers.insert (consumers.begin (), consumers.end ());
0 commit comments