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