aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorivanmorozov <ivanmorozov@yandex-team.com>2022-12-15 19:20:13 +0300
committerivanmorozov <ivanmorozov@yandex-team.com>2022-12-15 19:20:13 +0300
commitd1d5f5e00df0dd6efc00880dd8283477fc643aaf (patch)
treef6184e34b49e0f60b4606ce96199e9278fcf8cb1
parent6b780718b1af069992f4f7311c1cb753c8a68d05 (diff)
downloadydb-d1d5f5e00df0dd6efc00880dd8283477fc643aaf.tar.gz
use cache for table structure receiving
-rw-r--r--ydb/core/protos/services.proto1
-rw-r--r--ydb/services/metadata/ds_table/scheme_describe.cpp65
-rw-r--r--ydb/services/metadata/ds_table/scheme_describe.h30
-rw-r--r--ydb/services/metadata/ds_table/service.cpp4
-rw-r--r--ydb/services/metadata/ds_table/service.h7
-rw-r--r--ydb/services/metadata/initializer/ut/ut_init.cpp9
-rw-r--r--ydb/services/metadata/manager/abstract.cpp22
-rw-r--r--ydb/services/metadata/manager/abstract.h3
-rw-r--r--ydb/services/metadata/secret/access.cpp3
-rw-r--r--ydb/services/metadata/secret/access_behaviour.cpp5
-rw-r--r--ydb/services/metadata/secret/access_behaviour.h2
-rw-r--r--ydb/services/metadata/secret/secret.cpp3
-rw-r--r--ydb/services/metadata/secret/secret_behaviour.cpp5
-rw-r--r--ydb/services/metadata/secret/secret_behaviour.h3
14 files changed, 79 insertions, 83 deletions
diff --git a/ydb/core/protos/services.proto b/ydb/core/protos/services.proto
index 0810f2f59c..f35726ad93 100644
--- a/ydb/core/protos/services.proto
+++ b/ydb/core/protos/services.proto
@@ -957,5 +957,6 @@ message TActivity {
AUDIT_WRITER_ACTOR = 596;
SCHEMESHARD_SVP_MIGRATOR = 597;
SS_FETCHING_ACTOR = 598;
+ METADATA_SCHEME_DESCRIPTION_ACTOR = 599;
};
};
diff --git a/ydb/services/metadata/ds_table/scheme_describe.cpp b/ydb/services/metadata/ds_table/scheme_describe.cpp
index baed2ec3e7..30ed84e1ec 100644
--- a/ydb/services/metadata/ds_table/scheme_describe.cpp
+++ b/ydb/services/metadata/ds_table/scheme_describe.cpp
@@ -8,55 +8,38 @@
namespace NKikimr::NMetadata::NProvider {
-void TSchemeDescriptionActor::Handle(NSchemeShard::TEvSchemeShard::TEvDescribeSchemeResult::TPtr& ev) {
- auto g = PassAwayGuard();
- const auto& record = ev->Get()->GetRecord();
- const auto status = record.GetStatus();
- if (record.HasReason()) {
- auto issue = NYql::TIssue(record.GetReason());
- Controller->OnDescriptionFailed(issue.ToString(), RequestId);
+void TSchemeDescriptionActor::Handle(TEvTxProxySchemeCache::TEvNavigateKeySetResult::TPtr& ev) {
+ auto* info = ev->Get();
+ const auto& request = info->Request;
+
+ if (request->ResultSet.empty()) {
+ Controller->OnDescriptionFailed("navigation problems for path " + Path, RequestId);
+ PassAway();
return;
}
- Ydb::Table::DescribeTableResult describeTableResult;
- if (status != NKikimrScheme::StatusSuccess) {
- Controller->OnDescriptionFailed(::ToString(status), RequestId);
+ if (request->ResultSet.size() != 1) {
+ Controller->OnDescriptionFailed("cannot resolve database path " + Path, RequestId);
+ PassAway();
return;
}
- const auto& pathDescription = record.GetPathDescription();
- Ydb::Scheme::Entry* selfEntry = describeTableResult.mutable_self();
- selfEntry->set_name(pathDescription.GetSelf().GetName());
- selfEntry->set_type(static_cast<Ydb::Scheme::Entry::Type>(pathDescription.GetSelf().GetPathType()));
- ConvertDirectoryEntry(pathDescription.GetSelf(), selfEntry, true);
-
- if (pathDescription.HasColumnTableDescription()) {
- const auto& tableDescription = pathDescription.GetColumnTableDescription();
- FillColumnDescription(describeTableResult, tableDescription);
- } else {
- const auto& tableDescription = pathDescription.GetTable();
- NKikimrMiniKQL::TType splitKeyType;
-
- try {
- FillColumnDescription(describeTableResult, splitKeyType, tableDescription);
- } catch (const std::exception& ex) {
- Controller->OnDescriptionFailed("Unable to fill column description: " + CurrentExceptionMessage(), RequestId);
- return;
- }
-
- describeTableResult.mutable_primary_key()->CopyFrom(tableDescription.GetKeyColumnNames());
- }
- Controller->OnDescriptionSuccess(std::move(describeTableResult), RequestId);
+ auto& entity = request->ResultSet.front();
+ auto g = PassAwayGuard();
+ Controller->OnDescriptionSuccess(std::move(entity.Columns), RequestId);
}
-void TSchemeDescriptionActor::Execute() {
- auto event = std::make_unique<NSchemeShard::TEvSchemeShard::TEvDescribeScheme>(Path);
- event->Record.MutableOptions()->SetReturnPartitioningInfo(false);
- event->Record.MutableOptions()->SetReturnPartitionConfig(false);
- event->Record.MutableOptions()->SetReturnChildren(false);
- Send(SchemeShardPipe, new TEvPipeCache::TEvForward(event.release(), SchemeShardId, false));
+void TSchemeDescriptionActor::Bootstrap() {
+ Become(&TSchemeDescriptionActor::StateMain);
+
+ auto request = MakeHolder<NSchemeCache::TSchemeCacheNavigate>();
+ request->DatabaseName = NKikimr::CanonizePath(AppData()->TenantName);
+ auto& entry = request->ResultSet.emplace_back();
+ entry.Operation = NSchemeCache::TSchemeCacheNavigate::OpTable;
+ entry.Path = NKikimr::SplitPath(Path);
+ Send(MakeSchemeCacheID(), new TEvTxProxySchemeCache::TEvNavigateKeySet(request.Release()));
}
-void TSchemeDescriptionActor::OnFail(const TString& errorMessage) {
- Controller->OnDescriptionFailed(errorMessage, RequestId);
+NKikimrServices::TActivity::EType TSchemeDescriptionActor::ActorActivityType() {
+ return NKikimrServices::TActivity::METADATA_SCHEME_DESCRIPTION_ACTOR;
}
}
diff --git a/ydb/services/metadata/ds_table/scheme_describe.h b/ydb/services/metadata/ds_table/scheme_describe.h
index 41f0b76cff..d8c8a87ef7 100644
--- a/ydb/services/metadata/ds_table/scheme_describe.h
+++ b/ydb/services/metadata/ds_table/scheme_describe.h
@@ -10,35 +10,29 @@ public:
using TPtr = std::shared_ptr<ISchemeDescribeController>;
virtual ~ISchemeDescribeController() = default;
virtual void OnDescriptionFailed(const TString& errorMessage, const TString& requestId) const = 0;
- virtual void OnDescriptionSuccess(Ydb::Table::DescribeTableResult&& result, const TString& requestId) const = 0;
+ virtual void OnDescriptionSuccess(THashMap<ui32, TSysTables::TTableColumnInfo>&& result, const TString& requestId) const = 0;
};
-class TSchemeDescriptionActor: public NInternal::TSSDialogActor {
+class TSchemeDescriptionActor: public NActors::TActorBootstrapped<TSchemeDescriptionActor> {
private:
- using TBase = NInternal::TSSDialogActor;
+ using TBase = NActors::TActorBootstrapped<TSchemeDescriptionActor>;
ISchemeDescribeController::TPtr Controller;
TString Path;
TString RequestId;
- void Handle(NSchemeShard::TEvSchemeShard::TEvDescribeSchemeResult::TPtr& ev);
-protected:
- virtual void OnBootstrap() override {
- Become(&TSchemeDescriptionActor::StateMain);
- TBase::OnBootstrap();
- }
- virtual void OnFail(const TString& errorMessage) override;
- virtual void Execute() override;
+ void Handle(TEvTxProxySchemeCache::TEvNavigateKeySetResult::TPtr& ev);
public:
- static constexpr NKikimrServices::TActivity::EType ActorActivityType();
- STFUNC(StateMain) {
+ static NKikimrServices::TActivity::EType ActorActivityType();
+ void Bootstrap();
+
+ STATEFN(StateMain) {
switch (ev->GetTypeRewrite()) {
- hFunc(NSchemeShard::TEvSchemeShard::TEvDescribeSchemeResult, Handle);
+ hFunc(TEvTxProxySchemeCache::TEvNavigateKeySetResult, Handle);
default:
- TBase::StateMain(ev, ctx);
+ return;
}
}
- TSchemeDescriptionActor(ISchemeDescribeController::TPtr controller, const TString& reqId, const TString& path, const TDuration livetime)
- : TBase(livetime)
- , Controller(controller)
+ TSchemeDescriptionActor(ISchemeDescribeController::TPtr controller, const TString& reqId, const TString& path)
+ : Controller(controller)
, Path(path)
, RequestId(reqId)
{
diff --git a/ydb/services/metadata/ds_table/service.cpp b/ydb/services/metadata/ds_table/service.cpp
index b4d863e854..13ee11730a 100644
--- a/ydb/services/metadata/ds_table/service.cpp
+++ b/ydb/services/metadata/ds_table/service.cpp
@@ -99,7 +99,7 @@ void TService::Handle(NInitializer::TEvInitializationFinished::TPtr& ev) {
auto it = ManagersInRegistration.find(initId);
Y_VERIFY(it != ManagersInRegistration.end());
if (it->second->GetOperationsManager()) {
- Register(new TSchemeDescriptionActor(InternalController, initId, it->second->GetStorageTablePath(), TDuration::Seconds(5)));
+ Register(new TSchemeDescriptionActor(InternalController, initId, it->second->GetStorageTablePath()));
} else {
InitializationFinished(initId);
}
@@ -164,7 +164,7 @@ void TServiceInternalController::OnDescriptionFailed(const TString& errorMessage
ActorId.Send(ActorId, new TEvTableDescriptionFailed(errorMessage, requestId));
}
-void TServiceInternalController::OnDescriptionSuccess(Ydb::Table::DescribeTableResult&& result, const TString& requestId) const {
+void TServiceInternalController::OnDescriptionSuccess(THashMap<ui32, TSysTables::TTableColumnInfo>&& result, const TString& requestId) const {
ActorId.Send(ActorId, new TEvTableDescriptionSuccess(std::move(result), requestId));
}
diff --git a/ydb/services/metadata/ds_table/service.h b/ydb/services/metadata/ds_table/service.h
index 4552173cec..35dd823e76 100644
--- a/ydb/services/metadata/ds_table/service.h
+++ b/ydb/services/metadata/ds_table/service.h
@@ -29,10 +29,11 @@ public:
class TEvTableDescriptionSuccess: public TEventLocal<TEvTableDescriptionSuccess, EEvents::EvTableDescriptionSuccess> {
private:
+ using TDescription = THashMap<ui32, TSysTables::TTableColumnInfo>;
YDB_READONLY_DEF(TString, RequestId);
- YDB_READONLY_DEF(Ydb::Table::DescribeTableResult, Description);
+ YDB_READONLY_DEF(TDescription, Description);
public:
- TEvTableDescriptionSuccess(Ydb::Table::DescribeTableResult&& description, const TString& reqId)
+ TEvTableDescriptionSuccess(TDescription&& description, const TString& reqId)
: RequestId(reqId)
, Description(std::move(description))
{
@@ -56,7 +57,7 @@ public:
virtual void InitializationFinished(const TString& id) const override;
virtual void OnDescriptionFailed(const TString& errorMessage, const TString& requestId) const override;
- virtual void OnDescriptionSuccess(Ydb::Table::DescribeTableResult&& result, const TString& requestId) const override;
+ virtual void OnDescriptionSuccess(THashMap<ui32, TSysTables::TTableColumnInfo>&& result, const TString& requestId) const override;
};
class TManagersId {
diff --git a/ydb/services/metadata/initializer/ut/ut_init.cpp b/ydb/services/metadata/initializer/ut/ut_init.cpp
index 2ba224b2c3..5f0a9cdb65 100644
--- a/ydb/services/metadata/initializer/ut/ut_init.cpp
+++ b/ydb/services/metadata/initializer/ut/ut_init.cpp
@@ -70,12 +70,16 @@ Y_UNIT_TEST_SUITE(Initializer) {
virtual TString GetTypeId() const override {
return TypeName<TInitBehaviourTest>();
}
+
+ static IClassBehaviour::TPtr GetInstant() {
+ static std::shared_ptr<TInitBehaviourTest> result = std::make_shared<TInitBehaviourTest>();
+ return result;
+ }
};
class TInitUserEmulator: public NActors::TActorBootstrapped<TInitUserEmulator> {
private:
using TBase = NActors::TActorBootstrapped<TInitUserEmulator>;
- std::shared_ptr<TInitBehaviourTest> Manager = std::make_shared<TInitBehaviourTest>();
YDB_READONLY_FLAG(Initialized, false);
public:
@@ -93,7 +97,8 @@ Y_UNIT_TEST_SUITE(Initializer) {
void Bootstrap() {
Become(&TThis::StateWork);
- Sender<NMetadata::NProvider::TEvPrepareManager>(Manager).SendTo(NMetadata::NProvider::MakeServiceId(SelfId().NodeId()));
+ Sender<NMetadata::NProvider::TEvPrepareManager>(TInitBehaviourTest::GetInstant()).
+ SendTo(NMetadata::NProvider::MakeServiceId(SelfId().NodeId()));
}
};
diff --git a/ydb/services/metadata/manager/abstract.cpp b/ydb/services/metadata/manager/abstract.cpp
index 021fe5dc14..c2faf50d6c 100644
--- a/ydb/services/metadata/manager/abstract.cpp
+++ b/ydb/services/metadata/manager/abstract.cpp
@@ -2,23 +2,21 @@
namespace NKikimr::NMetadata::NModifications {
-TTableSchema::TTableSchema(const Ydb::Table::DescribeTableResult& description) {
+TTableSchema::TTableSchema(const THashMap<ui32, TSysTables::TTableColumnInfo>& description) {
std::map<TString, Ydb::Column> columns;
- for (auto&& i : description.columns()) {
+ std::map<ui32, Ydb::Column> pkColumns;
+ for (auto&& [_, i] : description) {
Ydb::Column column;
- column.set_name(i.name());
- if (i.type().has_optional_type()) {
- *column.mutable_type() = i.type().optional_type().item();
+ column.set_name(i.Name);
+ column.mutable_type()->set_type_id(::Ydb::Type::PrimitiveTypeId(i.PType.GetTypeId()));
+ if (i.KeyOrder >= 0) {
+ Y_VERIFY(pkColumns.emplace(i.KeyOrder, std::move(column)).second);
} else {
- *column.mutable_type() = i.type();
+ Y_VERIFY(columns.emplace(i.Name, std::move(column)).second);
}
- columns.emplace(i.name(), std::move(column));
}
- for (auto&& i : description.primary_key()) {
- auto it = columns.find(i);
- Y_VERIFY(it != columns.end());
- AddColumn(true, it->second);
- columns.erase(it);
+ for (auto&& i : pkColumns) {
+ AddColumn(true, i.second);
}
for (auto&& i : columns) {
AddColumn(false, i.second);
diff --git a/ydb/services/metadata/manager/abstract.h b/ydb/services/metadata/manager/abstract.h
index 38a66b39f6..5f2c156d23 100644
--- a/ydb/services/metadata/manager/abstract.h
+++ b/ydb/services/metadata/manager/abstract.h
@@ -2,6 +2,7 @@
#include "common.h"
#include "table_record.h"
+#include <ydb/core/tx/datashard/sys_tables.h>
#include <ydb/library/accessor/accessor.h>
#include <ydb/library/aclib/aclib.h>
#include <ydb/library/yql/ast/yql_expr_builder.h>
@@ -117,7 +118,7 @@ private:
TTableSchema& AddColumn(const bool primary, const Ydb::Column& info) noexcept;
public:
- TTableSchema(const Ydb::Table::DescribeTableResult& description);
+ TTableSchema(const THashMap<ui32, TSysTables::TTableColumnInfo>& description);
};
class IOperationsManager {
diff --git a/ydb/services/metadata/secret/access.cpp b/ydb/services/metadata/secret/access.cpp
index d51e453345..aae13342d0 100644
--- a/ydb/services/metadata/secret/access.cpp
+++ b/ydb/services/metadata/secret/access.cpp
@@ -7,8 +7,7 @@
namespace NKikimr::NMetadata::NSecret {
IClassBehaviour::TPtr TAccess::GetBehaviour() {
- static std::shared_ptr<NSecret::TAccessBehaviour> result = std::make_shared<NSecret::TAccessBehaviour>();
- return result;
+ return TAccessBehaviour::GetInstance();
}
bool TAccess::DeserializeFromRecord(const TDecoder& decoder, const Ydb::Value& rawValue) {
diff --git a/ydb/services/metadata/secret/access_behaviour.cpp b/ydb/services/metadata/secret/access_behaviour.cpp
index b7a14c28c5..9d9428817d 100644
--- a/ydb/services/metadata/secret/access_behaviour.cpp
+++ b/ydb/services/metadata/secret/access_behaviour.cpp
@@ -23,4 +23,9 @@ TString TAccessBehaviour::GetTypeId() const {
return TAccess::GetTypeId();
}
+IClassBehaviour::TPtr TAccessBehaviour::GetInstance() {
+ static std::shared_ptr<TAccessBehaviour> result = std::make_shared<TAccessBehaviour>();
+ return result;
+}
+
}
diff --git a/ydb/services/metadata/secret/access_behaviour.h b/ydb/services/metadata/secret/access_behaviour.h
index 58649723e3..2d84cc462e 100644
--- a/ydb/services/metadata/secret/access_behaviour.h
+++ b/ydb/services/metadata/secret/access_behaviour.h
@@ -17,7 +17,9 @@ protected:
virtual TString GetInternalStorageTablePath() const override;
public:
+ TAccessBehaviour() = default;
virtual TString GetTypeId() const override;
+ static IClassBehaviour::TPtr GetInstance();
};
}
diff --git a/ydb/services/metadata/secret/secret.cpp b/ydb/services/metadata/secret/secret.cpp
index d822763cab..4b12175f96 100644
--- a/ydb/services/metadata/secret/secret.cpp
+++ b/ydb/services/metadata/secret/secret.cpp
@@ -28,8 +28,7 @@ NInternal::TTableRecord TSecret::SerializeToRecord() const {
}
IClassBehaviour::TPtr TSecret::GetBehaviour() {
- static std::shared_ptr<NSecret::TSecretBehaviour> result = std::make_shared<NSecret::TSecretBehaviour>();
- return result;
+ return TSecretBehaviour::GetInstance();
}
TString TSecretId::SerializeToString() const {
diff --git a/ydb/services/metadata/secret/secret_behaviour.cpp b/ydb/services/metadata/secret/secret_behaviour.cpp
index 06ea9f8177..ee49fd397b 100644
--- a/ydb/services/metadata/secret/secret_behaviour.cpp
+++ b/ydb/services/metadata/secret/secret_behaviour.cpp
@@ -22,4 +22,9 @@ TString TSecretBehaviour::GetTypeId() const {
return TSecret::GetTypeId();
}
+IClassBehaviour::TPtr TSecretBehaviour::GetInstance() {
+ static std::shared_ptr<TSecretBehaviour> result = std::make_shared<TSecretBehaviour>();
+ return result;
+}
+
}
diff --git a/ydb/services/metadata/secret/secret_behaviour.h b/ydb/services/metadata/secret/secret_behaviour.h
index 1cb0331c1c..ad2fcc739a 100644
--- a/ydb/services/metadata/secret/secret_behaviour.h
+++ b/ydb/services/metadata/secret/secret_behaviour.h
@@ -14,6 +14,9 @@ protected:
virtual TString GetInternalStorageTablePath() const override;
public:
+ TSecretBehaviour() = default;
+ static IClassBehaviour::TPtr GetInstance();
+
virtual TString GetTypeId() const override;
};