Skip to content

Commit b8d1b19

Browse files
committed
Added not existing validations for alter/drop object
1 parent 8f1e398 commit b8d1b19

File tree

3 files changed

+78
-11
lines changed

3 files changed

+78
-11
lines changed

ydb/core/kqp/ut/scheme/kqp_scheme_ut.cpp

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7021,6 +7021,27 @@ Y_UNIT_TEST_SUITE(KqpScheme) {
70217021
}
70227022
}
70237023

7024+
Y_UNIT_TEST(AlterNonExistingResourcePoolClassifier) {
7025+
NKikimrConfig::TAppConfig config;
7026+
config.MutableFeatureFlags()->SetEnableResourcePools(true);
7027+
7028+
TKikimrRunner kikimr(NKqp::TKikimrSettings()
7029+
.SetAppConfig(config)
7030+
.SetEnableResourcePools(true));
7031+
7032+
auto db = kikimr.GetTableClient();
7033+
auto session = db.CreateSession().GetValueSync().GetSession();
7034+
7035+
auto query = R"(
7036+
ALTER RESOURCE POOL CLASSIFIER MyResourcePoolClassifier
7037+
SET (MEMBERNAME = "test@user", RANK = 100),
7038+
RESET (RESOURCE_POOL);
7039+
)";
7040+
auto result = session.ExecuteSchemeQuery(query).GetValueSync();
7041+
UNIT_ASSERT_VALUES_EQUAL_C(result.GetStatus(), EStatus::GENERIC_ERROR, result.GetIssues().ToString());
7042+
UNIT_ASSERT_STRING_CONTAINS(result.GetIssues().ToString(), "object with specified key not found");
7043+
}
7044+
70247045
Y_UNIT_TEST(DropResourcePoolClassifier) {
70257046
NKikimrConfig::TAppConfig config;
70267047
config.MutableFeatureFlags()->SetEnableResourcePools(true);
@@ -7049,6 +7070,23 @@ Y_UNIT_TEST_SUITE(KqpScheme) {
70497070
UNIT_ASSERT_VALUES_EQUAL(FetchResourcePoolClassifiers(kikimr), "{\"resource_pool_classifiers\":[]}");
70507071
}
70517072
}
7073+
7074+
Y_UNIT_TEST(DropNonExistingResourcePoolClassifier) {
7075+
NKikimrConfig::TAppConfig config;
7076+
config.MutableFeatureFlags()->SetEnableResourcePools(true);
7077+
7078+
TKikimrRunner kikimr(NKqp::TKikimrSettings()
7079+
.SetAppConfig(config)
7080+
.SetEnableResourcePools(true));
7081+
7082+
auto db = kikimr.GetTableClient();
7083+
auto session = db.CreateSession().GetValueSync().GetSession();
7084+
7085+
auto query = "DROP RESOURCE POOL CLASSIFIER MyResourcePoolClassifier;";
7086+
auto result = session.ExecuteSchemeQuery(query).GetValueSync();
7087+
UNIT_ASSERT_VALUES_EQUAL_C(result.GetStatus(), EStatus::GENERIC_ERROR, result.GetIssues().ToString());
7088+
UNIT_ASSERT_STRING_CONTAINS(result.GetIssues().ToString(), "object with specified key not found");
7089+
}
70527090
}
70537091

