@@ -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) {
@@ -2285,19 +2285,22 @@ void TPartition::CommitTransaction(TSimpleSharedPtr<TTransaction>& t)
2285
2285
Y_ABORT_UNLESS (userInfo.Offset == (i64 )operation.GetCommitOffsetsBegin ());
2286
2286
}
2287
2287
2288
- if (operation.GetCommitOffsetsEnd () < StartOffset) {
2288
+ if (operation.GetCommitOffsetsEnd () <= StartOffset) {
2289
+ userInfo.AnyCommits = false ;
2289
2290
userInfo.Offset = StartOffset;
2290
2291
} else if (operation.GetCommitOffsetsEnd () > EndOffset) {
2292
+ userInfo.AnyCommits = true ;
2291
2293
userInfo.Offset = EndOffset;
2292
2294
} else {
2295
+ userInfo.AnyCommits = true ;
2293
2296
userInfo.Offset = operation.GetCommitOffsetsEnd ();
2294
2297
}
2295
2298
2296
- if (operation.GetKillReadSession ()) { // savnik check default
2299
+ if (operation.GetKillReadSession ()) {
2297
2300
userInfo.Session = " " ;
2298
2301
userInfo.PartitionSessionId = 0 ;
2299
2302
userInfo.Generation = 0 ;
2300
- userInfo.Step = 0 ; // savnik check need drop this
2303
+ userInfo.Step = 0 ;
2301
2304
userInfo.PipeClient = {};
2302
2305
}
2303
2306
}
@@ -2423,6 +2426,9 @@ void TPartition::OnProcessTxsAndUserActsWriteComplete(const TActorContext& ctx)
2423
2426
userInfo.Generation = actual->Generation ;
2424
2427
userInfo.Step = actual->Step ;
2425
2428
userInfo.Offset = actual->Offset ;
2429
+ if (userInfo.Offset <= (i64 )StartOffset) {
2430
+ userInfo.AnyCommits = false ;
2431
+ }
2426
2432
userInfo.ReadRuleGeneration = actual->ReadRuleGeneration ;
2427
2433
userInfo.ReadFromTimestamp = actual->ReadFromTimestamp ;
2428
2434
userInfo.HasReadRule = true ;
@@ -2607,7 +2613,7 @@ TPartition::EProcessResult TPartition::PreProcessImmediateTx(const NKikimrPQ::TE
2607
2613
return EProcessResult::Continue;
2608
2614
}
2609
2615
2610
- void TPartition::ExecImmediateTx (TTransaction& t)
2616
+ void TPartition::ExecImmediateTx (TTransaction& t) // savnik
2611
2617
{
2612
2618
--ImmediateTxCount;
2613
2619
const auto & record = t.ProposeTransaction ->GetRecord ();
@@ -2639,7 +2645,7 @@ void TPartition::ExecImmediateTx(TTransaction& t)
2639
2645
" the consumer has been deleted" );
2640
2646
return ;
2641
2647
}
2642
- TUserInfoBase& userInfo = GetOrCreatePendingUser (user);
2648
+ TUserInfoBase& pendingUserInfo = GetOrCreatePendingUser (user);
2643
2649
2644
2650
if (operation.GetCommitOffsetsBegin () > operation.GetCommitOffsetsEnd ()) {
2645
2651
ScheduleReplyPropose (record,
@@ -2649,7 +2655,7 @@ void TPartition::ExecImmediateTx(TTransaction& t)
2649
2655
return ;
2650
2656
}
2651
2657
2652
- if (userInfo .Offset != (i64 )operation.GetCommitOffsetsBegin ()) {
2658
+ if (pendingUserInfo .Offset != (i64 )operation.GetCommitOffsetsBegin ()) {
2653
2659
ScheduleReplyPropose (record,
2654
2660
NKikimrPQ::TEvProposeTransactionResult::ABORTED,
2655
2661
NKikimrPQ::TError::BAD_REQUEST,
@@ -2664,7 +2670,7 @@ void TPartition::ExecImmediateTx(TTransaction& t)
2664
2670
" incorrect offset range (commit to the future)" );
2665
2671
return ;
2666
2672
}
2667
- userInfo .Offset = operation.GetCommitOffsetsEnd ();
2673
+ pendingUserInfo .Offset = operation.GetCommitOffsetsEnd ();
2668
2674
}
2669
2675
CommitWriteOperations (t);
2670
2676
@@ -2799,7 +2805,7 @@ void TPartition::CommitUserAct(TEvPQ::TEvSetClientInfo& act) {
2799
2805
userInfo.PipeClient = act.PipeClient ;
2800
2806
ScheduleReplyGetClientOffsetOk (act.Cookie ,
2801
2807
userInfo.Offset ,
2802
- ts.first , ts.second );
2808
+ ts.first , ts.second , ui-> AnyCommits );
2803
2809
2804
2810
return ;
2805
2811
}
@@ -2896,7 +2902,7 @@ void TPartition::EmulatePostProcessUserAct(const TEvPQ::TEvSetClientInfo& act,
2896
2902
ui32 step = act.Step ;
2897
2903
const ui64 readRuleGeneration = act.ReadRuleGeneration ;
2898
2904
2899
- bool setSession = act.Type == TEvPQ::TEvSetClientInfo::ESCI_CREATE_SESSION;
2905
+ bool createSession = act.Type == TEvPQ::TEvSetClientInfo::ESCI_CREATE_SESSION;
2900
2906
bool dropSession = act.Type == TEvPQ::TEvSetClientInfo::ESCI_DROP_SESSION;
2901
2907
bool commitNotFromReadSession = (act.Type == TEvPQ::TEvSetClientInfo::ESCI_OFFSET && act.SessionId .empty ());
2902
2908
@@ -2905,6 +2911,7 @@ void TPartition::EmulatePostProcessUserAct(const TEvPQ::TEvSetClientInfo& act,
2905
2911
userInfo.Session = " " ;
2906
2912
userInfo.Generation = userInfo.Step = 0 ;
2907
2913
userInfo.Offset = 0 ;
2914
+ userInfo.AnyCommits = false ;
2908
2915
2909
2916
PQ_LOG_D (" Topic '" << TopicName () << " ' partition " << Partition << " user " << user
2910
2917
<< " drop done"
@@ -2920,24 +2927,25 @@ void TPartition::EmulatePostProcessUserAct(const TEvPQ::TEvSetClientInfo& act,
2920
2927
userInfo.PartitionSessionId = 0 ;
2921
2928
userInfo.Generation = userInfo.Step = 0 ;
2922
2929
userInfo.Offset = 0 ;
2930
+ userInfo.AnyCommits = false ;
2923
2931
2924
2932
if (userInfo.Important ) {
2925
2933
userInfo.Offset = StartOffset;
2926
2934
}
2927
2935
} else {
2928
- if (setSession || dropSession) {
2936
+ if (createSession || dropSession) {
2929
2937
offset = userInfo.Offset ;
2930
2938
auto *ui = UsersInfoStorage->GetIfExists (userInfo.User );
2931
2939
auto ts = ui ? GetTime (*ui, userInfo.Offset ) : std::make_pair<TInstant, TInstant>(TInstant::Zero (), TInstant::Zero ());
2932
2940
2933
2941
ScheduleReplyGetClientOffsetOk (act.Cookie ,
2934
2942
offset,
2935
- ts.first , ts.second );
2943
+ ts.first , ts.second , ui-> AnyCommits );
2936
2944
} else {
2937
2945
ScheduleReplyOk (act.Cookie );
2938
2946
}
2939
2947
2940
- if (setSession ) {
2948
+ if (createSession ) {
2941
2949
userInfo.Session = session;
2942
2950
userInfo.Generation = generation;
2943
2951
userInfo.Step = step;
@@ -2953,17 +2961,20 @@ void TPartition::EmulatePostProcessUserAct(const TEvPQ::TEvSetClientInfo& act,
2953
2961
2954
2962
Y_ABORT_UNLESS (offset <= (ui64)Max<i64 >(), " Unexpected Offset: %" PRIu64, offset);
2955
2963
PQ_LOG_D (" Topic '" << TopicName () << " ' partition " << Partition << " user " << user
2956
- << (setSession || dropSession ? " session" : " offset" )
2964
+ << (createSession || dropSession ? " session" : " offset" )
2957
2965
<< " is set to " << offset << " (startOffset " << StartOffset << " ) session " << session
2958
2966
);
2959
2967
2960
2968
userInfo.Offset = offset;
2969
+ if (userInfo.Offset <= (i64 )StartOffset) {
2970
+ userInfo.AnyCommits = false ;
2971
+ }
2961
2972
2962
2973
if (LastOffsetHasBeenCommited (userInfo)) {
2963
2974
SendReadingFinished (user);
2964
2975
}
2965
2976
2966
- auto counter = setSession ? COUNTER_PQ_CREATE_SESSION_OK : (dropSession ? COUNTER_PQ_DELETE_SESSION_OK : COUNTER_PQ_SET_CLIENT_OFFSET_OK);
2977
+ auto counter = createSession ? COUNTER_PQ_CREATE_SESSION_OK : (dropSession ? COUNTER_PQ_DELETE_SESSION_OK : COUNTER_PQ_SET_CLIENT_OFFSET_OK);
2967
2978
TabletCounters.Cumulative ()[counter].Increment (1 );
2968
2979
}
2969
2980
}
@@ -2976,12 +2987,16 @@ void TPartition::ScheduleReplyOk(const ui64 dst)
2976
2987
2977
2988
void TPartition::ScheduleReplyGetClientOffsetOk (const ui64 dst,
2978
2989
const i64 offset,
2979
- const TInstant writeTimestamp, const TInstant createTimestamp)
2990
+ const TInstant writeTimestamp,
2991
+ const TInstant createTimestamp,
2992
+ bool consumerHasAnyCommits)
2980
2993
{
2981
2994
Replies.emplace_back (Tablet,
2982
2995
MakeReplyGetClientOffsetOk (dst,
2983
2996
offset,
2984
- writeTimestamp, createTimestamp).Release ());
2997
+ writeTimestamp,
2998
+ createTimestamp,
2999
+ consumerHasAnyCommits).Release ());
2985
3000
2986
3001
}
2987
3002
@@ -3056,7 +3071,8 @@ void TPartition::AddCmdWrite(NKikimrClient::TKeyValueRequest& request,
3056
3071
const TKeyPrefix& ikey, const TKeyPrefix& ikeyDeprecated,
3057
3072
ui64 offset, ui32 gen, ui32 step, const TString& session,
3058
3073
ui64 readOffsetRewindSum,
3059
- ui64 readRuleGeneration)
3074
+ ui64 readRuleGeneration,
3075
+ bool anyCommits)
3060
3076
{
3061
3077
TBuffer idata;
3062
3078
{
@@ -3067,6 +3083,7 @@ void TPartition::AddCmdWrite(NKikimrClient::TKeyValueRequest& request,
3067
3083
userData.SetSession (session);
3068
3084
userData.SetOffsetRewindSum (readOffsetRewindSum);
3069
3085
userData.SetReadRuleGeneration (readRuleGeneration);
3086
+ userData.SetAnyCommits (anyCommits);
3070
3087
3071
3088
TString out;
3072
3089
Y_PROTOBUF_SUPPRESS_NODISCARD userData.SerializeToString (&out);
@@ -3127,7 +3144,8 @@ void TPartition::AddCmdWriteUserInfos(NKikimrClient::TKeyValueRequest& request)
3127
3144
userInfo->Offset , userInfo->Generation , userInfo->Step ,
3128
3145
userInfo->Session ,
3129
3146
ui ? ui->ReadOffsetRewindSum : 0 ,
3130
- userInfo->ReadRuleGeneration );
3147
+ userInfo->ReadRuleGeneration ,
3148
+ userInfo->AnyCommits );
3131
3149
} else {
3132
3150
AddCmdDeleteRange (request,
3133
3151
ikey, ikeyDeprecated);
@@ -3156,27 +3174,27 @@ TUserInfoBase& TPartition::GetOrCreatePendingUser(const TString& user,
3156
3174
TMaybe<ui64> readRuleGeneration)
3157
3175
{
3158
3176
TUserInfoBase* userInfo = nullptr ;
3159
- auto i = PendingUsersInfo.find (user);
3160
- if (i == PendingUsersInfo.end ()) {
3161
- auto ui = UsersInfoStorage->GetIfExists (user);
3162
- auto [p , _] = PendingUsersInfo.emplace (user, UsersInfoStorage->CreateUserInfo (user, readRuleGeneration));
3177
+ auto pendingUserIt = PendingUsersInfo.find (user);
3178
+ if (pendingUserIt == PendingUsersInfo.end ()) {
3179
+ auto userIt = UsersInfoStorage->GetIfExists (user);
3180
+ auto [newPendingUserIt , _] = PendingUsersInfo.emplace (user, UsersInfoStorage->CreateUserInfo (user, readRuleGeneration));
3163
3181
3164
- if (ui ) {
3165
- p ->second .Session = ui ->Session ;
3166
- p ->second .PartitionSessionId = ui ->PartitionSessionId ;
3167
- p ->second .PipeClient = ui ->PipeClient ;
3182
+ if (userIt ) {
3183
+ newPendingUserIt ->second .Session = userIt ->Session ;
3184
+ newPendingUserIt ->second .PartitionSessionId = userIt ->PartitionSessionId ;
3185
+ newPendingUserIt ->second .PipeClient = userIt ->PipeClient ;
3168
3186
3169
- p ->second .Generation = ui ->Generation ;
3170
- p ->second .Step = ui ->Step ;
3171
- p ->second .Offset = ui ->Offset ;
3172
- p ->second .ReadRuleGeneration = ui ->ReadRuleGeneration ;
3173
- p ->second .Important = ui ->Important ;
3174
- p ->second .ReadFromTimestamp = ui ->ReadFromTimestamp ;
3187
+ newPendingUserIt ->second .Generation = userIt ->Generation ;
3188
+ newPendingUserIt ->second .Step = userIt ->Step ;
3189
+ newPendingUserIt ->second .Offset = userIt ->Offset ;
3190
+ newPendingUserIt ->second .ReadRuleGeneration = userIt ->ReadRuleGeneration ;
3191
+ newPendingUserIt ->second .Important = userIt ->Important ;
3192
+ newPendingUserIt ->second .ReadFromTimestamp = userIt ->ReadFromTimestamp ;
3175
3193
}
3176
3194
3177
- userInfo = &p ->second ;
3195
+ userInfo = &newPendingUserIt ->second ;
3178
3196
} else {
3179
- userInfo = &i ->second ;
3197
+ userInfo = &pendingUserIt ->second ;
3180
3198
}
3181
3199
AffectedUsers.insert (user);
3182
3200
@@ -3205,7 +3223,9 @@ THolder<TEvPQ::TEvProxyResponse> TPartition::MakeReplyOk(const ui64 dst)
3205
3223
3206
3224
THolder<TEvPQ::TEvProxyResponse> TPartition::MakeReplyGetClientOffsetOk (const ui64 dst,
3207
3225
const i64 offset,
3208
- const TInstant writeTimestamp, const TInstant createTimestamp)
3226
+ const TInstant writeTimestamp,
3227
+ const TInstant createTimestamp,
3228
+ bool consumerHasAnyCommits)
3209
3229
{
3210
3230
auto response = MakeHolder<TEvPQ::TEvProxyResponse>(dst);
3211
3231
NKikimrClient::TResponse& resp = *response->Response ;
@@ -3225,6 +3245,7 @@ THolder<TEvPQ::TEvProxyResponse> TPartition::MakeReplyGetClientOffsetOk(const ui
3225
3245
user->SetEndOffset (EndOffset);
3226
3246
user->SetSizeLag (GetSizeLag (offset));
3227
3247
user->SetWriteTimestampEstimateMS (WriteTimestampEstimate.MilliSeconds ());
3248
+ user->SetClientHasAnyCommits (consumerHasAnyCommits);
3228
3249
3229
3250
return response;
3230
3251
}
0 commit comments