@@ -531,6 +531,21 @@ class TKqpSessionActor : public TActorBootstrapped<TKqpSessionActor> {
531
531
CompileQuery ();
532
532
}
533
533
534
+ bool AreAllTheTopicsAndPartitionsKnown () const {
535
+ const NKikimrKqp::TTopicOperationsRequest& operations = QueryState->GetTopicOperations ();
536
+ for (const auto & topic : operations.GetTopics ()) {
537
+ auto path = CanonizePath (NPersQueue::GetFullTopicPath (TlsActivationContext->AsActorContext (),
538
+ QueryState->GetDatabase (), topic.path ()));
539
+
540
+ for (const auto & partition : topic.partitions ()) {
541
+ if (!QueryState->TxCtx ->TopicOperations .HasThisPartitionAlreadyBeenAdded (path, partition.partition_id ())) {
542
+ return false ;
543
+ }
544
+ }
545
+ }
546
+ return true ;
547
+ }
548
+
534
549
void AddOffsetsToTransaction () {
535
550
YQL_ENSURE (QueryState);
536
551
if (!PrepareQueryTransaction ()) {
@@ -539,10 +554,25 @@ class TKqpSessionActor : public TActorBootstrapped<TKqpSessionActor> {
539
554
540
555
QueryState->AddOffsetsToTransaction ();
541
556
542
- auto navigate = QueryState->BuildSchemeCacheNavigate ();
557
+ if (!AreAllTheTopicsAndPartitionsKnown ()) {
558
+ auto navigate = QueryState->BuildSchemeCacheNavigate ();
559
+ Become (&TKqpSessionActor::ExecuteState);
560
+ Send (MakeSchemeCacheID (), new TEvTxProxySchemeCache::TEvNavigateKeySet (navigate.release ()));
561
+ return ;
562
+ }
543
563
544
- Become (&TKqpSessionActor::ExecuteState);
545
- Send (MakeSchemeCacheID (), new TEvTxProxySchemeCache::TEvNavigateKeySet (navigate.release ()));
564
+ TString message;
565
+ if (!QueryState->TryMergeTopicOffsets (QueryState->TopicOperations , message)) {
566
+ ythrow TRequestFail (Ydb::StatusIds::BAD_REQUEST) << message;
567
+ }
568
+
569
+ if (HasTopicWriteOperations () && !HasTopicWriteId ()) {
570
+ Become (&TKqpSessionActor::ExecuteState);
571
+ Send (MakeTxProxyID (), new TEvTxUserProxy::TEvAllocateTxId, 0 , QueryState->QueryId );
572
+ return ;
573
+ }
574
+
575
+ ReplySuccess ();
546
576
}
547
577
548
578
void CompileQuery () {
0 commit comments