@@ -156,8 +156,8 @@ void TPartition::ReplyOk(const TActorContext& ctx, const ui64 dst) {
156
156
}
157
157
158
158
void TPartition::ReplyGetClientOffsetOk (const TActorContext& ctx, const ui64 dst, const i64 offset,
159
- const TInstant writeTimestamp, const TInstant createTimestamp) {
160
- ctx.Send (Tablet, MakeReplyGetClientOffsetOk (dst, offset, writeTimestamp, createTimestamp).Release ());
159
+ const TInstant writeTimestamp, const TInstant createTimestamp, bool consumerHasAnyCommits ) {
160
+ ctx.Send (Tablet, MakeReplyGetClientOffsetOk (dst, offset, writeTimestamp, createTimestamp, consumerHasAnyCommits ).Release ());
161
161
}
162
162
163
163
NKikimrClient::TKeyValueRequest::EStorageChannel GetChannel (ui32 i) {
@@ -2266,19 +2266,22 @@ void TPartition::CommitTransaction(TSimpleSharedPtr<TTransaction>& t)
2266
2266
Y_ABORT_UNLESS (userInfo.Offset == (i64 )operation.GetCommitOffsetsBegin ());
2267
2267
}
2268
2268
2269
- if (operation.GetCommitOffsetsEnd () < StartOffset) {
2269
+ if (operation.GetCommitOffsetsEnd () <= StartOffset) {
2270
+ userInfo.AnyCommits = false ;
2270
2271
userInfo.Offset = StartOffset;
2271
2272
} else if (operation.GetCommitOffsetsEnd () > EndOffset) {
2273
+ userInfo.AnyCommits = true ;
2272
2274
userInfo.Offset = EndOffset;
2273
2275
} else {
2276
+ userInfo.AnyCommits = true ;
2274
2277
userInfo.Offset = operation.GetCommitOffsetsEnd ();
2275
2278
}
2276
2279
2277
- if (operation.GetKillReadSession ()) { // savnik check default
2280
+ if (operation.GetKillReadSession ()) {
2278
2281
userInfo.Session = " " ;
2279
2282
userInfo.PartitionSessionId = 0 ;
2280
2283
userInfo.Generation = 0 ;
2281
- userInfo.Step = 0 ; // savnik check need drop this
2284
+ userInfo.Step = 0 ;
2282
2285
userInfo.PipeClient = {};
2283
2286
}
2284
2287
}
@@ -2404,6 +2407,9 @@ void TPartition::OnProcessTxsAndUserActsWriteComplete(const TActorContext& ctx)
2404
2407
userInfo.Generation = actual->Generation ;
2405
2408
userInfo.Step = actual->Step ;
2406
2409
userInfo.Offset = actual->Offset ;
2410
+ if (userInfo.Offset <= (i64 )StartOffset) {
2411
+ userInfo.AnyCommits = false ;
2412
+ }
2407
2413
userInfo.ReadRuleGeneration = actual->ReadRuleGeneration ;
2408
2414
userInfo.ReadFromTimestamp = actual->ReadFromTimestamp ;
2409
2415
userInfo.HasReadRule = true ;
@@ -2588,7 +2594,7 @@ TPartition::EProcessResult TPartition::PreProcessImmediateTx(const NKikimrPQ::TE
2588
2594
return EProcessResult::Continue;
2589
2595
}
2590
2596
2591
- void TPartition::ExecImmediateTx (TTransaction& t)
2597
+ void TPartition::ExecImmediateTx (TTransaction& t) // savnik
2592
2598
{
2593
2599
--ImmediateTxCount;
2594
2600
const auto & record = t.ProposeTransaction ->GetRecord ();
@@ -2620,7 +2626,7 @@ void TPartition::ExecImmediateTx(TTransaction& t)
2620
2626
" the consumer has been deleted" );
2621
2627
return ;
2622
2628
}
2623
- TUserInfoBase& userInfo = GetOrCreatePendingUser (user);
2629
+ TUserInfoBase& pendingUserInfo = GetOrCreatePendingUser (user);
2624
2630
2625
2631
if (operation.GetCommitOffsetsBegin () > operation.GetCommitOffsetsEnd ()) {
2626
2632
ScheduleReplyPropose (record,
@@ -2630,7 +2636,7 @@ void TPartition::ExecImmediateTx(TTransaction& t)
2630
2636
return ;
2631
2637
}
2632
2638
2633
- if (userInfo .Offset != (i64 )operation.GetCommitOffsetsBegin ()) {
2639
+ if (pendingUserInfo .Offset != (i64 )operation.GetCommitOffsetsBegin ()) {
2634
2640
ScheduleReplyPropose (record,
2635
2641
NKikimrPQ::TEvProposeTransactionResult::ABORTED,
2636
2642
NKikimrPQ::TError::BAD_REQUEST,
@@ -2645,7 +2651,7 @@ void TPartition::ExecImmediateTx(TTransaction& t)
2645
2651
" incorrect offset range (commit to the future)" );
2646
2652
return ;
2647
2653
}
2648
- userInfo .Offset = operation.GetCommitOffsetsEnd ();
2654
+ pendingUserInfo .Offset = operation.GetCommitOffsetsEnd ();
2649
2655
}
2650
2656
CommitWriteOperations (t);
2651
2657
@@ -2780,7 +2786,7 @@ void TPartition::CommitUserAct(TEvPQ::TEvSetClientInfo& act) {
2780
2786
userInfo.PipeClient = act.PipeClient ;
2781
2787
ScheduleReplyGetClientOffsetOk (act.Cookie ,
2782
2788
userInfo.Offset ,
2783
- ts.first , ts.second );
2789
+ ts.first , ts.second , ui-> AnyCommits );
2784
2790
2785
2791
return ;
2786
2792
}
@@ -2877,7 +2883,7 @@ void TPartition::EmulatePostProcessUserAct(const TEvPQ::TEvSetClientInfo& act,
2877
2883
ui32 step = act.Step ;
2878
2884
const ui64 readRuleGeneration = act.ReadRuleGeneration ;
2879
2885
2880
- bool setSession = act.Type == TEvPQ::TEvSetClientInfo::ESCI_CREATE_SESSION;
2886
+ bool createSession = act.Type == TEvPQ::TEvSetClientInfo::ESCI_CREATE_SESSION;
2881
2887
bool dropSession = act.Type == TEvPQ::TEvSetClientInfo::ESCI_DROP_SESSION;
2882
2888
bool commitNotFromReadSession = (act.Type == TEvPQ::TEvSetClientInfo::ESCI_OFFSET && act.SessionId .empty ());
2883
2889
@@ -2886,6 +2892,7 @@ void TPartition::EmulatePostProcessUserAct(const TEvPQ::TEvSetClientInfo& act,
2886
2892
userInfo.Session = " " ;
2887
2893
userInfo.Generation = userInfo.Step = 0 ;
2888
2894
userInfo.Offset = 0 ;
2895
+ userInfo.AnyCommits = false ;
2889
2896
2890
2897
PQ_LOG_D (" Topic '" << TopicName () << " ' partition " << Partition << " user " << user
2891
2898
<< " drop done"
@@ -2901,24 +2908,25 @@ void TPartition::EmulatePostProcessUserAct(const TEvPQ::TEvSetClientInfo& act,
2901
2908
userInfo.PartitionSessionId = 0 ;
2902
2909
userInfo.Generation = userInfo.Step = 0 ;
2903
2910
userInfo.Offset = 0 ;
2911
+ userInfo.AnyCommits = false ;
2904
2912
2905
2913
if (userInfo.Important ) {
2906
2914
userInfo.Offset = StartOffset;
2907
2915
}
2908
2916
} else {
2909
- if (setSession || dropSession) {
2917
+ if (createSession || dropSession) {
2910
2918
offset = userInfo.Offset ;
2911
2919
auto *ui = UsersInfoStorage->GetIfExists (userInfo.User );
2912
2920
auto ts = ui ? GetTime (*ui, userInfo.Offset ) : std::make_pair<TInstant, TInstant>(TInstant::Zero (), TInstant::Zero ());
2913
2921
2914
2922
ScheduleReplyGetClientOffsetOk (act.Cookie ,
2915
2923
offset,
2916
- ts.first , ts.second );
2924
+ ts.first , ts.second , ui-> AnyCommits );
2917
2925
} else {
2918
2926
ScheduleReplyOk (act.Cookie );
2919
2927
}
2920
2928
2921
- if (setSession ) {
2929
+ if (createSession ) {
2922
2930
userInfo.Session = session;
2923
2931
userInfo.Generation = generation;
2924
2932
userInfo.Step = step;
@@ -2934,17 +2942,20 @@ void TPartition::EmulatePostProcessUserAct(const TEvPQ::TEvSetClientInfo& act,
2934
2942
2935
2943
Y_ABORT_UNLESS (offset <= (ui64)Max<i64 >(), " Unexpected Offset: %" PRIu64, offset);
2936
2944
PQ_LOG_D (" Topic '" << TopicName () << " ' partition " << Partition << " user " << user
2937
- << (setSession || dropSession ? " session" : " offset" )
2945
+ << (createSession || dropSession ? " session" : " offset" )
2938
2946
<< " is set to " << offset << " (startOffset " << StartOffset << " ) session " << session
2939
2947
);
2940
2948
2941
2949
userInfo.Offset = offset;
2950
+ if (userInfo.Offset <= (i64 )StartOffset) {
2951
+ userInfo.AnyCommits = false ;
2952
+ }
2942
2953
2943
2954
if (LastOffsetHasBeenCommited (userInfo)) {
2944
2955
SendReadingFinished (user);
2945
2956
}
2946
2957
2947
- auto counter = setSession ? COUNTER_PQ_CREATE_SESSION_OK : (dropSession ? COUNTER_PQ_DELETE_SESSION_OK : COUNTER_PQ_SET_CLIENT_OFFSET_OK);
2958
+ auto counter = createSession ? COUNTER_PQ_CREATE_SESSION_OK : (dropSession ? COUNTER_PQ_DELETE_SESSION_OK : COUNTER_PQ_SET_CLIENT_OFFSET_OK);
2948
2959
TabletCounters.Cumulative ()[counter].Increment (1 );
2949
2960
}
2950
2961
}
@@ -2957,12 +2968,16 @@ void TPartition::ScheduleReplyOk(const ui64 dst)
2957
2968
2958
2969
void TPartition::ScheduleReplyGetClientOffsetOk (const ui64 dst,
2959
2970
const i64 offset,
2960
- const TInstant writeTimestamp, const TInstant createTimestamp)
2971
+ const TInstant writeTimestamp,
2972
+ const TInstant createTimestamp,
2973
+ bool consumerHasAnyCommits)
2961
2974
{
2962
2975
Replies.emplace_back (Tablet,
2963
2976
MakeReplyGetClientOffsetOk (dst,
2964
2977
offset,
2965
- writeTimestamp, createTimestamp).Release ());
2978
+ writeTimestamp,
2979
+ createTimestamp,
2980
+ consumerHasAnyCommits).Release ());
2966
2981
2967
2982
}
2968
2983
@@ -3037,7 +3052,8 @@ void TPartition::AddCmdWrite(NKikimrClient::TKeyValueRequest& request,
3037
3052
const TKeyPrefix& ikey, const TKeyPrefix& ikeyDeprecated,
3038
3053
ui64 offset, ui32 gen, ui32 step, const TString& session,
3039
3054
ui64 readOffsetRewindSum,
3040
- ui64 readRuleGeneration)
3055
+ ui64 readRuleGeneration,
3056
+ bool anyCommits)
3041
3057
{
3042
3058
TBuffer idata;
3043
3059
{
@@ -3048,6 +3064,7 @@ void TPartition::AddCmdWrite(NKikimrClient::TKeyValueRequest& request,
3048
3064
userData.SetSession (session);
3049
3065
userData.SetOffsetRewindSum (readOffsetRewindSum);
3050
3066
userData.SetReadRuleGeneration (readRuleGeneration);
3067
+ userData.SetAnyCommits (anyCommits);
3051
3068
3052
3069
TString out;
3053
3070
Y_PROTOBUF_SUPPRESS_NODISCARD userData.SerializeToString (&out);
@@ -3108,7 +3125,8 @@ void TPartition::AddCmdWriteUserInfos(NKikimrClient::TKeyValueRequest& request)
3108
3125
userInfo->Offset , userInfo->Generation , userInfo->Step ,
3109
3126
userInfo->Session ,
3110
3127
ui ? ui->ReadOffsetRewindSum : 0 ,
3111
- userInfo->ReadRuleGeneration );
3128
+ userInfo->ReadRuleGeneration ,
3129
+ userInfo->AnyCommits );
3112
3130
} else {
3113
3131
AddCmdDeleteRange (request,
3114
3132
ikey, ikeyDeprecated);
@@ -3137,27 +3155,27 @@ TUserInfoBase& TPartition::GetOrCreatePendingUser(const TString& user,
3137
3155
TMaybe<ui64> readRuleGeneration)
3138
3156
{
3139
3157
TUserInfoBase* userInfo = nullptr ;
3140
- auto i = PendingUsersInfo.find (user);
3141
- if (i == PendingUsersInfo.end ()) {
3142
- auto ui = UsersInfoStorage->GetIfExists (user);
3143
- auto [p , _] = PendingUsersInfo.emplace (user, UsersInfoStorage->CreateUserInfo (user, readRuleGeneration));
3158
+ auto pendingUserIt = PendingUsersInfo.find (user);
3159
+ if (pendingUserIt == PendingUsersInfo.end ()) {
3160
+ auto userIt = UsersInfoStorage->GetIfExists (user);
3161
+ auto [newPendingUserIt , _] = PendingUsersInfo.emplace (user, UsersInfoStorage->CreateUserInfo (user, readRuleGeneration));
3144
3162
3145
- if (ui ) {
3146
- p ->second .Session = ui ->Session ;
3147
- p ->second .PartitionSessionId = ui ->PartitionSessionId ;
3148
- p ->second .PipeClient = ui ->PipeClient ;
3163
+ if (userIt ) {
3164
+ newPendingUserIt ->second .Session = userIt ->Session ;
3165
+ newPendingUserIt ->second .PartitionSessionId = userIt ->PartitionSessionId ;
3166
+ newPendingUserIt ->second .PipeClient = userIt ->PipeClient ;
3149
3167
3150
- p ->second .Generation = ui ->Generation ;
3151
- p ->second .Step = ui ->Step ;
3152
- p ->second .Offset = ui ->Offset ;
3153
- p ->second .ReadRuleGeneration = ui ->ReadRuleGeneration ;
3154
- p ->second .Important = ui ->Important ;
3155
- p ->second .ReadFromTimestamp = ui ->ReadFromTimestamp ;
3168
+ newPendingUserIt ->second .Generation = userIt ->Generation ;
3169
+ newPendingUserIt ->second .Step = userIt ->Step ;
3170
+ newPendingUserIt ->second .Offset = userIt ->Offset ;
3171
+ newPendingUserIt ->second .ReadRuleGeneration = userIt ->ReadRuleGeneration ;
3172
+ newPendingUserIt ->second .Important = userIt ->Important ;
3173
+ newPendingUserIt ->second .ReadFromTimestamp = userIt ->ReadFromTimestamp ;
3156
3174
}
3157
3175
3158
- userInfo = &p ->second ;
3176
+ userInfo = &newPendingUserIt ->second ;
3159
3177
} else {
3160
- userInfo = &i ->second ;
3178
+ userInfo = &pendingUserIt ->second ;
3161
3179
}
3162
3180
AffectedUsers.insert (user);
3163
3181
@@ -3186,7 +3204,9 @@ THolder<TEvPQ::TEvProxyResponse> TPartition::MakeReplyOk(const ui64 dst)
3186
3204
3187
3205
THolder<TEvPQ::TEvProxyResponse> TPartition::MakeReplyGetClientOffsetOk (const ui64 dst,
3188
3206
const i64 offset,
3189
- const TInstant writeTimestamp, const TInstant createTimestamp)
3207
+ const TInstant writeTimestamp,
3208
+ const TInstant createTimestamp,
3209
+ bool consumerHasAnyCommits)
3190
3210
{
3191
3211
auto response = MakeHolder<TEvPQ::TEvProxyResponse>(dst);
3192
3212
NKikimrClient::TResponse& resp = *response->Response ;
@@ -3206,6 +3226,7 @@ THolder<TEvPQ::TEvProxyResponse> TPartition::MakeReplyGetClientOffsetOk(const ui
3206
3226
user->SetEndOffset (EndOffset);
3207
3227
user->SetSizeLag (GetSizeLag (offset));
3208
3228
user->SetWriteTimestampEstimateMS (WriteTimestampEstimate.MilliSeconds ());
3229
+ user->SetClientHasAnyCommits (consumerHasAnyCommits);
3209
3230
3210
3231
return response;
3211
3232
}
0 commit comments