11
11
#include < ydb/public/sdk/cpp/include/ydb-cpp-sdk/client/proto/accessor.h>
12
12
13
13
#include < util/generic/set.h>
14
+ #include < util/stream/format.h>
14
15
#include < util/stream/str.h>
15
16
#include < util/string/cast.h>
16
17
#include < util/string/hex.h>
17
18
#include < util/string/vector.h>
18
19
#include < util/string/join.h>
20
+ #include < util/string/strip.h>
19
21
20
22
#define TIMESTAMP_FORMAT_OPTION_DESCRIPTION " Timestamp may be specified in unix time format (seconds from 1970.01.01) or in ISO-8601 format (like 2020-07-10T15:00:00Z)"
21
23
@@ -162,6 +164,28 @@ namespace NYdb::NConsoleClient {
162
164
163
165
return exists->second ;
164
166
}
167
+
168
+ TDuration ParseDurationHours (const TStringBuf str) {
169
+ double hours = 0 ;
170
+ if (!TryFromString (str, hours)) {
171
+ throw TMisuseException () << " Invalid hours duration '" << str << " '" ;
172
+ }
173
+ if (hours < 0 ) {
174
+ throw TMisuseException () << " Duration must be non-negative" ;
175
+ }
176
+ if (!std::isfinite (hours)) {
177
+ throw TMisuseException () << " Duration must be finite" ;
178
+ }
179
+ return TDuration::Seconds (hours * 3600 ); // using floating-point ctor with saturation
180
+ }
181
+
182
+ TDuration ParseDuration (TStringBuf str) {
183
+ StripInPlace (str);
184
+ if (!str.empty () && !IsAsciiAlpha (str.back ())) {
185
+ throw TMisuseException () << " Duration must ends with a unit name (ex. 'h' for hours, 's' for seconds)" ;
186
+ }
187
+ return TDuration::Parse (str);
188
+ }
165
189
}
166
190
167
191
void TCommandWithSupportedCodecs::AddAllowedCodecs (TClientCommand::TConfig& config, const TVector<NYdb::NTopic::ECodec>& supportedCodecs) {
@@ -343,10 +367,18 @@ namespace NYdb::NConsoleClient {
343
367
.Optional ()
344
368
.StoreResult (&MinActivePartitions_)
345
369
.DefaultValue (1 );
346
- config.Opts ->AddLongOption (" retention-period-hours" , " Duration in hours for which data in topic is stored" )
347
- .DefaultValue (24 )
370
+ config.Opts ->AddLongOption (" retention-period-hours" , TStringBuilder ()
371
+ << " Duration in hours for which data in topic is stored "
372
+ << " (default: " << NColorizer::StdOut ().CyanColor () << RetentionPeriod_.Hours () << NColorizer::StdOut ().OldColor () << " )" )
373
+ .Hidden ()
374
+ .Optional ()
375
+ .RequiredArgument (" HOURS" )
376
+ .StoreMappedResult (&RetentionPeriod_, ParseDurationHours);
377
+ config.Opts ->AddLongOption (" retention-period" , TStringBuilder ()
378
+ << " Duration for which data in topic is stored (ex. '72h', '1440m') "
379
+ << " (default: " << NColorizer::StdOut ().CyanColor () << HumanReadable (RetentionPeriod_) << NColorizer::StdOut ().OldColor () << " )" )
348
380
.Optional ()
349
- .StoreResult (&RetentionPeriodHours_ );
381
+ .StoreMappedResult (&RetentionPeriod_, ParseDuration );
350
382
config.Opts ->AddLongOption (" partition-write-speed-kbps" , " Partition write speed in kilobytes per second" )
351
383
.DefaultValue (1024 )
352
384
.Optional ()
@@ -370,6 +402,8 @@ namespace NYdb::NConsoleClient {
370
402
.Optional ()
371
403
.Hidden ()
372
404
.StoreResult (&PartitionsPerTablet_);
405
+
406
+ config.Opts ->MutuallyExclusive (" retention-period-hours" , " retention-period" );
373
407
}
374
408
375
409
void TCommandTopicCreate::Parse (TConfig& config) {
@@ -409,7 +443,7 @@ namespace NYdb::NConsoleClient {
409
443
settings.MeteringMode (GetMeteringMode ());
410
444
}
411
445
412
- settings.RetentionPeriod (TDuration::Hours (RetentionPeriodHours_) );
446
+ settings.RetentionPeriod (RetentionPeriod_ );
413
447
settings.RetentionStorageMb (RetentionStorageMb_);
414
448
415
449
if (PartitionsPerTablet_.Defined ()) {
@@ -434,9 +468,14 @@ namespace NYdb::NConsoleClient {
434
468
config.Opts ->AddLongOption (" partitions-count" , " Initial and minimum number of partitions for topic" )
435
469
.Optional ()
436
470
.StoreResult (&MinActivePartitions_);
437
- config.Opts ->AddLongOption (" retention-period-hours" , " Duration for which data in topic is stored" )
471
+ config.Opts ->AddLongOption (" retention-period-hours" , " Duration in hours for which data in topic is stored" )
472
+ .Hidden ()
438
473
.Optional ()
439
- .StoreResult (&RetentionPeriodHours_);
474
+ .RequiredArgument (" HOURS" )
475
+ .StoreMappedResult (&RetentionPeriod_, ParseDurationHours);
476
+ config.Opts ->AddLongOption (" retention-period" , " Duration for which data in topic is stored (ex. '72h', '1440m')" )
477
+ .Optional ()
478
+ .StoreMappedResult (&RetentionPeriod_, ParseDuration);
440
479
config.Opts ->AddLongOption (" partition-write-speed-kbps" , " Partition write speed in kilobytes per second" )
441
480
.Optional ()
442
481
.StoreResult (&PartitionWriteSpeedKbps_);
@@ -453,6 +492,8 @@ namespace NYdb::NConsoleClient {
453
492
.Optional ()
454
493
.StoreResult (&MaxActivePartitions_);
455
494
AddAutoPartitioning (config, true );
495
+
496
+ config.Opts ->MutuallyExclusive (" retention-period-hours" , " retention-period" );
456
497
}
457
498
458
499
void TCommandTopicAlter::Parse (TConfig& config) {
@@ -501,8 +542,8 @@ namespace NYdb::NConsoleClient {
501
542
settings.SetSupportedCodecs (codecs);
502
543
}
503
544
504
- if (RetentionPeriodHours_ .Defined () && describeResult.GetTopicDescription ().GetRetentionPeriod () != TDuration::Hours (*RetentionPeriodHours_) ) {
505
- settings.SetRetentionPeriod (TDuration::Hours (*RetentionPeriodHours_) );
545
+ if (RetentionPeriod_ .Defined () && describeResult.GetTopicDescription ().GetRetentionPeriod () != RetentionPeriod_ ) {
546
+ settings.SetRetentionPeriod (*RetentionPeriod_ );
506
547
}
507
548
508
549
if (PartitionWriteSpeedKbps_.Defined () && describeResult.GetTopicDescription ().GetPartitionWriteSpeedBytesPerSecond () / 1_KB != *PartitionWriteSpeedKbps_) {
@@ -600,6 +641,9 @@ namespace NYdb::NConsoleClient {
600
641
.Optional ()
601
642
.DefaultValue (false )
602
643
.StoreResult (&IsImportant_);
644
+ config.Opts ->AddLongOption (" availability-period" , " Duration for which uncommited data in topic is retained (ex. '72h', '1440m')" )
645
+ .Optional ()
646
+ .StoreMappedResult (&AvailabilityPeriod_, ParseDuration);
603
647
config.Opts ->SetFreeArgsNum (1 );
604
648
SetFreeArgTitle (0 , " <topic-path>" , " Topic path" );
605
649
AddAllowedCodecs (config, AllowedCodecs);
@@ -630,6 +674,9 @@ namespace NYdb::NConsoleClient {
630
674
consumerSettings.SetSupportedCodecs (codecs);
631
675
}
632
676
consumerSettings.SetImportant (IsImportant_);
677
+ if (AvailabilityPeriod_.Defined ()) {
678
+ consumerSettings.AvailabilityPeriod (*AvailabilityPeriod_);
679
+ }
633
680
634
681
readRuleSettings.AppendAddConsumers (consumerSettings);
635
682
0 commit comments