Skip to content

Commit

Permalink
Add stable node names (ydb-platform#5759)
Browse files Browse the repository at this point in the history
  • Loading branch information
pixcc authored Jun 20, 2024
1 parent 49e8858 commit 9242688
Show file tree
Hide file tree
Showing 30 changed files with 631 additions and 30 deletions.
1 change: 1 addition & 0 deletions ydb/core/base/appdata_fwd.h
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,7 @@ struct TAppData {
TVector<TString> DefaultUserSIDs;
TString AllAuthenticatedUsers = "all-users@well-known";
TString TenantName;
TString NodeName;

TIntrusivePtr<TResourceProfiles> ResourceProfiles;

Expand Down
40 changes: 35 additions & 5 deletions ydb/core/driver_lib/cli_utils/cli_cmds_server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -722,8 +722,23 @@ class TClientCommandServerBase : public TClientCommand {
TRACE_CONFIG_CHANGE_INPLACE_T(TenantPoolConfig, UpdateExplicitly);
}

if (config.ParseResult->Has("tenant") && InterconnectPort != DefaultInterconnectPort) {
AppConfig.MutableMonitoringConfig()->SetHostLabelOverride(HostAndICPort());
if (config.ParseResult->Has("tenant")) {
if (AppConfig.GetDynamicNodeConfig().GetNodeInfo().HasName()) {
const TString& nodeName = AppConfig.GetDynamicNodeConfig().GetNodeInfo().GetName();
AppConfig.MutableMonitoringConfig()->SetHostLabelOverride(nodeName);
TRACE_CONFIG_CHANGE_INPLACE_T(MonitoringConfig, UpdateExplicitly);
} else if (InterconnectPort != DefaultInterconnectPort) {
AppConfig.MutableMonitoringConfig()->SetHostLabelOverride(HostAndICPort());
TRACE_CONFIG_CHANGE_INPLACE_T(MonitoringConfig, UpdateExplicitly);
}
}

if (config.ParseResult->Has("tenant")) {
if (InterconnectPort == DefaultInterconnectPort) {
AppConfig.MutableMonitoringConfig()->SetProcessLocation(Host());
} else {
AppConfig.MutableMonitoringConfig()->SetProcessLocation(HostAndICPort());
}
TRACE_CONFIG_CHANGE_INPLACE_T(MonitoringConfig, UpdateExplicitly);
}

Expand Down Expand Up @@ -989,11 +1004,18 @@ class TClientCommandServerBase : public TClientCommand {
ShuffleRange(addrs);
}

TString HostAndICPort() {
TString HostAndICPort() const {
auto hostname = Host();
if (!hostname) {
return "";
}
return TStringBuilder() << hostname << ":" << InterconnectPort;
}

TString Host() const {
try {
auto hostname = to_lower(HostName());
hostname = hostname.substr(0, hostname.find('.'));
return TStringBuilder() << hostname << ":" << InterconnectPort;
return hostname.substr(0, hostname.find('.'));
} catch (TSystemError& error) {
return "";
}
Expand All @@ -1015,6 +1037,11 @@ class TClientCommandServerBase : public TClientCommand {
result = TryToRegisterDynamicNodeViaDiscoveryService(addr, domainName, NodeHost, NodeAddress, NodeResolveHost, GetSchemePath());
if (result.IsSuccess()) {
Cout << "Success. Registered via discovery service as " << result.GetNodeId() << Endl;
Cout << "Node name: ";
if (result.HasNodeName()) {
Cout << result.GetNodeName();
}
Cout << Endl;
break;
}
Cerr << "Registration error: " << static_cast<NYdb::TStatus>(result) << Endl;
Expand Down Expand Up @@ -1052,6 +1079,9 @@ class TClientCommandServerBase : public TClientCommand {
nodeInfo->SetAddress(node.Address);
nodeInfo->SetExpire(node.Expire);
CopyNodeLocation(nodeInfo->MutableLocation(), node.Location);
if (result.HasNodeName()) {
nodeInfo->SetName(result.GetNodeName());
}
} else {
auto &info = *nsConfig.AddNode();
info.SetNodeId(node.NodeId);
Expand Down
2 changes: 1 addition & 1 deletion ydb/core/driver_lib/run/kikimr_services_initializers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2116,7 +2116,7 @@ void TKqpServiceInitializer::InitializeServices(NActors::TActorSystemSetup* setu

auto kqpProxySharedResources = std::make_shared<NKqp::TKqpProxySharedResources>();

// Crate resource manager
// Create resource manager
auto rm = NKqp::CreateKqpResourceManagerActor(Config.GetTableServiceConfig().GetResourceManager(), nullptr,
{}, kqpProxySharedResources);
setup->LocalServices.push_back(std::make_pair(
Expand Down
4 changes: 4 additions & 0 deletions ydb/core/driver_lib/run/run.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1075,6 +1075,10 @@ void TKikimrRunner::InitializeAppData(const TKikimrRunConfig& runConfig)

AppData->TenantName = runConfig.TenantName;

if (runConfig.AppConfig.GetDynamicNodeConfig().GetNodeInfo().HasName()) {
AppData->NodeName = runConfig.AppConfig.GetDynamicNodeConfig().GetNodeInfo().GetName();
}

if (runConfig.AppConfig.HasBootstrapConfig()) {
AppData->BootstrapConfig = runConfig.AppConfig.GetBootstrapConfig();
}
Expand Down
3 changes: 3 additions & 0 deletions ydb/core/grpc_services/rpc_node_registration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,9 @@ class TNodeRegistrationRPC : public TActorBootstrapped<TNodeRegistrationRPC> {

auto request = TEvNodeRegistrationRequest::GetProtoRequest(Request);
Result.set_node_id(rec.GetNode().GetNodeId());
if (rec.GetNode().HasName()) {
Result.set_node_name(rec.GetNode().GetName());
}
Result.set_expire(rec.GetNode().GetExpire());
Result.set_domain_path(request->domain_path());
CopyNodeInfo(Result.add_nodes(), rec.GetNode());
Expand Down
3 changes: 3 additions & 0 deletions ydb/core/mind/hive/hive_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1974,6 +1974,9 @@ void THive::Handle(TEvHive::TEvRequestHiveNodeStats::TPtr& ev) {
if (!node.ServicedDomains.empty()) {
nodeStats.MutableNodeDomain()->CopyFrom(node.ServicedDomains.front());
}
if (!node.Name.empty()) {
nodeStats.SetNodeName(node.Name);
}
if (request.GetReturnExtendedTabletInfo()) {
if (request.HasFilterTabletsByPathId()) {
auto itTabletsOfObject = node.TabletsOfObject.find({request.GetFilterTabletsBySchemeShardId(), request.GetFilterTabletsByPathId()});
Expand Down
3 changes: 2 additions & 1 deletion ydb/core/mind/hive/hive_schema.h
Original file line number Diff line number Diff line change
Expand Up @@ -192,9 +192,10 @@ struct Schema : NIceDb::Schema {
struct Drain : Column<6, NScheme::NTypeIds::Bool> { static constexpr bool Default = false; };
struct DrainInitiators : Column<8, NScheme::NTypeIds::String> { using Type = TVector<TActorId>; };
struct Location : Column<9, NScheme::NTypeIds::String> { using Type = NActorsInterconnect::TNodeLocation; };
struct Name : Column<10, NScheme::NTypeIds::String> {};

using TKey = TableKey<ID>;
using TColumns = TableColumns<ID, Local, Down, Freeze, ServicedDomains, Statistics, Drain, DrainInitiators, Location>;
using TColumns = TableColumns<ID, Local, Down, Freeze, ServicedDomains, Statistics, Drain, DrainInitiators, Location, Name>;
};

struct TabletCategory : Table<6> {
Expand Down
1 change: 1 addition & 0 deletions ydb/core/mind/hive/node_info.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ struct TNodeInfo {
THashSet<TLeaderTabletInfo*> LockedTablets;
mutable TInstant LastResourceChangeReaction;
NKikimrHive::TNodeStatistics Statistics;
TString Name;

TNodeInfo(TNodeId nodeId, THive& hive);
TNodeInfo(const TNodeInfo&) = delete;
Expand Down
1 change: 1 addition & 0 deletions ydb/core/mind/hive/tx__load_everything.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,7 @@ class TTxLoadEverything : public TTransactionBase<THive> {
node.DrainInitiators = nodeRowset.GetValueOrDefault<Schema::Node::DrainInitiators>();
node.ServicedDomains = nodeRowset.GetValueOrDefault<Schema::Node::ServicedDomains>();
node.Statistics = nodeRowset.GetValueOrDefault<Schema::Node::Statistics>();
node.Name = nodeRowset.GetValueOrDefault<Schema::Node::Name>();
if (nodeRowset.HaveValue<Schema::Node::Location>()) {
auto location = nodeRowset.GetValue<Schema::Node::Location>();
if (location.HasDataCenter()) {
Expand Down
10 changes: 9 additions & 1 deletion ydb/core/mind/hive/tx__register_node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,14 @@ class TTxRegisterNode : public TTransactionBase<THive> {
} else {
Sort(servicedDomains);
}
db.Table<Schema::Node>().Key(nodeId).Update<Schema::Node::Local, Schema::Node::ServicedDomains, Schema::Node::Statistics>(Local, servicedDomains, node.Statistics);
const TString& name = Record.GetName();
db.Table<Schema::Node>().Key(nodeId).Update(
NIceDb::TUpdate<Schema::Node::Local>(Local),
NIceDb::TUpdate<Schema::Node::ServicedDomains>(servicedDomains),
NIceDb::TUpdate<Schema::Node::Statistics>(node.Statistics),
NIceDb::TUpdate<Schema::Node::Name>(name)
);

node.BecomeDisconnected();
if (node.LastSeenServicedDomains != servicedDomains) {
// new tenant - new rules
Expand All @@ -52,6 +59,7 @@ class TTxRegisterNode : public TTransactionBase<THive> {
node.Local = Local;
node.ServicedDomains.swap(servicedDomains);
node.LastSeenServicedDomains = node.ServicedDomains;
node.Name = name;
}
if (Record.HasSystemLocation() && Record.GetSystemLocation().HasDataCenter()) {
node.Location = TNodeLocation(Record.GetSystemLocation());
Expand Down
3 changes: 3 additions & 0 deletions ydb/core/mind/local.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,9 @@ class TLocalNodeRegistrar : public TActorBootstrapped<TLocalNodeRegistrar> {
}
tabletAvailability->SetPriority(tabletInfo.Priority);
}
if (const TString& nodeName = AppData(ctx)->NodeName; !nodeName.Empty()) {
request->Record.SetName(nodeName);
}

NTabletPipe::SendData(ctx, HivePipeClient, request.Release());

Expand Down
Loading

0 comments on commit 9242688

Please sign in to comment.