@@ -59,15 +59,18 @@ struct TCheckpointContext : public TThrRefBase {
59
59
TGenerationContextPtr GenerationContext;
60
60
TCheckpointGraphDescriptionContextPtr CheckpointGraphDescriptionContext;
61
61
IEntityIdGenerator::TPtr EntityIdGenerator;
62
+ TExecDataQuerySettings Settings;
62
63
63
64
TCheckpointContext (const TCheckpointId& id,
64
65
ECheckpointStatus status,
65
66
ECheckpointStatus expected,
66
- ui64 stateSizeBytes)
67
+ ui64 stateSizeBytes,
68
+ TExecDataQuerySettings settings)
67
69
: CheckpointId(id)
68
70
, Status(status)
69
71
, ExpectedStatus(expected)
70
72
, StateSizeBytes(stateSizeBytes)
73
+ , Settings(settings)
71
74
{
72
75
}
73
76
};
@@ -220,7 +223,7 @@ TFuture<TStatus> CreateCheckpoint(const TCheckpointContextPtr& context) {
220
223
}
221
224
222
225
auto ttxControl = TTxControl::Tx (*generationContext->Transaction ).CommitTx ();
223
- return generationContext->Session .ExecuteDataQuery (query, ttxControl, params.Build ()).Apply (
226
+ return generationContext->Session .ExecuteDataQuery (query, ttxControl, params.Build (), context-> Settings ).Apply (
224
227
[] (const TFuture<TDataQueryResult>& future) {
225
228
TStatus status = future.GetValue ();
226
229
return status;
@@ -236,21 +239,41 @@ TFuture<TStatus> UpdateCheckpoint(const TCheckpointContextPtr& context) {
236
239
auto query = Sprintf (R"(
237
240
--!syntax_v1
238
241
PRAGMA TablePathPrefix("%s");
239
- $ts = cast(%lu as Timestamp);
242
+ DECLARE $graph_id AS String;
243
+ DECLARE $coordinator_generation AS Uint64;
244
+ DECLARE $seq_no AS Uint64;
245
+ DECLARE $status AS Uint8;
246
+ DECLARE $state_size AS Uint64;
247
+ DECLARE $ts AS Timestamp;
240
248
241
249
UPSERT INTO %s (graph_id, coordinator_generation, seq_no, status, state_size, modified_by) VALUES
242
- ("%s", %lu, %lu, %u, %lu , $ts);
250
+ ($graph_id, $coordinator_generation, $seq_no, $status, $state_size , $ts);
243
251
)" , generationContext->TablePathPrefix .c_str (),
244
- TInstant::Now ().MicroSeconds (),
245
- CheckpointsMetadataTable,
246
- generationContext->PrimaryKey .c_str (),
247
- context->CheckpointId .CoordinatorGeneration ,
248
- context->CheckpointId .SeqNo ,
249
- (ui32)context->Status ,
250
- context->StateSizeBytes );
252
+ CheckpointsMetadataTable);
253
+
254
+ NYdb::TParamsBuilder params;
255
+ params
256
+ .AddParam (" $graph_id" )
257
+ .String (generationContext->PrimaryKey )
258
+ .Build ()
259
+ .AddParam (" $coordinator_generation" )
260
+ .Uint64 (context->CheckpointId .CoordinatorGeneration )
261
+ .Build ()
262
+ .AddParam (" $seq_no" )
263
+ .Uint64 (context->CheckpointId .SeqNo )
264
+ .Build ()
265
+ .AddParam (" $status" )
266
+ .Uint8 ((ui8)context->Status )
267
+ .Build ()
268
+ .AddParam (" $state_size" )
269
+ .Uint64 (context->StateSizeBytes )
270
+ .Build ()
271
+ .AddParam (" $ts" )
272
+ .Timestamp (TInstant::Now ())
273
+ .Build ();
251
274
252
275
auto ttxControl = TTxControl::Tx (*generationContext->Transaction ).CommitTx ();
253
- return generationContext->Session .ExecuteDataQuery (query, ttxControl).Apply (
276
+ return generationContext->Session .ExecuteDataQuery (query, ttxControl, params. Build (), context-> Settings ).Apply (
254
277
[] (const TFuture<TDataQueryResult>& future) {
255
278
TStatus status = future.GetValue ();
256
279
return status;
@@ -264,15 +287,20 @@ TFuture<TDataQueryResult> SelectGraphDescId(const TCheckpointContextPtr& context
264
287
auto query = Sprintf (R"(
265
288
--!syntax_v1
266
289
PRAGMA TablePathPrefix("%s");
290
+ DECLARE $graph_desc_id AS String;
267
291
268
292
SELECT ref_count
269
293
FROM %s
270
- WHERE id = "%s" ;
294
+ WHERE id = $graph_desc_id ;
271
295
)" , generationContext->TablePathPrefix .c_str (),
272
- CheckpointsGraphsDescriptionTable,
273
- graphDescContext->GraphDescId .c_str ());
296
+ CheckpointsGraphsDescriptionTable);
297
+ NYdb::TParamsBuilder params;
298
+ params
299
+ .AddParam (" $graph_desc_id" )
300
+ .String (graphDescContext->GraphDescId )
301
+ .Build ();
274
302
275
- return generationContext->Session .ExecuteDataQuery (query, TTxControl::Tx (*generationContext->Transaction ));
303
+ return generationContext->Session .ExecuteDataQuery (query, TTxControl::Tx (*generationContext->Transaction ), params. Build (), context-> Settings );
276
304
}
277
305
278
306
bool GraphDescIdExists (const TFuture<TDataQueryResult>& result) {
@@ -292,6 +320,7 @@ TFuture<TStatus> GenerateGraphDescId(const TCheckpointContextPtr& context) {
292
320
if (!result.GetValue ().IsSuccess ()) {
293
321
return MakeFuture<TStatus>(result.GetValue ());
294
322
}
323
+ // TODO racing!
295
324
if (!GraphDescIdExists (result)) {
296
325
return MakeFuture (TStatus (EStatus::SUCCESS, NYdb::NIssue::TIssues ()));
297
326
} else {
@@ -443,19 +472,33 @@ TFuture<TDataQueryResult> SelectCheckpoint(const TCheckpointContextPtr& context)
443
472
auto query = Sprintf (R"(
444
473
--!syntax_v1
445
474
PRAGMA TablePathPrefix("%s");
475
+ DECLARE $graph_id AS String;
476
+ DECLARE $coordinator_generation AS Uint64;
477
+ DECLARE $seq_no AS Uint64;
446
478
447
479
SELECT status
448
480
FROM %s
449
- WHERE graph_id = "%s" AND coordinator_generation = %lu AND seq_no = %lu ;
481
+ WHERE graph_id = $graph_id AND coordinator_generation = $coordinator_generation AND seq_no = $seq_no ;
450
482
)" , generationContext->TablePathPrefix .c_str (),
451
- CheckpointsMetadataTable,
452
- generationContext->PrimaryKey .c_str (),
453
- context->CheckpointId .CoordinatorGeneration ,
454
- context->CheckpointId .SeqNo );
483
+ CheckpointsMetadataTable);
484
+
485
+ NYdb::TParamsBuilder params;
486
+ params
487
+ .AddParam (" $graph_id" )
488
+ .String (generationContext->PrimaryKey )
489
+ .Build ()
490
+ .AddParam (" $coordinator_generation" )
491
+ .Uint64 (context->CheckpointId .CoordinatorGeneration )
492
+ .Build ()
493
+ .AddParam (" $seq_no" )
494
+ .Uint64 (context->CheckpointId .SeqNo )
495
+ .Build ();
455
496
456
497
return generationContext->Session .ExecuteDataQuery (
457
498
query,
458
- TTxControl::Tx (*generationContext->Transaction ));
499
+ TTxControl::Tx (*generationContext->Transaction ),
500
+ params.Build (),
501
+ context->Settings );
459
502
}
460
503
461
504
TFuture<TStatus> CheckCheckpoint (
@@ -768,7 +811,7 @@ TFuture<ICheckpointStorage::TCreateCheckpointResult> TCheckpointStorage::CreateC
768
811
ECheckpointStatus status)
769
812
{
770
813
Y_ABORT_UNLESS (graphDescId);
771
- auto checkpointContext = MakeIntrusive<TCheckpointContext>(checkpointId, status, ECheckpointStatus::Pending, 0ul );
814
+ auto checkpointContext = MakeIntrusive<TCheckpointContext>(checkpointId, status, ECheckpointStatus::Pending, 0ul , DefaultExecDataQuerySettings () );
772
815
checkpointContext->CheckpointGraphDescriptionContext = MakeIntrusive<TCheckpointGraphDescriptionContext>(graphDescId);
773
816
return CreateCheckpointImpl (coordinator, checkpointContext);
774
817
}
@@ -779,7 +822,7 @@ TFuture<ICheckpointStorage::TCreateCheckpointResult> TCheckpointStorage::CreateC
779
822
const NProto::TCheckpointGraphDescription& graphDesc,
780
823
ECheckpointStatus status)
781
824
{
782
- auto checkpointContext = MakeIntrusive<TCheckpointContext>(checkpointId, status, ECheckpointStatus::Pending, 0ul );
825
+ auto checkpointContext = MakeIntrusive<TCheckpointContext>(checkpointId, status, ECheckpointStatus::Pending, 0ul , DefaultExecDataQuerySettings () );
783
826
checkpointContext->CheckpointGraphDescriptionContext = MakeIntrusive<TCheckpointGraphDescriptionContext>(graphDesc);
784
827
checkpointContext->EntityIdGenerator = EntityIdGenerator;
785
828
return CreateCheckpointImpl (coordinator, checkpointContext);
@@ -820,7 +863,7 @@ TFuture<TIssues> TCheckpointStorage::UpdateCheckpointStatus(
820
863
ECheckpointStatus prevStatus,
821
864
ui64 stateSizeBytes)
822
865
{
823
- auto checkpointContext = MakeIntrusive<TCheckpointContext>(checkpointId, newStatus, prevStatus, stateSizeBytes);
866
+ auto checkpointContext = MakeIntrusive<TCheckpointContext>(checkpointId, newStatus, prevStatus, stateSizeBytes, DefaultExecDataQuerySettings () );
824
867
auto future = YdbConnection->TableClient .RetryOperation (
825
868
[prefix = YdbConnection->TablePathPrefix , coordinator, checkpointContext] (TSession session) {
826
869
auto generationContext = MakeIntrusive<TGenerationContext>(
@@ -846,7 +889,7 @@ TFuture<TIssues> TCheckpointStorage::AbortCheckpoint(
846
889
const TCoordinatorId& coordinator,
847
890
const TCheckpointId& checkpointId)
848
891
{
849
- auto checkpointContext = MakeIntrusive<TCheckpointContext>(checkpointId, ECheckpointStatus::Aborted, ECheckpointStatus::Pending, 0ul );
892
+ auto checkpointContext = MakeIntrusive<TCheckpointContext>(checkpointId, ECheckpointStatus::Aborted, ECheckpointStatus::Pending, 0ul , DefaultExecDataQuerySettings () );
850
893
auto future = YdbConnection->TableClient .RetryOperation (
851
894
[prefix = YdbConnection->TablePathPrefix , coordinator, checkpointContext] (TSession session) {
852
895
auto generationContext = MakeIntrusive<TGenerationContext>(
@@ -905,28 +948,35 @@ TFuture<ICheckpointStorage::TGetCheckpointsResult> TCheckpointStorage::GetCheckp
905
948
906
949
TFuture<TIssues> TCheckpointStorage::DeleteGraph (const TString& graphId) {
907
950
auto future = YdbConnection->TableClient .RetryOperation (
908
- [prefix = YdbConnection->TablePathPrefix , graphId] (TSession session) {
951
+ [prefix = YdbConnection->TablePathPrefix , graphId, settings = DefaultExecDataQuerySettings () ] (TSession session) {
909
952
// TODO: use prepared queries
910
953
auto query = Sprintf (R"(
911
954
--!syntax_v1
912
955
PRAGMA TablePathPrefix("%s");
956
+ DECLARE $graph_id AS String;
913
957
914
958
DELETE
915
959
FROM %s
916
- WHERE graph_id = "%s" ;
960
+ WHERE graph_id = $graph_id ;
917
961
918
962
DELETE
919
963
FROM %s
920
- WHERE graph_id = "%s" ;
964
+ WHERE graph_id = $graph_id ;
921
965
)" , prefix.c_str (),
922
966
CoordinatorsSyncTable,
923
- graphId.c_str (),
924
- CheckpointsMetadataTable,
925
- graphId.c_str ());
967
+ CheckpointsMetadataTable);
968
+
969
+ NYdb::TParamsBuilder params;
970
+ params
971
+ .AddParam (" $graph_id" )
972
+ .String (graphId)
973
+ .Build ();
926
974
927
975
auto future = session.ExecuteDataQuery (
928
976
query,
929
- TTxControl::BeginTx (TTxSettings::SerializableRW ()).CommitTx ());
977
+ TTxControl::BeginTx (TTxSettings::SerializableRW ()).CommitTx (),
978
+ params.Build (),
979
+ settings);
930
980
931
981
return future.Apply (
932
982
[] (const TFuture<TDataQueryResult>& future) {
@@ -943,30 +993,48 @@ TFuture<TIssues> TCheckpointStorage::MarkCheckpointsGC(
943
993
const TCheckpointId& checkpointUpperBound)
944
994
{
945
995
auto future = YdbConnection->TableClient .RetryOperation (
946
- [prefix = YdbConnection->TablePathPrefix , graphId, checkpointUpperBound] (TSession session) {
996
+ [prefix = YdbConnection->TablePathPrefix , graphId, checkpointUpperBound, thisPtr = TIntrusivePtr ( this ) ] (TSession session) {
947
997
// TODO: use prepared queries
948
998
auto query = Sprintf (R"(
949
999
--!syntax_v1
950
1000
PRAGMA TablePathPrefix("%s");
951
- $ts = cast(%lu as Timestamp);
1001
+ DECLARE $ts AS Timestamp;
1002
+ DECLARE $status AS Uint8;
1003
+ DECLARE $graph_id AS String;
1004
+ DECLARE $coordinator_generation AS Uint64;
1005
+ DECLARE $seq_no AS Uint64;
952
1006
953
1007
UPDATE %s
954
- SET status = %u , modified_by = $ts
955
- WHERE graph_id = "%s" AND
956
- (coordinator_generation < %lu OR
957
- (coordinator_generation = %lu AND seq_no < %lu ));
1008
+ SET status = $status , modified_by = $ts
1009
+ WHERE graph_id = $graph_id AND
1010
+ (coordinator_generation < $coordinator_generation OR
1011
+ (coordinator_generation = $coordinator_generation AND seq_no < $seq_no ));
958
1012
)" , prefix.c_str (),
959
- TInstant::Now ().MicroSeconds (),
960
- CheckpointsMetadataTable,
961
- (ui32)ECheckpointStatus::GC,
962
- graphId.c_str (),
963
- checkpointUpperBound.CoordinatorGeneration ,
964
- checkpointUpperBound.CoordinatorGeneration ,
965
- checkpointUpperBound.SeqNo );
1013
+ CheckpointsMetadataTable);
1014
+
1015
+ NYdb::TParamsBuilder params;
1016
+ params
1017
+ .AddParam (" $graph_id" )
1018
+ .String (graphId)
1019
+ .Build ()
1020
+ .AddParam (" $coordinator_generation" )
1021
+ .Uint64 (checkpointUpperBound.CoordinatorGeneration )
1022
+ .Build ()
1023
+ .AddParam (" $seq_no" )
1024
+ .Uint64 (checkpointUpperBound.SeqNo )
1025
+ .Build ()
1026
+ .AddParam (" $status" )
1027
+ .Uint8 ((ui8)ECheckpointStatus::GC)
1028
+ .Build ()
1029
+ .AddParam (" $ts" )
1030
+ .Timestamp (TInstant::Now ())
1031
+ .Build ();
966
1032
967
1033
auto future = session.ExecuteDataQuery (
968
1034
query,
969
- TTxControl::BeginTx (TTxSettings::SerializableRW ()).CommitTx ());
1035
+ TTxControl::BeginTx (TTxSettings::SerializableRW ()).CommitTx (),
1036
+ params.Build (),
1037
+ thisPtr->DefaultExecDataQuerySettings ());
970
1038
971
1039
return future.Apply (
972
1040
[] (const TFuture<TDataQueryResult>& future) {
@@ -983,7 +1051,7 @@ TFuture<TIssues> TCheckpointStorage::DeleteMarkedCheckpoints(
983
1051
const TCheckpointId& checkpointUpperBound)
984
1052
{
985
1053
auto future = YdbConnection->TableClient .RetryOperation (
986
- [prefix = YdbConnection->TablePathPrefix , graphId, checkpointUpperBound] (TSession session) {
1054
+ [prefix = YdbConnection->TablePathPrefix , graphId, checkpointUpperBound, settings = DefaultExecDataQuerySettings () ] (TSession session) {
987
1055
// TODO: use prepared queries
988
1056
using namespace fmt ::literals;
989
1057
const TString query = fmt::format (R"sql(
@@ -1042,7 +1110,7 @@ TFuture<TIssues> TCheckpointStorage::DeleteMarkedCheckpoints(
1042
1110
1043
1111
auto future = session.ExecuteDataQuery (
1044
1112
query,
1045
- TTxControl::BeginTx (TTxSettings::SerializableRW ()).CommitTx (), params.Build ());
1113
+ TTxControl::BeginTx (TTxSettings::SerializableRW ()).CommitTx (), params.Build (), settings );
1046
1114
1047
1115
return future.Apply (
1048
1116
[] (const TFuture<TDataQueryResult>& future) {
0 commit comments