70547092
Y_UNIT_TEST_SUITE(KqpOlapScheme) {

ydb/services/metadata/manager/alter.h

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,23 @@ class TDeleteObjectActor: public TModificationActor<TObject> {
108108
return true;
109109
}
110110

111-
virtual bool PrepareRestoredObjects(std::vector<TObject>& /*objects*/) const override {
111+
virtual bool PrepareRestoredObjects(std::vector<TObject>& objects) const override {
112+
if (TBase::NewObjectsAllowed) {
113+
return true;
114+
}
115+
for (auto&& p : TBase::Patches) {
116+
bool found = false;
117+
for (auto&& i : objects) {
118+
if (i.SerializeToRecord().CompareColumns(p, Manager->GetSchema().GetPKColumnIds())) {
119+
found = true;
120+
break;
121+
}
122+
}
123+
if (!found) {
124+
TBase::ExternalController->OnAlteringProblem("object with specified key not found");
125+
return false;
126+
}
127+
}
112128
return true;
113129
}
114130

@@ -158,7 +174,7 @@ class TUpdateObjectCommand: public IObjectModificationCommand {
158174
protected:
159175
virtual void DoExecute() const override {
160176
typename IObjectOperationsManager<TObject>::TPtr manager = TBase::GetOperationsManagerFor<TObject>();
161-
TActivationContext::AsActorContext().Register(new TUpdateObjectActor<TObject>(GetRecords(), GetController(), manager, GetContext()));
177+
TActivationContext::AsActorContext().Register(new TUpdateObjectActor<TObject>(GetRecords(), GetController(), manager, GetContext(), false));
162178
}
163179
public:
164180
using TBase::TBase;
@@ -172,7 +188,7 @@ class TDeleteObjectCommand: public IObjectModificationCommand {
172188
protected:
173189
virtual void DoExecute() const override {
174190
typename IObjectOperationsManager<TObject>::TPtr manager = TBase::GetOperationsManagerFor<TObject>();
175-
TActivationContext::AsActorContext().Register(new TDeleteObjectActor<TObject>(GetRecords(), GetController(), manager, GetContext()));
191+
TActivationContext::AsActorContext().Register(new TDeleteObjectActor<TObject>(GetRecords(), GetController(), manager, GetContext(), MissingOk));
176192
}
177193
public:
178194
TDeleteObjectCommand(const NInternal::TTableRecord& record,

ydb/services/metadata/manager/alter_impl.h

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ class TModificationActorImpl: public NActors::TActorBootstrapped<TModificationAc
5959
std::vector<NInternal::TTableRecord> Patches;
6060
NInternal::TTableRecords RestoreObjectIds;
6161
const NACLib::TUserToken UserToken = NACLib::TSystemUsers::Metadata();
62+
const bool NewObjectsAllowed;
6263
virtual bool PrepareRestoredObjects(std::vector<TObject>& objects) const = 0;
6364
virtual bool ProcessPreparedObjects(NInternal::TTableRecords&& records) const = 0;
6465
virtual void InitState() = 0;
@@ -67,39 +68,47 @@ class TModificationActorImpl: public NActors::TActorBootstrapped<TModificationAc
6768
TModificationActorImpl(NInternal::TTableRecord&& patch,
6869
IAlterController::TPtr controller,
6970
const typename IObjectOperationsManager<TObject>::TPtr& manager,
70-
const IOperationsManager::TInternalModificationContext& context)
71+
const IOperationsManager::TInternalModificationContext& context,
72+
bool newObjectsAllowed = true)
7173
: ExternalController(controller)
7274
, Manager(manager)
73-
, Context(context) {
75+
, Context(context)
76+
, NewObjectsAllowed(newObjectsAllowed) {
7477
Patches.emplace_back(std::move(patch));
7578
}
7679

7780
TModificationActorImpl(const NInternal::TTableRecord& patch, IAlterController::TPtr controller,
7881
const typename IObjectOperationsManager<TObject>::TPtr& manager,
79-
const IOperationsManager::TInternalModificationContext& context)
82+
const IOperationsManager::TInternalModificationContext& context,
83+
bool newObjectsAllowed = true)
8084
: ExternalController(controller)
8185
, Manager(manager)
82-
, Context(context) {
86+
, Context(context)
87+
, NewObjectsAllowed(newObjectsAllowed) {
8388
Patches.emplace_back(patch);
8489
}
8590

8691
TModificationActorImpl(std::vector<NInternal::TTableRecord>&& patches, IAlterController::TPtr controller,
8792
const typename IObjectOperationsManager<TObject>::TPtr& manager,
88-
const IOperationsManager::TInternalModificationContext& context)
93+
const IOperationsManager::TInternalModificationContext& context,
94+
bool newObjectsAllowed = true)
8995
: ExternalController(controller)
9096
, Manager(manager)
9197
, Context(context)
92-
, Patches(std::move(patches)) {
98+
, Patches(std::move(patches))
99+
, NewObjectsAllowed(newObjectsAllowed) {
93100

94101
}
95102

96103
TModificationActorImpl(const std::vector<NInternal::TTableRecord>& patches, IAlterController::TPtr controller,
97104
const typename IObjectOperationsManager<TObject>::TPtr& manager,
98-
const IOperationsManager::TInternalModificationContext& context)
105+
const IOperationsManager::TInternalModificationContext& context,
106+
bool newObjectsAllowed = true)
99107
: ExternalController(controller)
100108
, Manager(manager)
101109
, Context(context)
102-
, Patches(patches) {
110+
, Patches(patches)
111+
, NewObjectsAllowed(newObjectsAllowed) {
103112

104113
}
105114

@@ -255,6 +264,10 @@ class TModificationActor: public TModificationActorImpl<TObject> {
255264
}
256265
}
257266
if (!found) {
267+
if (!TBase::NewObjectsAllowed) {
268+
TBase::ExternalController->OnAlteringProblem("object with specified key not found");
269+
return false;
270+
}
258271
TObject object;
259272
if (!TObject::TDecoder::DeserializeFromRecord(object, p)) {
260273
TBase::ExternalController->OnAlteringProblem("cannot parse new object");

0 commit comments

Comments
 (0)