Skip to content

Commit 6182d7e

Browse files
authored
Add block for V1 API when V2 is enabled (#30863)
1 parent 5835f07 commit 6182d7e

File tree

4 files changed

+122
-1
lines changed

4 files changed

+122
-1
lines changed

ydb/core/grpc_services/rpc_dynamic_config.cpp

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
#include "service_dynamic_config.h"
22
#include "rpc_deferrable.h"
33

4+
#include <type_traits>
5+
46
#include <ydb/core/grpc_services/base/base.h>
57
#include <ydb/core/base/appdata.h>
68
#include <ydb/core/base/tablet_pipe.h>
79
#include <ydb/core/cms/console/console.h>
10+
#include <ydb/core/blobstorage/base/blobstorage_events.h>
811
#include <ydb/public/api/protos/draft/ydb_dynamic_config.pb.h>
912

1013
namespace NKikimr::NGRpcService {
@@ -66,6 +69,32 @@ class TDynamicConfigRPC : public TRpcOperationRequestActor<TDynamicConfigRPC<TRe
6669
{
6770
TBase::Bootstrap(TActivationContext::AsActorContext());
6871

72+
if constexpr (std::is_same_v<TRequest, TEvSetConfigRequest> || std::is_same_v<TRequest, TEvReplaceConfigRequest>) {
73+
if (AppData()->FeatureFlags.GetSwitchToConfigV2()) {
74+
NYql::TIssues issues;
75+
issues.AddIssue("Dynamic Config V1 is disabled. Use V2 API.");
76+
TBase::Reply(Ydb::StatusIds::BAD_REQUEST, issues, TActivationContext::AsActorContext());
77+
return;
78+
}
79+
80+
this->Send(MakeBlobStorageNodeWardenID(IActor::SelfId().NodeId()), new TEvNodeWardenQueryStorageConfig(false));
81+
this->Become(&TThis::StateWaitNodeWarden);
82+
} else {
83+
StartConsolePipe();
84+
}
85+
}
86+
87+
void Handle(TEvNodeWardenStorageConfig::TPtr& ev) {
88+
if (ev->Get()->SelfManagementEnabled) {
89+
NYql::TIssues issues;
90+
issues.AddIssue("Dynamic Config V1 is disabled. Use V2 API.");
91+
TBase::Reply(Ydb::StatusIds::BAD_REQUEST, issues, TActivationContext::AsActorContext());
92+
} else {
93+
StartConsolePipe();
94+
}
95+
}
96+
97+
void StartConsolePipe() {
6998
NTabletPipe::TClientConfig pipeConfig;
7099
pipeConfig.RetryPolicy = {
71100
.RetryLimitCount = 10,
@@ -78,6 +107,13 @@ class TDynamicConfigRPC : public TRpcOperationRequestActor<TDynamicConfigRPC<TRe
78107
this->Become(&TThis::StateWork);
79108
}
80109

110+
STFUNC(StateWaitNodeWarden) {
111+
switch (ev->GetTypeRewrite()) {
112+
hFunc(TEvNodeWardenStorageConfig, Handle);
113+
default: TBase::StateFuncBase(ev);
114+
}
115+
}
116+
81117
private:
82118
void PassAway()
83119
{

ydb/services/config/bsconfig_ut.cpp

Lines changed: 71 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
#include <ydb/core/tx/scheme_cache/scheme_cache.h>
99

1010
#include <ydb/public/api/grpc/ydb_scheme_v1.grpc.pb.h>
11+
#include <ydb/public/api/grpc/draft/ydb_dynamic_config_v1.grpc.pb.h>
12+
#include <ydb/services/dynamic_config/grpc_service.h>
1113

1214
#include <ydb/public/sdk/cpp/include/ydb-cpp-sdk/client/resources/ydb_resources.h>
1315

@@ -20,6 +22,7 @@
2022
#include <grpcpp/create_channel.h>
2123

2224
#include <util/string/builder.h>
25+
#include <util/system/thread.h>
2326

2427
#include <functional>
2528

@@ -70,7 +73,9 @@ class TBasicKikimrWithGrpcAndRootSchema {
7073
}
7174
ServerSettings->Formats = new NKikimr::TFormatFactory;
7275
ServerSettings->FeatureFlags = appConfig.GetFeatureFlags();
76+
ServerSettings->SetEnableFeatureFlagsConfigurator(true);
7377
ServerSettings->RegisterGrpcService<NKikimr::NGRpcService::TConfigGRpcService>("bsconfig");
78+
ServerSettings->RegisterGrpcService<NKikimr::NGRpcService::TGRpcDynamicConfigService>("dynconfig", std::nullopt, true);
7479
7580
Server_.Reset(new NKikimr::Tests::TServer(*ServerSettings));
7681
Tenants_.Reset(new NKikimr::Tests::TTenants(Server_));
@@ -83,7 +88,7 @@ class TBasicKikimrWithGrpcAndRootSchema {
8388
//Server_->GetRuntime()->SetLogPriority(NKikimrServices::TX_PROXY, NActors::NLog::PRI_DEBUG);
8489
Server_->GetRuntime()->SetLogPriority(NKikimrServices::GRPC_SERVER, NActors::NLog::PRI_DEBUG);
8590
Server_->GetRuntime()->SetLogPriority(NKikimrServices::GRPC_PROXY, NActors::NLog::PRI_DEBUG);
86-
Server_->GetRuntime()->SetLogPriority(NKikimrServices::BSCONFIG, NActors::NLog::PRI_DEBUG);
91+
Server_->GetRuntime()->SetLogPriority(NKikimrServices::BS_CONTROLLER, NActors::NLog::PRI_DEBUG);
8792
Server_->GetRuntime()->SetLogPriority(NKikimrServices::BOOTSTRAPPER, NActors::NLog::PRI_DEBUG);
8893
//Server_->GetRuntime()->SetLogPriority(NKikimrServices::STATESTORAGE, NActors::NLog::PRI_DEBUG);
8994
//Server_->GetRuntime()->SetLogPriority(NKikimrServices::TABLET_EXECUTOR, NActors::NLog::PRI_DEBUG);
@@ -340,6 +345,71 @@ selector_config: []
340345
UNIT_ASSERT(!yamlConfigFetched);
341346
UNIT_ASSERT(!storageYamlConfigFetched);
342347
}
348+
349+
Y_UNIT_TEST(CheckV1IsBlocked) {
350+
TKikimrWithGrpcAndRootSchema server;
351+
TString yamlConfig = R"(
352+
metadata:
353+
kind: MainConfig
354+
cluster: ""
355+
version: 0
356+
357+
config:
358+
host_configs:
359+
- host_config_id: 1
360+
drive:
361+
- path: SectorMap:1:64
362+
type: SSD
363+
- path: SectorMap:2:64
364+
type: SSD
365+
- host_config_id: 2
366+
drive:
367+
- path: SectorMap:3:64
368+
type: SSD
369+
hosts:
370+
- host: ::1
371+
port: 12001
372+
host_config_id: 2
373+
feature_flags:
374+
switch_to_config_v2: true
375+
)";
376+
ReplaceConfig(server.GetChannel(), yamlConfig, std::nullopt, std::nullopt, false,
377+
[](const auto& resp) {
378+
UNIT_ASSERT_CHECK_STATUS(resp.operation(), Ydb::StatusIds::SUCCESS);
379+
});
380+
std::optional<TString> yamlConfigFetched, storageYamlConfigFetched;
381+
FetchConfig(server.GetChannel(), false, false, yamlConfigFetched, storageYamlConfigFetched);
382+
UNIT_ASSERT(yamlConfigFetched);
383+
UNIT_ASSERT(!storageYamlConfigFetched);
384+
UNIT_ASSERT_VALUES_EQUAL(yamlConfig, *yamlConfigFetched);
385+
386+
auto* runtime = server.GetRuntime();
387+
bool switchToConfigV2 = false;
388+
for (int i = 0; i < 10; ++i) {
389+
auto& appData = runtime->GetAppData(0);
390+
if (appData.FeatureFlags.GetSwitchToConfigV2()) {
391+
switchToConfigV2 = true;
392+
break;
393+
}
394+
Sleep(TDuration::MilliSeconds(100));
395+
}
396+
UNIT_ASSERT(switchToConfigV2);
397+
398+
std::unique_ptr<Ydb::DynamicConfig::V1::DynamicConfigService::Stub> stub;
399+
stub = Ydb::DynamicConfig::V1::DynamicConfigService::NewStub(server.GetChannel());
400+
401+
Ydb::DynamicConfig::ReplaceConfigRequest request;
402+
request.set_config(yamlConfig);
403+
404+
Ydb::DynamicConfig::ReplaceConfigResponse response;
405+
grpc::ClientContext context;
406+
AdjustCtxForDB(context);
407+
408+
stub->ReplaceConfig(&context, request, &response);
409+
410+
UNIT_ASSERT_CHECK_STATUS(response.operation(), Ydb::StatusIds::BAD_REQUEST);
411+
UNIT_ASSERT_STRING_CONTAINS(response.operation().issues(0).message(), "Dynamic Config V1 is disabled. Use V2 API.");
412+
}
343413
}
344414
345415
} // NKikimr::NGRpcService

ydb/tests/functional/config/test_distconf.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
from ydb.tests.library.common.types import Erasure
1212
import ydb.tests.library.common.cms as cms
1313
from ydb.tests.library.clients.kikimr_http_client import SwaggerClient
14+
from ydb.tests.library.clients.kikimr_dynconfig_client import DynConfigClient
1415
from ydb.tests.library.harness.kikimr_runner import KiKiMR
1516
from ydb.tests.library.harness.kikimr_config import KikimrConfigGenerator
1617
from ydb.tests.library.kv.helpers import create_kv_tablets_and_wait_for_start
@@ -95,7 +96,9 @@ def setup_class(cls):
9596
if not cls.protected_mode:
9697
cms.request_increase_ratio_limit(cls.cluster.client)
9798
host = cls.cluster.nodes[1].host
99+
grpc_port = cls.cluster.nodes[1].grpc_port
98100
cls.swagger_client = SwaggerClient(host, cls.cluster.nodes[1].mon_port)
101+
cls.dynconfig_client = DynConfigClient(host, grpc_port)
99102

100103
@classmethod
101104
def teardown_class(cls):
@@ -415,6 +418,13 @@ def test_invalid_change_host_config_disk(self):
415418
logger.debug(f"replace_config_response: {replace_config_response}")
416419
assert_that(replace_config_response.operation.status == StatusIds.INTERNAL_ERROR)
417420

421+
def test_v1_blocked_when_v2_is_enabled(self):
422+
fetched_config = fetch_config(self.cluster.config_client)
423+
replace_config_response = self.dynconfig_client.replace_config(fetched_config)
424+
assert_that(replace_config_response.operation.status == StatusIds.BAD_REQUEST)
425+
assert_that(replace_config_response.operation.issues[0].message == "Dynamic Config V1 is disabled. Use V2 API.")
426+
logger.debug(replace_config_response.operation)
427+
418428

419429
class TestDistConfBootstrapValidation:
420430

ydb/tests/library/clients/kikimr_dynconfig_client.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,11 @@ def fetch_config(self):
6565
request = dynamic_config_api.GetConfigRequest()
6666
return self.invoke(request, 'GetConfig')
6767

68+
def replace_config(self, config):
69+
request = dynamic_config_api.ReplaceConfigRequest()
70+
request.config = config
71+
return self.invoke(request, 'ReplaceConfig')
72+
6873
def get_configuration_version(self, list_nodes=False):
6974
request = dynamic_config_api.GetConfigurationVersionRequest(
7075
list_nodes=list_nodes

0 commit comments

Comments
 (0)