Skip to content

Commit 0dc827a

Browse files
authored
Add start and end times to Operations API (#5426)
1 parent 432d1a6 commit 0dc827a

File tree

12 files changed

+92
-18
lines changed

12 files changed

+92
-18
lines changed

ydb/core/grpc_services/rpc_export_base.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,13 @@ struct TExportConv {
4545
operation.mutable_issues()->CopyFrom(exprt.GetIssues());
4646
}
4747

48+
if (exprt.HasStartTime()) {
49+
*operation.mutable_start_time() = exprt.GetStartTime();
50+
}
51+
if (exprt.HasEndTime()) {
52+
*operation.mutable_end_time() = exprt.GetEndTime();
53+
}
54+
4855
using namespace Ydb::Export;
4956
switch (exprt.GetSettingsCase()) {
5057
case NKikimrExport::TExport::kExportToYtSettings:

ydb/core/grpc_services/rpc_import_base.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,13 @@ struct TImportConv {
4242
operation.mutable_issues()->CopyFrom(import.GetIssues());
4343
}
4444

45+
if (import.HasStartTime()) {
46+
*operation.mutable_start_time() = import.GetStartTime();
47+
}
48+
if (import.HasEndTime()) {
49+
*operation.mutable_end_time() = import.GetEndTime();
50+
}
51+
4552
using namespace Ydb::Import;
4653
switch (import.GetSettingsCase()) {
4754
case NKikimrImport::TImport::kImportFromS3Settings:

ydb/core/tx/schemeshard/schemeshard_export.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,9 @@ void TSchemeShard::FromXxportInfo(NKikimrExport::TExport& exprt, const TExportIn
8484
exprt.SetId(exportInfo->Id);
8585
exprt.SetStatus(Ydb::StatusIds::SUCCESS);
8686

87-
*exprt.MutableStartTime() = SecondsToProtoTimeStamp(exportInfo->StartTime.Seconds());
87+
if (exportInfo->StartTime != TInstant::Zero()) {
88+
*exprt.MutableStartTime() = SecondsToProtoTimeStamp(exportInfo->StartTime.Seconds());
89+
}
8890
if (exportInfo->EndTime != TInstant::Zero()) {
8991
*exprt.MutableEndTime() = SecondsToProtoTimeStamp(exportInfo->EndTime.Seconds());
9092
}

ydb/core/tx/schemeshard/schemeshard_import.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,9 @@ void TSchemeShard::FromXxportInfo(NKikimrImport::TImport& import, const TImportI
4848
import.SetId(importInfo->Id);
4949
import.SetStatus(Ydb::StatusIds::SUCCESS);
5050

51-
*import.MutableStartTime() = SecondsToProtoTimeStamp(importInfo->StartTime.Seconds());
51+
if (importInfo->StartTime != TInstant::Zero()) {
52+
*import.MutableStartTime() = SecondsToProtoTimeStamp(importInfo->StartTime.Seconds());
53+
}
5254
if (importInfo->EndTime != TInstant::Zero()) {
5355
*import.MutableEndTime() = SecondsToProtoTimeStamp(importInfo->EndTime.Seconds());
5456
}

ydb/core/tx/schemeshard/ut_export/ut_export.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1507,6 +1507,7 @@ partitioning_settings {
15071507
Y_UNIT_TEST(ExportStartTime) {
15081508
TTestBasicRuntime runtime;
15091509
TTestEnv env(runtime);
1510+
runtime.UpdateCurrentTime(TInstant::Now());
15101511
ui64 txId = 100;
15111512

15121513
TestCreateTable(runtime, ++txId, "/MyRoot", R"(
@@ -1544,6 +1545,7 @@ partitioning_settings {
15441545
Y_UNIT_TEST(CompletedExportEndTime) {
15451546
TTestBasicRuntime runtime;
15461547
TTestEnv env(runtime);
1548+
runtime.UpdateCurrentTime(TInstant::Now());
15471549
ui64 txId = 100;
15481550

15491551
TestCreateTable(runtime, ++txId, "/MyRoot", R"(
@@ -1586,6 +1588,7 @@ partitioning_settings {
15861588
Y_UNIT_TEST(CancelledExportEndTime) {
15871589
TTestBasicRuntime runtime;
15881590
TTestEnv env(runtime);
1591+
runtime.UpdateCurrentTime(TInstant::Now());
15891592
ui64 txId = 100;
15901593

15911594
TestCreateTable(runtime, ++txId, "/MyRoot", R"(

ydb/core/tx/schemeshard/ut_restore/ut_restore.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2952,7 +2952,8 @@ Y_UNIT_TEST_SUITE(TImportTests) {
29522952

29532953
Y_UNIT_TEST(ImportStartTime) {
29542954
TTestBasicRuntime runtime;
2955-
TTestEnv env(runtime, TTestEnvOptions());
2955+
TTestEnv env(runtime);
2956+
runtime.UpdateCurrentTime(TInstant::Now());
29562957
ui64 txId = 100;
29572958

29582959
const auto data = GenerateTestData(R"(
@@ -2993,7 +2994,8 @@ Y_UNIT_TEST_SUITE(TImportTests) {
29932994

29942995
Y_UNIT_TEST(CompletedImportEndTime) {
29952996
TTestBasicRuntime runtime;
2996-
TTestEnv env(runtime, TTestEnvOptions());
2997+
TTestEnv env(runtime);
2998+
runtime.UpdateCurrentTime(TInstant::Now());
29972999
ui64 txId = 100;
29983000

29993001
const auto data = GenerateTestData(R"(
@@ -3039,7 +3041,8 @@ Y_UNIT_TEST_SUITE(TImportTests) {
30393041

30403042
Y_UNIT_TEST(CancelledImportEndTime) {
30413043
TTestBasicRuntime runtime;
3042-
TTestEnv env(runtime, TTestEnvOptions());
3044+
TTestEnv env(runtime);
3045+
runtime.UpdateCurrentTime(TInstant::Now());
30433046
ui64 txId = 100;
30443047

30453048
const auto data = GenerateTestData(R"(

ydb/public/api/protos/ydb_operation.proto

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ option cc_enable_arenas = true;
33

44
import "google/protobuf/any.proto";
55
import "google/protobuf/duration.proto";
6+
import "google/protobuf/timestamp.proto";
67

78
import "ydb/public/api/protos/annotations/validation.proto";
89
import "ydb/public/api/protos/ydb_common.proto";
@@ -103,7 +104,7 @@ message Operation {
103104
// not created in the first place, as in SYNC operation mode).
104105
string id = 1;
105106

106-
// true - this operation has beed finished (doesn't matter successful or not),
107+
// true - this operation has been completed (doesn't matter successful or not),
107108
// so Status field has status code, and Result field can contains result data.
108109
// false - this operation still running. You can repeat request using operation Id.
109110
bool ready = 2;
@@ -120,4 +121,10 @@ message Operation {
120121
// For completed operations, it shows the final cost of the operation.
121122
// For operations in progress, it might indicate the current cost of the operation (if supported).
122123
CostInfo cost_info = 7;
124+
125+
// The time at which this operation was started (if supported).
126+
google.protobuf.Timestamp start_time = 8;
127+
128+
// The time at which this operation was completed, doesn't matter successful or not (if supported).
129+
google.protobuf.Timestamp end_time = 9;
123130
}

ydb/public/lib/ydb_cli/common/print_operation.cpp

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,14 @@ namespace {
3636
freeText << " - " << issue << Endl;
3737
}
3838
}
39+
40+
if (operation.StartTime() != TInstant::Zero()) {
41+
freeText << "Start time: " << operation.StartTime().ToStringUpToSeconds() << Endl;
42+
}
43+
44+
if (operation.EndTime() != TInstant::Zero()) {
45+
freeText << "End time: " << operation.EndTime().ToStringUpToSeconds() << Endl;
46+
}
3947

4048
row.FreeText(freeText);
4149
}
@@ -114,6 +122,14 @@ namespace {
114122

115123
freeText << "TypeV3: " << (settings.UseTypeV3_ ? "true" : "false") << Endl;
116124

125+
if (operation.StartTime() != TInstant::Zero()) {
126+
freeText << "Start time: " << operation.StartTime().ToStringUpToSeconds() << Endl;
127+
}
128+
129+
if (operation.EndTime() != TInstant::Zero()) {
130+
freeText << "End time: " << operation.EndTime().ToStringUpToSeconds() << Endl;
131+
}
132+
117133
row.FreeText(freeText);
118134
}
119135

@@ -168,6 +184,14 @@ namespace {
168184
freeText << "Number of retries: " << settings.NumberOfRetries_.GetRef() << Endl;
169185
}
170186

187+
if (operation.StartTime() != TInstant::Zero()) {
188+
freeText << "Start time: " << operation.StartTime().ToStringUpToSeconds() << Endl;
189+
}
190+
191+
if (operation.EndTime() != TInstant::Zero()) {
192+
freeText << "End time: " << operation.EndTime().ToStringUpToSeconds() << Endl;
193+
}
194+
171195
row.FreeText(freeText);
172196
}
173197

ydb/public/sdk/cpp/client/ydb_export/export.cpp

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,6 @@ using namespace Ydb::Export;
2424
/// Common
2525
namespace {
2626

27-
TInstant ProtoTimestampToInstant(const NProtoBuf::Timestamp& timestamp) {
28-
ui64 us = timestamp.seconds() * 1000000;
29-
us += timestamp.nanos() / 1000;
30-
return TInstant::MicroSeconds(us);
31-
}
32-
3327
TVector<TExportItemProgress> ItemsProgressFromProto(const google::protobuf::RepeatedPtrField<ExportItemProgress>& proto) {
3428
TVector<TExportItemProgress> result(Reserve(proto.size()));
3529

ydb/public/sdk/cpp/client/ydb_import/import.cpp

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,6 @@ using namespace Ydb::Import;
1919
/// Common
2020
namespace {
2121

22-
TInstant ProtoTimestampToInstant(const NProtoBuf::Timestamp& timestamp) {
23-
ui64 us = timestamp.seconds() * 1000000;
24-
us += timestamp.nanos() / 1000;
25-
return TInstant::MicroSeconds(us);
26-
}
27-
2822
TVector<TImportItemProgress> ItemsProgressFromProto(const google::protobuf::RepeatedPtrField<Ydb::Import::ImportItemProgress>& proto) {
2923
TVector<TImportItemProgress> result(Reserve(proto.size()));
3024

0 commit comments

Comments
 (0)