@@ -48,6 +48,7 @@ class TGateway : public IYtGateway {
48
48
{}
49
49
50
50
void OpenSession (TOpenSessionOptions&& options) final {
51
+ SessionGenerations_[options.SessionId ()] = 0 ;
51
52
return Inner_->OpenSession (std::move (options));
52
53
}
53
54
@@ -56,6 +57,7 @@ class TGateway : public IYtGateway {
56
57
}
57
58
58
59
NThreading::TFuture<void > CleanupSession (TCleanupSessionOptions&& options) final {
60
+ ++SessionGenerations_[options.SessionId ()];
59
61
return Inner_->CleanupSession (std::move (options));
60
62
}
61
63
@@ -166,8 +168,9 @@ class TGateway : public IYtGateway {
166
168
});
167
169
}
168
170
169
- static TString MakeGetTableInfoKey (const TTableReq& req, ui32 epoch) {
171
+ static TString MakeGetTableInfoKey (const TTableReq& req, ui32 epoch, ui64 generation ) {
170
172
auto tableNode = NYT::TNode ()
173
+ (" Generation" , generation)
171
174
(" Cluster" , req.Cluster ())
172
175
(" Table" , req.Table ());
173
176
@@ -199,12 +202,13 @@ class TGateway : public IYtGateway {
199
202
}
200
203
201
204
NThreading::TFuture<TTableInfoResult> GetTableInfo (TGetTableInfoOptions&& options) final {
205
+ ui64 generation = SessionGenerations_[options.SessionId ()];
202
206
if (QContext_.CanRead ()) {
203
207
TTableInfoResult res;
204
208
res.SetSuccess ();
205
209
for (const auto & req : options.Tables ()) {
206
210
TTableInfoResult::TTableData data;
207
- auto key = MakeGetTableInfoKey (req, options.Epoch ());
211
+ auto key = MakeGetTableInfoKey (req, options.Epoch (), generation );
208
212
auto item = QContext_.GetReader ()->Get ({YtGateway_GetTableInfo, key}).GetValueSync ();
209
213
if (!item) {
210
214
throw yexception () << " Missing replay data" ;
@@ -246,7 +250,7 @@ class TGateway : public IYtGateway {
246
250
247
251
auto optionsDup = options;
248
252
return Inner_->GetTableInfo (std::move (options))
249
- .Subscribe ([optionsDup, qContext = QContext_](const NThreading::TFuture<TTableInfoResult>& future) {
253
+ .Subscribe ([optionsDup, qContext = QContext_, generation ](const NThreading::TFuture<TTableInfoResult>& future) {
250
254
if (!qContext.CanWrite () || future.HasException ()) {
251
255
return ;
252
256
}
@@ -260,7 +264,7 @@ class TGateway : public IYtGateway {
260
264
for (size_t i = 0 ; i < res.Data .size (); ++i) {
261
265
const auto & req = optionsDup.Tables ()[i];
262
266
const auto & data = res.Data [i];
263
- auto key = MakeGetTableInfoKey (req, optionsDup.Epoch ());
267
+ auto key = MakeGetTableInfoKey (req, optionsDup.Epoch (), generation );
264
268
265
269
auto attrsNode = NYT::TNode::CreateMap ();
266
270
if (data.Meta ) {
@@ -303,8 +307,9 @@ class TGateway : public IYtGateway {
303
307
});
304
308
}
305
309
306
- static TString MakeGetTableRangeKey (const TTableRangeOptions& options) {
310
+ static TString MakeGetTableRangeKey (const TTableRangeOptions& options, ui64 generation ) {
307
311
auto keyNode = NYT::TNode ()
312
+ (" Generation" , generation)
308
313
(" Cluster" , options.Cluster ())
309
314
(" Prefix" , options.Prefix ())
310
315
(" Suffix" , options.Suffix ());
@@ -317,9 +322,10 @@ class TGateway : public IYtGateway {
317
322
}
318
323
319
324
NThreading::TFuture<TTableRangeResult> GetTableRange (TTableRangeOptions&& options) final {
325
+ ui64 generation = SessionGenerations_[options.SessionId ()];
320
326
TString key;
321
327
if (QContext_) {
322
- key = MakeGetTableRangeKey (options);
328
+ key = MakeGetTableRangeKey (options, generation );
323
329
}
324
330
325
331
if (QContext_.CanRead ()) {
@@ -407,21 +413,22 @@ class TGateway : public IYtGateway {
407
413
});
408
414
}
409
415
410
- static TString MakeGetFolderKey (const TFolderOptions& options) {
416
+ static TString MakeGetFolderKey (const TFolderOptions& options, ui64 generation ) {
411
417
auto attrNode = NYT::TNode::CreateList ();
412
418
for (const auto & attr : options.Attributes ()) {
413
419
attrNode.Add (NYT::TNode (attr));
414
420
}
415
421
416
422
auto keyNode = NYT::TNode ()
423
+ (" Generation" , generation)
417
424
(" Cluster" , options.Cluster ())
418
425
(" Prefix" , options.Prefix ())
419
426
(" Attributes" , attrNode);
420
427
421
428
return MakeHash (NYT::NodeToCanonicalYsonString (keyNode, NYT::NYson::EYsonFormat::Binary));
422
429
}
423
430
424
- static TString MakeResolveLinksKey (const TResolveOptions& options) {
431
+ static TString MakeResolveLinksKey (const TResolveOptions& options, ui64 generation ) {
425
432
auto itemsNode = NYT::TNode::CreateList ();
426
433
for (const auto & item : options.Items ()) {
427
434
auto attrNode = NYT::TNode::CreateList ();
@@ -438,13 +445,14 @@ class TGateway : public IYtGateway {
438
445
}
439
446
440
447
auto keyNode = NYT::TNode ()
448
+ (" Generation" , generation)
441
449
(" Cluster" , options.Cluster ())
442
450
(" Items" , itemsNode);
443
451
444
452
return MakeHash (NYT::NodeToCanonicalYsonString (keyNode, NYT::NYson::EYsonFormat::Binary));
445
453
}
446
454
447
- static TString MakeGetFoldersKey (const TBatchFolderOptions& options) {
455
+ static TString MakeGetFoldersKey (const TBatchFolderOptions& options, ui64 generation ) {
448
456
auto itemsNode = NYT::TNode ();
449
457
TMap<TString, size_t > order;
450
458
for (size_t i = 0 ; i < options.Folders ().size (); ++i) {
@@ -464,6 +472,7 @@ class TGateway : public IYtGateway {
464
472
}
465
473
466
474
auto keyNode = NYT::TNode ()
475
+ (" Generation" , generation)
467
476
(" Cluster" , options.Cluster ())
468
477
(" Items" , itemsNode);
469
478
@@ -490,8 +499,9 @@ class TGateway : public IYtGateway {
490
499
}
491
500
492
501
NThreading::TFuture<TFolderResult> GetFolder (TFolderOptions&& options) final {
502
+ ui64 generation = SessionGenerations_[options.SessionId ()];
493
503
if (QContext_.CanRead ()) {
494
- const auto & key = MakeGetFolderKey (options);
504
+ const auto & key = MakeGetFolderKey (options, generation );
495
505
auto item = QContext_.GetReader ()->Get ({YtGateway_GetFolder, key}).GetValueSync ();
496
506
if (!item) {
497
507
throw yexception () << " Missing replay data" ;
@@ -520,7 +530,7 @@ class TGateway : public IYtGateway {
520
530
521
531
auto optionsDup = options;
522
532
return Inner_->GetFolder (std::move (options))
523
- .Subscribe ([optionsDup, qContext = QContext_](const NThreading::TFuture<TFolderResult>& future) {
533
+ .Subscribe ([optionsDup, qContext = QContext_, generation ](const NThreading::TFuture<TFolderResult>& future) {
524
534
if (!qContext.CanWrite () || future.HasException ()) {
525
535
return ;
526
536
}
@@ -530,7 +540,7 @@ class TGateway : public IYtGateway {
530
540
return ;
531
541
}
532
542
533
- const auto & key = MakeGetFolderKey (optionsDup);
543
+ const auto & key = MakeGetFolderKey (optionsDup, generation );
534
544
auto valueNode = NYT::TNode ();
535
545
536
546
if (std::holds_alternative<TFileLinkPtr>(res.ItemsOrFileLink )) {
@@ -550,10 +560,11 @@ class TGateway : public IYtGateway {
550
560
}
551
561
552
562
NThreading::TFuture<TBatchFolderResult> ResolveLinks (TResolveOptions&& options) final {
563
+ ui64 generation = SessionGenerations_[options.SessionId ()];
553
564
if (QContext_.CanRead ()) {
554
565
TBatchFolderResult res;
555
566
res.SetSuccess ();
556
- const auto & key = MakeResolveLinksKey (options);
567
+ const auto & key = MakeResolveLinksKey (options, generation );
557
568
auto item = QContext_.GetReader ()->Get ({YtGateway_ResolveLinks, key}).GetValueSync ();
558
569
if (!item) {
559
570
throw yexception () << " Missing replay data" ;
@@ -571,7 +582,7 @@ class TGateway : public IYtGateway {
571
582
572
583
auto optionsDup = options;
573
584
return Inner_->ResolveLinks (std::move (options))
574
- .Subscribe ([optionsDup, qContext = QContext_](const NThreading::TFuture<TBatchFolderResult>& future) {
585
+ .Subscribe ([optionsDup, qContext = QContext_, generation ](const NThreading::TFuture<TBatchFolderResult>& future) {
575
586
if (!qContext.CanWrite () || future.HasException ()) {
576
587
return ;
577
588
}
@@ -581,7 +592,7 @@ class TGateway : public IYtGateway {
581
592
return ;
582
593
}
583
594
584
- const auto & key = MakeResolveLinksKey (optionsDup);
595
+ const auto & key = MakeResolveLinksKey (optionsDup, generation );
585
596
NYT::TNode valueNode = NYT::TNode::CreateList ();
586
597
for (const auto & item : res.Items ) {
587
598
valueNode.Add (SerializeFolderItem (item));
@@ -593,10 +604,11 @@ class TGateway : public IYtGateway {
593
604
}
594
605
595
606
NThreading::TFuture<TBatchFolderResult> GetFolders (TBatchFolderOptions&& options) final {
607
+ ui64 generation = SessionGenerations_[options.SessionId ()];
596
608
if (QContext_.CanRead ()) {
597
609
TBatchFolderResult res;
598
610
res.SetSuccess ();
599
- const auto & key = MakeGetFoldersKey (options);
611
+ const auto & key = MakeGetFoldersKey (options, generation );
600
612
auto item = QContext_.GetReader ()->Get ({YtGateway_GetFolders, key}).GetValueSync ();
601
613
if (!item) {
602
614
throw yexception () << " Missing replay data" ;
@@ -614,7 +626,7 @@ class TGateway : public IYtGateway {
614
626
615
627
auto optionsDup = options;
616
628
return Inner_->GetFolders (std::move (options))
617
- .Subscribe ([optionsDup, qContext = QContext_](const NThreading::TFuture<TBatchFolderResult>& future) {
629
+ .Subscribe ([optionsDup, qContext = QContext_, generation ](const NThreading::TFuture<TBatchFolderResult>& future) {
618
630
if (!qContext.CanWrite () || future.HasException ()) {
619
631
return ;
620
632
}
@@ -624,7 +636,7 @@ class TGateway : public IYtGateway {
624
636
return ;
625
637
}
626
638
627
- const auto & key = MakeGetFoldersKey (optionsDup);
639
+ const auto & key = MakeGetFoldersKey (optionsDup, generation );
628
640
NYT::TNode valueNode = NYT::TNode::CreateList ();
629
641
for (const auto & item : res.Items ) {
630
642
valueNode.Add (SerializeFolderItem (item));
@@ -699,8 +711,9 @@ class TGateway : public IYtGateway {
699
711
return Inner_->DropTrackables (std::move (options));
700
712
}
701
713
702
- static TString MakePathStatKey (const TString& cluster, bool extended, const TPathStatReq& req) {
714
+ static TString MakePathStatKey (const TString& cluster, bool extended, const TPathStatReq& req, ui64 generation ) {
703
715
auto node = NYT::TNode ()
716
+ (" Generation" , generation)
704
717
(" Cluster" , cluster)
705
718
(" Extended" , extended);
706
719
@@ -766,13 +779,14 @@ class TGateway : public IYtGateway {
766
779
}
767
780
768
781
NThreading::TFuture<TPathStatResult> PathStat (TPathStatOptions&& options) final {
782
+ ui64 generation = SessionGenerations_[options.SessionId ()];
769
783
if (QContext_.CanRead ()) {
770
784
TPathStatResult res;
771
785
res.DataSize .resize (options.Paths ().size (), 0 );
772
786
res.Extended .resize (options.Paths ().size ());
773
787
774
788
for (ui32 index = 0 ; index < options.Paths ().size (); ++index ) {
775
- const auto & key = MakePathStatKey (options.Cluster (), options.Extended (), options.Paths ()[index ]);
789
+ const auto & key = MakePathStatKey (options.Cluster (), options.Extended (), options.Paths ()[index ], generation );
776
790
auto item = QContext_.GetReader ()->Get ({YtGateway_PathStat, key}).GetValueSync ();
777
791
if (!item) {
778
792
throw yexception () << " Missing replay data" ;
@@ -789,7 +803,7 @@ class TGateway : public IYtGateway {
789
803
790
804
auto optionsDup = options;
791
805
return Inner_->PathStat (std::move (options))
792
- .Subscribe ([optionsDup, qContext = QContext_](const NThreading::TFuture<TPathStatResult>& future) {
806
+ .Subscribe ([optionsDup, qContext = QContext_, generation ](const NThreading::TFuture<TPathStatResult>& future) {
793
807
if (!qContext.CanWrite () || future.HasException ()) {
794
808
return ;
795
809
}
@@ -800,21 +814,22 @@ class TGateway : public IYtGateway {
800
814
}
801
815
802
816
for (ui32 index = 0 ; index < optionsDup.Paths ().size (); ++index ) {
803
- const auto & key = MakePathStatKey (optionsDup.Cluster (), optionsDup.Extended (), optionsDup.Paths ()[index ]);
817
+ const auto & key = MakePathStatKey (optionsDup.Cluster (), optionsDup.Extended (), optionsDup.Paths ()[index ], generation );
804
818
auto value = SerializePathStat (res, index );
805
819
qContext.GetWriter ()->Put ({YtGateway_PathStat, key}, value).GetValueSync ();
806
820
}
807
821
});
808
822
}
809
823
810
824
TPathStatResult TryPathStat (TPathStatOptions&& options) final {
825
+ ui64 generation = SessionGenerations_[options.SessionId ()];
811
826
if (QContext_.CanRead ()) {
812
827
TPathStatResult res;
813
828
res.DataSize .resize (options.Paths ().size (), 0 );
814
829
res.Extended .resize (options.Paths ().size ());
815
830
816
831
for (ui32 index = 0 ; index < options.Paths ().size (); ++index ) {
817
- const auto & key = MakePathStatKey (options.Cluster (), options.Extended (), options.Paths ()[index ]);
832
+ const auto & key = MakePathStatKey (options.Cluster (), options.Extended (), options.Paths ()[index ], generation );
818
833
bool allow = false ;
819
834
if (PathStatKeys_.contains (key)) {
820
835
allow = true ;
@@ -851,15 +866,15 @@ class TGateway : public IYtGateway {
851
866
852
867
if (!res.Success ()) {
853
868
for (ui32 index = 0 ; index < optionsDup.Paths ().size (); ++index ) {
854
- const auto & key = MakePathStatKey (optionsDup.Cluster (), optionsDup.Extended (), optionsDup.Paths ()[index ]);
869
+ const auto & key = MakePathStatKey (optionsDup.Cluster (), optionsDup.Extended (), optionsDup.Paths ()[index ], generation );
855
870
QContext_.GetWriter ()->Put ({YtGateway_PathStatMissing, key}, " 1" ).GetValueSync ();
856
871
}
857
872
858
873
return res;
859
874
}
860
875
861
876
for (ui32 index = 0 ; index < optionsDup.Paths ().size (); ++index ) {
862
- const auto & key = MakePathStatKey (optionsDup.Cluster (), optionsDup.Extended (), optionsDup.Paths ()[index ]);
877
+ const auto & key = MakePathStatKey (optionsDup.Cluster (), optionsDup.Extended (), optionsDup.Paths ()[index ], generation );
863
878
auto value = SerializePathStat (res, index );
864
879
QContext_.GetWriter ()->Put ({YtGateway_PathStat, key}, value).GetValueSync ();
865
880
}
@@ -937,6 +952,7 @@ class TGateway : public IYtGateway {
937
952
const TIntrusivePtr<IRandomProvider> RandomProvider_;
938
953
const TFileStoragePtr FileStorage_;
939
954
THashSet<TString> PathStatKeys_;
955
+ THashMap<TString, ui64> SessionGenerations_;
940
956
};
941
957
942
958
}
0 commit comments