Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions ydb/core/grpc_services/rpc_export_base.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,13 @@ struct TExportConv {
operation.mutable_issues()->CopyFrom(exprt.GetIssues());
}

if (exprt.HasStartTime()) {
*operation.mutable_start_time() = exprt.GetStartTime();
}
if (exprt.HasEndTime()) {
*operation.mutable_end_time() = exprt.GetEndTime();
}

using namespace Ydb::Export;
switch (exprt.GetSettingsCase()) {
case NKikimrExport::TExport::kExportToYtSettings:
Expand Down
7 changes: 7 additions & 0 deletions ydb/core/grpc_services/rpc_import_base.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,13 @@ struct TImportConv {
operation.mutable_issues()->CopyFrom(import.GetIssues());
}

if (import.HasStartTime()) {
*operation.mutable_start_time() = import.GetStartTime();
}
if (import.HasEndTime()) {
*operation.mutable_end_time() = import.GetEndTime();
}

using namespace Ydb::Import;
switch (import.GetSettingsCase()) {
case NKikimrImport::TImport::kImportFromS3Settings:
Expand Down
4 changes: 3 additions & 1 deletion ydb/core/tx/schemeshard/schemeshard_export.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,9 @@ void TSchemeShard::FromXxportInfo(NKikimrExport::TExport& exprt, const TExportIn
exprt.SetId(exportInfo->Id);
exprt.SetStatus(Ydb::StatusIds::SUCCESS);

*exprt.MutableStartTime() = SecondsToProtoTimeStamp(exportInfo->StartTime.Seconds());
if (exportInfo->StartTime != TInstant::Zero()) {
*exprt.MutableStartTime() = SecondsToProtoTimeStamp(exportInfo->StartTime.Seconds());
}
if (exportInfo->EndTime != TInstant::Zero()) {
*exprt.MutableEndTime() = SecondsToProtoTimeStamp(exportInfo->EndTime.Seconds());
}
Expand Down
4 changes: 3 additions & 1 deletion ydb/core/tx/schemeshard/schemeshard_import.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,9 @@ void TSchemeShard::FromXxportInfo(NKikimrImport::TImport& import, const TImportI
import.SetId(importInfo->Id);
import.SetStatus(Ydb::StatusIds::SUCCESS);

*import.MutableStartTime() = SecondsToProtoTimeStamp(importInfo->StartTime.Seconds());
if (importInfo->StartTime != TInstant::Zero()) {
*import.MutableStartTime() = SecondsToProtoTimeStamp(importInfo->StartTime.Seconds());
}
if (importInfo->EndTime != TInstant::Zero()) {
*import.MutableEndTime() = SecondsToProtoTimeStamp(importInfo->EndTime.Seconds());
}
Expand Down
3 changes: 3 additions & 0 deletions ydb/core/tx/schemeshard/ut_export/ut_export.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1507,6 +1507,7 @@ partitioning_settings {
Y_UNIT_TEST(ExportStartTime) {
TTestBasicRuntime runtime;
TTestEnv env(runtime);
runtime.UpdateCurrentTime(TInstant::Now());
ui64 txId = 100;

TestCreateTable(runtime, ++txId, "/MyRoot", R"(
Expand Down Expand Up @@ -1544,6 +1545,7 @@ partitioning_settings {
Y_UNIT_TEST(CompletedExportEndTime) {
TTestBasicRuntime runtime;
TTestEnv env(runtime);
runtime.UpdateCurrentTime(TInstant::Now());
ui64 txId = 100;

TestCreateTable(runtime, ++txId, "/MyRoot", R"(
Expand Down Expand Up @@ -1586,6 +1588,7 @@ partitioning_settings {
Y_UNIT_TEST(CancelledExportEndTime) {
TTestBasicRuntime runtime;
TTestEnv env(runtime);
runtime.UpdateCurrentTime(TInstant::Now());
ui64 txId = 100;

TestCreateTable(runtime, ++txId, "/MyRoot", R"(
Expand Down
9 changes: 6 additions & 3 deletions ydb/core/tx/schemeshard/ut_restore/ut_restore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2952,7 +2952,8 @@ Y_UNIT_TEST_SUITE(TImportTests) {

Y_UNIT_TEST(ImportStartTime) {
TTestBasicRuntime runtime;
TTestEnv env(runtime, TTestEnvOptions());
TTestEnv env(runtime);
runtime.UpdateCurrentTime(TInstant::Now());
ui64 txId = 100;

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

Y_UNIT_TEST(CompletedImportEndTime) {
TTestBasicRuntime runtime;
TTestEnv env(runtime, TTestEnvOptions());
TTestEnv env(runtime);
runtime.UpdateCurrentTime(TInstant::Now());
ui64 txId = 100;

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

Y_UNIT_TEST(CancelledImportEndTime) {
TTestBasicRuntime runtime;
TTestEnv env(runtime, TTestEnvOptions());
TTestEnv env(runtime);
runtime.UpdateCurrentTime(TInstant::Now());
ui64 txId = 100;

const auto data = GenerateTestData(R"(
Expand Down
9 changes: 8 additions & 1 deletion ydb/public/api/protos/ydb_operation.proto
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ option cc_enable_arenas = true;

import "google/protobuf/any.proto";
import "google/protobuf/duration.proto";
import "google/protobuf/timestamp.proto";

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

// true - this operation has beed finished (doesn't matter successful or not),
// true - this operation has been completed (doesn't matter successful or not),
// so Status field has status code, and Result field can contains result data.
// false - this operation still running. You can repeat request using operation Id.
bool ready = 2;
Expand All @@ -120,4 +121,10 @@ message Operation {
// For completed operations, it shows the final cost of the operation.
// For operations in progress, it might indicate the current cost of the operation (if supported).
CostInfo cost_info = 7;

// The time at which this operation was started (if supported).
google.protobuf.Timestamp start_time = 8;

// The time at which this operation was completed, doesn't matter successful or not (if supported).
google.protobuf.Timestamp end_time = 9;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Если уж ты выше переименовал в 'completed', почему тогда не complete_time?

Copy link
Member Author

@pixcc pixcc Jun 11, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

end_time как будто сильно более популярнее. Особенно в связке с start_time.

В нашем публичном API для прогресса айтемов экспорта/импорта уже есть ровно такая связка.
https://github.com/ydb-platform/ydb/blob/main/ydb/public/api/protos/ydb_export.proto#L28

}
24 changes: 24 additions & 0 deletions ydb/public/lib/ydb_cli/common/print_operation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,14 @@ namespace {
freeText << " - " << issue << Endl;
}
}

if (operation.StartTime() != TInstant::Zero()) {
freeText << "Start time: " << operation.StartTime().ToStringUpToSeconds() << Endl;
}

if (operation.EndTime() != TInstant::Zero()) {
freeText << "End time: " << operation.EndTime().ToStringUpToSeconds() << Endl;
}

row.FreeText(freeText);
}
Expand Down Expand Up @@ -114,6 +122,14 @@ namespace {

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

if (operation.StartTime() != TInstant::Zero()) {
freeText << "Start time: " << operation.StartTime().ToStringUpToSeconds() << Endl;
}

if (operation.EndTime() != TInstant::Zero()) {
freeText << "End time: " << operation.EndTime().ToStringUpToSeconds() << Endl;
}

row.FreeText(freeText);
}

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

if (operation.StartTime() != TInstant::Zero()) {
freeText << "Start time: " << operation.StartTime().ToStringUpToSeconds() << Endl;
}

if (operation.EndTime() != TInstant::Zero()) {
freeText << "End time: " << operation.EndTime().ToStringUpToSeconds() << Endl;
}

row.FreeText(freeText);
}

Expand Down
6 changes: 0 additions & 6 deletions ydb/public/sdk/cpp/client/ydb_export/export.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,6 @@ using namespace Ydb::Export;
/// Common
namespace {

TInstant ProtoTimestampToInstant(const NProtoBuf::Timestamp& timestamp) {
ui64 us = timestamp.seconds() * 1000000;
us += timestamp.nanos() / 1000;
return TInstant::MicroSeconds(us);
}

TVector<TExportItemProgress> ItemsProgressFromProto(const google::protobuf::RepeatedPtrField<ExportItemProgress>& proto) {
TVector<TExportItemProgress> result(Reserve(proto.size()));

Expand Down
6 changes: 0 additions & 6 deletions ydb/public/sdk/cpp/client/ydb_import/import.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,6 @@ using namespace Ydb::Import;
/// Common
namespace {

TInstant ProtoTimestampToInstant(const NProtoBuf::Timestamp& timestamp) {
ui64 us = timestamp.seconds() * 1000000;
us += timestamp.nanos() / 1000;
return TInstant::MicroSeconds(us);
}

TVector<TImportItemProgress> ItemsProgressFromProto(const google::protobuf::RepeatedPtrField<Ydb::Import::ImportItemProgress>& proto) {
TVector<TImportItemProgress> result(Reserve(proto.size()));

Expand Down
26 changes: 26 additions & 0 deletions ydb/public/sdk/cpp/client/ydb_types/operation/operation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ class TOperation::TImpl {
: Id_(operation.id(), true /* allowEmpty */)
, Status_(std::move(status))
, Ready_(operation.ready())
, StartTime_(ProtoTimestampToInstant(operation.start_time()))
, EndTime_(ProtoTimestampToInstant(operation.end_time()))
, Operation_(std::move(operation))
{
}
Expand All @@ -33,6 +35,14 @@ class TOperation::TImpl {
return Status_;
}

TInstant StartTime() const {
return StartTime_;
}

TInstant EndTime() const {
return EndTime_;
}

const Ydb::Operations::Operation& GetProto() const {
return Operation_;
}
Expand All @@ -41,6 +51,8 @@ class TOperation::TImpl {
const TOperationId Id_;
const TStatus Status_;
const bool Ready_;
const TInstant StartTime_;
const TInstant EndTime_;
const Ydb::Operations::Operation Operation_;
};

Expand All @@ -64,6 +76,14 @@ const TStatus& TOperation::Status() const {
return Impl_->Status();
}

TInstant TOperation::StartTime() const {
return Impl_->StartTime();
}

TInstant TOperation::EndTime() const {
return Impl_->EndTime();
}

TString TOperation::ToString() const {
TString result;
TStringOutput out(result);
Expand All @@ -88,4 +108,10 @@ const Ydb::Operations::Operation& TOperation::GetProto() const {
return Impl_->GetProto();
}

TInstant ProtoTimestampToInstant(const NProtoBuf::Timestamp& timestamp) {
ui64 us = timestamp.seconds() * 1000000;
us += timestamp.nanos() / 1000;
return TInstant::MicroSeconds(us);
}

} // namespace NYdb
5 changes: 5 additions & 0 deletions ydb/public/sdk/cpp/client/ydb_types/operation/operation.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include <library/cpp/threading/future/future.h>

#include <google/protobuf/stubs/status.h>
#include <google/protobuf/timestamp.pb.h>
#include <google/protobuf/util/json_util.h>

namespace Ydb {
Expand All @@ -31,6 +32,8 @@ class TOperation {
const TOperationId& Id() const;
bool Ready() const;
const TStatus& Status() const;
TInstant StartTime() const;
TInstant EndTime() const;

TString ToString() const;
TString ToJsonString() const;
Expand All @@ -46,4 +49,6 @@ class TOperation {

using TAsyncOperation = NThreading::TFuture<TOperation>;

TInstant ProtoTimestampToInstant(const NProtoBuf::Timestamp& timestamp);

} // namespace NYdb