1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
|
#include "rpc_parameters_serialization.h"
#include <yt/cpp/mapreduce/common/helpers.h>
#include <yt/cpp/mapreduce/interface/config.h>
#include <yt/cpp/mapreduce/interface/client_method_options.h>
#include <yt/cpp/mapreduce/interface/operation.h>
#include <yt/cpp/mapreduce/interface/serialize.h>
#include <library/cpp/yson/node/node.h>
#include <library/cpp/yson/node/node_io.h>
#include <library/cpp/yson/node/node_builder.h>
#include <util/generic/guid.h>
#include <util/string/cast.h>
namespace NYT::NDetail::NRawClient {
using ::ToString;
////////////////////////////////////////////////////////////////////
static void SetTransactionIdParam(TNode* node, const TTransactionId& transactionId)
{
if (transactionId != TTransactionId()) {
(*node)["transaction_id"] = GetGuidAsString(transactionId);
}
}
static void SetOperationIdParam(TNode* node, const TOperationId& operationId)
{
(*node)["operation_id"] = GetGuidAsString(operationId);
}
static void SetAliasParam(TNode* node, const TString& alias)
{
(*node)["operation_alias"] = alias;
}
static void SetPathParam(TNode* node, const TString& pathPrefix, const TYPath& path)
{
TYPath updatedPath = AddPathPrefix(path, pathPrefix);
// Translate "//" to "/"
// Translate "//some/constom/prefix/from/config/" to "//some/constom/prefix/from/config"
if (path.empty() && updatedPath.EndsWith('/')) {
updatedPath.pop_back();
}
(*node)["path"] = std::move(updatedPath);
}
static TNode SerializeAttributeFilter(const TAttributeFilter& attributeFilter)
{
TNode result = TNode::CreateList();
for (const auto& attribute : attributeFilter.Attributes_) {
result.Add(attribute);
}
return result;
}
static TNode SerializeAttributeFilter(const TOperationAttributeFilter& attributeFilter)
{
TNode result = TNode::CreateList();
for (const auto& attribute : attributeFilter.Attributes_) {
result.Add(ToString(attribute));
}
return result;
}
template <typename TOptions>
static void SetFirstLastTabletIndex(TNode* node, const TOptions& options)
{
if (options.FirstTabletIndex_) {
(*node)["first_tablet_index"] = *options.FirstTabletIndex_;
}
if (options.LastTabletIndex_) {
(*node)["last_tablet_index"] = *options.LastTabletIndex_;
}
}
static TString GetDefaultTransactionTitle()
{
const auto processState = TProcessState::Get();
TStringStream res;
res << "User transaction. Created by: " << processState->UserName << " on " << processState->FqdnHostName
<< " client: " << processState->ClientVersion << " pid: " << processState->Pid;
if (!processState->CommandLine.empty()) {
res << " program: " << processState->CommandLine[0];
} else {
res << " command line is unknown probably NYT::Initialize was never called";
}
#ifndef NDEBUG
res << " build: debug";
#endif
return res.Str();
}
template <typename T>
void SerializeMasterReadOptions(TNode* node, const TMasterReadOptions<T>& options)
{
if (options.ReadFrom_) {
(*node)["read_from"] = ToString(*options.ReadFrom_);
}
}
////////////////////////////////////////////////////////////////////
TNode SerializeParamsForCreate(
const TTransactionId& transactionId,
const TString& pathPrefix,
const TYPath& path,
ENodeType type,
const TCreateOptions& options)
{
TNode result;
SetTransactionIdParam(&result, transactionId);
SetPathParam(&result, pathPrefix, path);
result["recursive"] = options.Recursive_;
result["type"] = ToString(type);
result["ignore_existing"] = options.IgnoreExisting_;
result["force"] = options.Force_;
if (options.Attributes_) {
result["attributes"] = *options.Attributes_;
}
return result;
}
TNode SerializeParamsForRemove(
const TTransactionId& transactionId,
const TString& pathPrefix,
const TYPath& path,
const TRemoveOptions& options)
{
TNode result;
SetTransactionIdParam(&result, transactionId);
SetPathParam(&result, pathPrefix, path);
result["recursive"] = options.Recursive_;
result["force"] = options.Force_;
return result;
}
TNode SerializeParamsForExists(
const TTransactionId& transactionId,
const TString& pathPrefix,
const TYPath& path,
const TExistsOptions& options)
{
TNode result;
SetTransactionIdParam(&result, transactionId);
SetPathParam(&result, pathPrefix, path);
SerializeMasterReadOptions(&result, options);
return result;
}
TNode SerializeParamsForGet(
const TTransactionId& transactionId,
const TString& pathPrefix,
const TYPath& path,
const TGetOptions& options)
{
TNode result;
SetTransactionIdParam(&result, transactionId);
SetPathParam(&result, pathPrefix, path);
SerializeMasterReadOptions(&result, options);
if (options.AttributeFilter_) {
result["attributes"] = SerializeAttributeFilter(*options.AttributeFilter_);
}
if (options.MaxSize_) {
result["max_size"] = *options.MaxSize_;
}
return result;
}
TNode SerializeParamsForSet(
const TTransactionId& transactionId,
const TString& pathPrefix,
const TYPath& path,
const TSetOptions& options)
{
TNode result;
SetTransactionIdParam(&result, transactionId);
SetPathParam(&result, pathPrefix, path);
result["recursive"] = options.Recursive_;
if (options.Force_) {
result["force"] = *options.Force_;
}
return result;
}
TNode SerializeParamsForMultisetAttributes(
const TTransactionId& transactionId,
const TString& pathPrefix,
const TYPath& path,
[[maybe_unused]] const TMultisetAttributesOptions& options)
{
TNode result;
SetTransactionIdParam(&result, transactionId);
SetPathParam(&result, pathPrefix, path);
if (options.Force_) {
result["force"] = *options.Force_;
}
return result;
}
TNode SerializeParamsForList(
const TTransactionId& transactionId,
const TString& pathPrefix,
const TYPath& path,
const TListOptions& options)
{
TNode result;
SetTransactionIdParam(&result, transactionId);
SetPathParam(&result, pathPrefix, path);
SerializeMasterReadOptions(&result, options);
if (options.MaxSize_) {
result["max_size"] = *options.MaxSize_;
}
if (options.AttributeFilter_) {
result["attributes"] = SerializeAttributeFilter(*options.AttributeFilter_);
}
return result;
}
TNode SerializeParamsForCopy(
const TTransactionId& transactionId,
const TString& pathPrefix,
const TYPath& sourcePath,
const TYPath& destinationPath,
const TCopyOptions& options)
{
TNode result;
SetTransactionIdParam(&result, transactionId);
result["source_path"] = AddPathPrefix(sourcePath, pathPrefix);
result["destination_path"] = AddPathPrefix(destinationPath, pathPrefix);
result["recursive"] = options.Recursive_;
result["force"] = options.Force_;
result["preserve_account"] = options.PreserveAccount_;
if (options.PreserveExpirationTime_) {
result["preserve_expiration_time"] = *options.PreserveExpirationTime_;
}
return result;
}
TNode SerializeParamsForMove(
const TTransactionId& transactionId,
const TString& pathPrefix,
const TYPath& sourcePath,
const TYPath& destinationPath,
const TMoveOptions& options)
{
TNode result;
SetTransactionIdParam(&result, transactionId);
result["source_path"] = AddPathPrefix(sourcePath, pathPrefix);
result["destination_path"] = AddPathPrefix(destinationPath, pathPrefix);
result["recursive"] = options.Recursive_;
result["force"] = options.Force_;
result["preserve_account"] = options.PreserveAccount_;
if (options.PreserveExpirationTime_) {
result["preserve_expiration_time"] = *options.PreserveExpirationTime_;
}
return result;
}
TNode SerializeParamsForLink(
const TTransactionId& transactionId,
const TString& pathPrefix,
const TYPath& targetPath,
const TYPath& linkPath,
const TLinkOptions& options)
{
TNode result;
SetTransactionIdParam(&result, transactionId);
result["target_path"] = AddPathPrefix(targetPath, pathPrefix);
result["link_path"] = AddPathPrefix(linkPath, pathPrefix);
result["recursive"] = options.Recursive_;
result["ignore_existing"] = options.IgnoreExisting_;
result["force"] = options.Force_;
if (options.Attributes_) {
result["attributes"] = *options.Attributes_;
}
return result;
}
TNode SerializeParamsForLock(
const TTransactionId& transactionId,
const TString& pathPrefix,
const TYPath& path,
ELockMode mode,
const TLockOptions& options)
{
TNode result;
SetTransactionIdParam(&result, transactionId);
SetPathParam(&result, pathPrefix, path);
result["mode"] = ToString(mode);
result["waitable"] = options.Waitable_;
if (options.AttributeKey_) {
result["attribute_key"] = *options.AttributeKey_;
}
if (options.ChildKey_) {
result["child_key"] = *options.ChildKey_;
}
return result;
}
TNode SerializeParamsForUnlock(
const TTransactionId& transactionId,
const TString& pathPrefix,
const TYPath& path,
const TUnlockOptions& options)
{
TNode result;
SetTransactionIdParam(&result, transactionId);
SetPathParam(&result, pathPrefix, path);
Y_UNUSED(options);
return result;
}
TNode SerializeParamsForConcatenate(
const TTransactionId& transactionId,
const TString& pathPrefix,
const TVector<TRichYPath>& sourcePaths,
const TRichYPath& destinationPath,
const TConcatenateOptions& options)
{
TNode result;
SetTransactionIdParam(&result, transactionId);
{
auto actualDestination = destinationPath;
actualDestination.Path(AddPathPrefix(actualDestination.Path_, pathPrefix));
if (options.Append_) {
actualDestination.Append(*options.Append_);
}
result["destination_path"] = PathToNode(actualDestination);
}
auto& sourcePathsNode = result["source_paths"];
for (const auto& path : sourcePaths) {
auto actualSource = path;
actualSource.Path(AddPathPrefix(actualSource.Path_, pathPrefix));
sourcePathsNode.Add(PathToNode(actualSource));
}
return result;
}
TNode SerializeParamsForPingTx(
const TTransactionId& transactionId)
{
TNode result;
SetTransactionIdParam(&result, transactionId);
return result;
}
TNode SerializeParamsForListOperations(
const TListOperationsOptions& options)
{
TNode result = TNode::CreateMap();
if (options.FromTime_) {
result["from_time"] = ToString(*options.FromTime_);
}
if (options.ToTime_) {
result["to_time"] = ToString(*options.ToTime_);
}
if (options.CursorTime_) {
result["cursor_time"] = ToString(*options.CursorTime_);
}
if (options.CursorDirection_) {
result["cursor_direction"] = ToString(*options.CursorDirection_);
}
if (options.Pool_) {
result["pool"] = *options.Pool_;
}
if (options.Filter_) {
result["filter"] = *options.Filter_;
}
if (options.User_) {
result["user"] = *options.User_;
}
if (options.State_) {
result["state"] = *options.State_;
}
if (options.Type_) {
result["type"] = ToString(*options.Type_);
}
if (options.WithFailedJobs_) {
result["with_failed_jobs"] = *options.WithFailedJobs_;
}
if (options.IncludeCounters_) {
result["include_counters"] = *options.IncludeCounters_;
}
if (options.IncludeArchive_) {
result["include_archive"] = *options.IncludeArchive_;
}
if (options.Limit_) {
result["limit"] = *options.Limit_;
}
return result;
}
TNode SerializeParamsForGetOperation(const std::variant<TString, TOperationId>& aliasOrOperationId, const TGetOperationOptions& options)
{
auto includeRuntime = options.IncludeRuntime_;
TNode result;
std::visit([&] (const auto& value) {
using TValue = std::decay_t<decltype(value)>;
if constexpr (std::is_same_v<TValue, TString>) {
SetAliasParam(&result, value);
if (includeRuntime.Empty()) {
// Getting operation by operation alias requires enabling this option.
// So enable it unless user explicitly set it.
includeRuntime = true;
}
} else if constexpr (std::is_same_v<TValue, TOperationId>) {
SetOperationIdParam(&result, value);
} else {
static_assert(std::is_same_v<TValue, void>, "unreachable");
}
}, aliasOrOperationId);
if (options.AttributeFilter_) {
result["attributes"] = SerializeAttributeFilter(*options.AttributeFilter_);
}
if (includeRuntime.Defined()) {
result["include_runtime"] = *includeRuntime;
}
return result;
}
TNode SerializeParamsForAbortOperation(const TOperationId& operationId)
{
TNode result;
SetOperationIdParam(&result, operationId);
return result;
}
TNode SerializeParamsForCompleteOperation(const TOperationId& operationId)
{
TNode result;
SetOperationIdParam(&result, operationId);
return result;
}
TNode SerializeParamsForSuspendOperation(
const TOperationId& operationId,
const TSuspendOperationOptions& options)
{
TNode result;
SetOperationIdParam(&result, operationId);
if (options.AbortRunningJobs_) {
result["abort_running_jobs"] = *options.AbortRunningJobs_;
}
return result;
}
TNode SerializeParamsForResumeOperation(
const TOperationId& operationId,
const TResumeOperationOptions& options)
{
TNode result;
SetOperationIdParam(&result, operationId);
Y_UNUSED(options);
return result;
}
TNode SerializeParamsForUpdateOperationParameters(
const TOperationId& operationId,
const TUpdateOperationParametersOptions& options)
{
TNode result;
SetOperationIdParam(&result, operationId);
TNode& parameters = result["parameters"];
if (options.Pool_) {
parameters["pool"] = *options.Pool_;
}
if (options.Weight_) {
parameters["weight"] = *options.Weight_;
}
if (!options.Owners_.empty()) {
parameters["owners"] = TNode::CreateList();
for (const auto& owner : options.Owners_) {
parameters["owners"].Add(owner);
}
}
if (options.SchedulingOptionsPerPoolTree_) {
parameters["scheduling_options_per_pool_tree"] = TNode::CreateMap();
for (const auto& entry : options.SchedulingOptionsPerPoolTree_->Options_) {
auto schedulingOptionsNode = TNode::CreateMap();
const auto& schedulingOptions = entry.second;
if (schedulingOptions.Pool_) {
schedulingOptionsNode["pool"] = *schedulingOptions.Pool_;
}
if (schedulingOptions.Weight_) {
schedulingOptionsNode["weight"] = *schedulingOptions.Weight_;
}
if (schedulingOptions.ResourceLimits_) {
auto resourceLimitsNode = TNode::CreateMap();
const auto& resourceLimits = *schedulingOptions.ResourceLimits_;
if (resourceLimits.UserSlots_) {
resourceLimitsNode["user_slots"] = *resourceLimits.UserSlots_;
}
if (resourceLimits.Memory_) {
resourceLimitsNode["memory"] = *resourceLimits.Memory_;
}
if (resourceLimits.Cpu_) {
resourceLimitsNode["cpu"] = *resourceLimits.Cpu_;
}
if (resourceLimits.Network_) {
resourceLimitsNode["network"] = *resourceLimits.Network_;
}
schedulingOptionsNode["resource_limits"] = std::move(resourceLimitsNode);
}
parameters["scheduling_options_per_pool_tree"][entry.first] = std::move(schedulingOptionsNode);
}
}
return result;
}
TNode SerializeParamsForGetJob(
const TOperationId& operationId,
const TJobId& jobId,
const TGetJobOptions& /* options */)
{
TNode result;
SetOperationIdParam(&result, operationId);
result["job_id"] = GetGuidAsString(jobId);
return result;
}
TNode SerializeParamsForListJobs(
const TOperationId& operationId,
const TListJobsOptions& options)
{
TNode result;
SetOperationIdParam(&result, operationId);
if (options.Type_) {
result["type"] = ToString(*options.Type_);
}
if (options.State_) {
result["state"] = ToString(*options.State_);
}
if (options.Address_) {
result["address"] = *options.Address_;
}
if (options.WithStderr_) {
result["with_stderr"] = *options.WithStderr_;
}
if (options.WithSpec_) {
result["with_spec"] = *options.WithSpec_;
}
if (options.WithFailContext_) {
result["with_fail_context"] = *options.WithFailContext_;
}
if (options.WithMonitoringDescriptor_) {
result["with_monitoring_descriptor"] = *options.WithMonitoringDescriptor_;
}
if (options.SortField_) {
result["sort_field"] = ToString(*options.SortField_);
}
if (options.SortOrder_) {
result["sort_order"] = ToString(*options.SortOrder_);
}
if (options.Offset_) {
result["offset"] = *options.Offset_;
}
if (options.Limit_) {
result["limit"] = *options.Limit_;
}
if (options.IncludeCypress_) {
result["include_cypress"] = *options.IncludeCypress_;
}
if (options.IncludeArchive_) {
result["include_archive"] = *options.IncludeArchive_;
}
if (options.IncludeControllerAgent_) {
result["include_controller_agent"] = *options.IncludeControllerAgent_;
}
return result;
}
TNode SerializeParametersForInsertRows(
const TString& pathPrefix,
const TYPath& path,
const TInsertRowsOptions& options)
{
TNode result;
SetPathParam(&result, pathPrefix, path);
if (options.Aggregate_) {
result["aggregate"] = *options.Aggregate_;
}
if (options.Update_) {
result["update"] = *options.Update_;
}
if (options.Atomicity_) {
result["atomicity"] = ToString(*options.Atomicity_);
}
if (options.Durability_) {
result["durability"] = ToString(*options.Durability_);
}
if (options.RequireSyncReplica_) {
result["require_sync_replica"] = *options.RequireSyncReplica_;
}
return result;
}
TNode SerializeParametersForDeleteRows(
const TString& pathPrefix,
const TYPath& path,
const TDeleteRowsOptions& options)
{
TNode result;
SetPathParam(&result, pathPrefix, path);
if (options.Atomicity_) {
result["atomicity"] = ToString(*options.Atomicity_);
}
if (options.Durability_) {
result["durability"] = ToString(*options.Durability_);
}
if (options.RequireSyncReplica_) {
result["require_sync_replica"] = *options.RequireSyncReplica_;
}
return result;
}
TNode SerializeParametersForTrimRows(
const TString& pathPrefix,
const TYPath& path,
const TTrimRowsOptions& /* options*/)
{
TNode result;
SetPathParam(&result, pathPrefix, path);
return result;
}
TNode SerializeParamsForParseYPath(const TRichYPath& path)
{
TNode result;
result["path"] = PathToNode(path);
return result;
}
TNode SerializeParamsForEnableTableReplica(
const TReplicaId& replicaId)
{
TNode result;
result["replica_id"] = GetGuidAsString(replicaId);
return result;
}
TNode SerializeParamsForDisableTableReplica(
const TReplicaId& replicaId)
{
TNode result;
result["replica_id"] = GetGuidAsString(replicaId);
return result;
}
TNode SerializeParamsForAlterTableReplica(const TReplicaId& replicaId, const TAlterTableReplicaOptions& options)
{
TNode result;
result["replica_id"] = GetGuidAsString(replicaId);
if (options.Enabled_) {
result["enabled"] = *options.Enabled_;
}
if (options.Mode_) {
result["mode"] = ToString(*options.Mode_);
}
return result;
}
TNode SerializeParamsForFreezeTable(
const TString& pathPrefix,
const TYPath& path,
const TFreezeTableOptions& options)
{
TNode result;
SetPathParam(&result, pathPrefix, path);
SetFirstLastTabletIndex(&result, options);
return result;
}
TNode SerializeParamsForUnfreezeTable(
const TString& pathPrefix,
const TYPath& path,
const TUnfreezeTableOptions& options)
{
TNode result;
SetPathParam(&result, pathPrefix, path);
SetFirstLastTabletIndex(&result, options);
return result;
}
TNode SerializeParamsForAlterTable(
const TTransactionId& transactionId,
const TString& pathPrefix,
const TYPath& path,
const TAlterTableOptions& options)
{
TNode result;
SetTransactionIdParam(&result, transactionId);
SetPathParam(&result, pathPrefix, path);
if (options.Dynamic_) {
result["dynamic"] = *options.Dynamic_;
}
if (options.Schema_) {
TNode schema;
{
TNodeBuilder builder(&schema);
Serialize(*options.Schema_, &builder);
}
result["schema"] = schema;
}
if (options.UpstreamReplicaId_) {
result["upstream_replica_id"] = GetGuidAsString(*options.UpstreamReplicaId_);
}
return result;
}
TNode SerializeParamsForGetTableColumnarStatistics(
const TTransactionId& transactionId,
const TVector<TRichYPath>& paths,
const TGetTableColumnarStatisticsOptions& options)
{
TNode result;
SetTransactionIdParam(&result, transactionId);
for (const auto& path : paths) {
result["paths"].Add(PathToNode(path));
}
if (options.FetcherMode_) {
result["fetcher_mode"] = ToString(*options.FetcherMode_);
}
return result;
}
TNode SerializeParamsForGetTablePartitions(
const TTransactionId& transactionId,
const TVector<TRichYPath>& paths,
const TGetTablePartitionsOptions& options)
{
TNode result;
SetTransactionIdParam(&result, transactionId);
for (const auto& path : paths) {
result["paths"].Add(PathToNode(path));
}
result["partition_mode"] = ToString(options.PartitionMode_);
result["data_weight_per_partition"] = options.DataWeightPerPartition_;
if (options.MaxPartitionCount_) {
result["max_partition_count"] = *options.MaxPartitionCount_;
}
result["adjust_data_weight_per_partition"] = options.AdjustDataWeightPerPartition_;
return result;
}
TNode SerializeParamsForGetFileFromCache(
const TTransactionId& transactionId,
const TString& md5Signature,
const TYPath& cachePath,
const TGetFileFromCacheOptions&)
{
TNode result;
SetTransactionIdParam(&result, transactionId);
result["md5"] = md5Signature;
result["cache_path"] = cachePath;
return result;
}
TNode SerializeParamsForPutFileToCache(
const TTransactionId& transactionId,
const TString& pathPrefix,
const TYPath& filePath,
const TString& md5Signature,
const TYPath& cachePath,
const TPutFileToCacheOptions& options)
{
TNode result;
SetTransactionIdParam(&result, transactionId);
SetPathParam(&result, pathPrefix, filePath);
result["md5"] = md5Signature;
result["cache_path"] = cachePath;
if (options.PreserveExpirationTimeout_) {
result["preserve_expiration_timeout"] = *options.PreserveExpirationTimeout_;
}
return result;
}
TNode SerializeParamsForSkyShareTable(
const TString& serverName,
const TString& pathPrefix,
const std::vector<TYPath>& tablePaths,
const TSkyShareTableOptions& options)
{
TNode result;
if (tablePaths.size() == 1) {
SetPathParam(&result, pathPrefix, tablePaths[0]);
} else {
auto pathList = TNode::CreateList();
for (const auto& p : tablePaths) {
pathList.Add(AddPathPrefix(p, pathPrefix));
}
result["paths"] = pathList;
}
result["cluster"] = serverName;
if (options.KeyColumns_) {
auto keyColumnsList = TNode::CreateList();
for (const auto& s : options.KeyColumns_->Parts_) {
if (s.empty()) {
continue;
}
keyColumnsList.Add(s);
}
result["key_columns"] = keyColumnsList;
}
if (options.EnableFastbone_) {
result["enable_fastbone"] = *options.EnableFastbone_;
}
return result;
}
TNode SerializeParamsForCheckPermission(
const TString& user,
EPermission permission,
const TString& pathPrefix,
const TYPath& path,
const TCheckPermissionOptions& options)
{
TNode result;
SetPathParam(&result, pathPrefix, path);
result["path"] = path;
result["user"] = user;
result["permission"] = ToString(permission);
if (!options.Columns_.empty()) {
result["columns"] = TNode::CreateList();
result["columns"].AsList().assign(options.Columns_.begin(), options.Columns_.end());
}
return result;
}
TNode SerializeParamsForGetTabletInfos(
const TString& pathPrefix,
const TYPath& path,
const TVector<int>& tabletIndexes,
const TGetTabletInfosOptions& options)
{
Y_UNUSED(options);
TNode result;
SetPathParam(&result, pathPrefix, path);
result["tablet_indexes"] = TNode::CreateList();
result["tablet_indexes"].AsList().assign(tabletIndexes.begin(), tabletIndexes.end());
return result;
}
TNode SerializeParamsForAbortTransaction(const TTransactionId& transactionId)
{
TNode result;
SetTransactionIdParam(&result, transactionId);
return result;
}
TNode SerializeParamsForCommitTransaction(const TTransactionId& transactionId)
{
TNode result;
SetTransactionIdParam(&result, transactionId);
return result;
}
TNode SerializeParamsForStartTransaction(
const TTransactionId& parentTransactionId,
TDuration txTimeout,
const TStartTransactionOptions& options)
{
TNode result;
SetTransactionIdParam(&result, parentTransactionId);
result["timeout"] = static_cast<i64>((options.Timeout_.GetOrElse(txTimeout).MilliSeconds()));
if (options.Deadline_) {
result["deadline"] = ToString(options.Deadline_);
}
if (options.PingAncestors_) {
result["ping_ancestor_transactions"] = true;
}
if (options.Attributes_ && !options.Attributes_->IsMap()) {
ythrow TApiUsageError() << "Attributes must be a Map node";
}
auto attributes = options.Attributes_.GetOrElse(TNode::CreateMap());
if (options.Title_) {
attributes["title"] = *options.Title_;
} else if (!attributes.HasKey("title")) {
attributes["title"] = GetDefaultTransactionTitle();
}
result["attributes"] = attributes;
return result;
}
////////////////////////////////////////////////////////////////////////////////
} // namespace NYT::NDetail::NRawClient
|