From e6dbc1502a376c3ba41b96d34ca83ba097670ee8 Mon Sep 17 00:00:00 2001 From: Vladislav Klimenko Date: Thu, 3 Oct 2024 18:52:08 +0300 Subject: [PATCH] dev: split chk config into server and raft sections --- pkg/model/chk/config/const.go | 3 ++- pkg/model/chk/config/files_generator.go | 3 ++- pkg/model/chk/config/generator.go | 30 ++++++++++++++++++------- 3 files changed, 26 insertions(+), 10 deletions(-) diff --git a/pkg/model/chk/config/const.go b/pkg/model/chk/config/const.go index 2c8c6ef60..dfa863451 100644 --- a/pkg/model/chk/config/const.go +++ b/pkg/model/chk/config/const.go @@ -72,10 +72,11 @@ const ( ) const ( - xmlTagYandex = "yandex" + xmlTagClickHouse = "clickhouse" ) const ( + configServerId = "server-id" configRaft = "raft" configSettings = "settings" ) diff --git a/pkg/model/chk/config/files_generator.go b/pkg/model/chk/config/files_generator.go index 20fb66687..55794dc32 100644 --- a/pkg/model/chk/config/files_generator.go +++ b/pkg/model/chk/config/files_generator.go @@ -71,6 +71,7 @@ func (c *FilesGenerator) createConfigFilesGroupCommon(options *FilesGeneratorOpt } func (c *FilesGenerator) createConfigFilesGroupCommonDomain(configSections map[string]string, options *FilesGeneratorOptions) { + util.IncludeNonEmpty(configSections, createConfigSectionFilename(configRaft), c.configGenerator.getRaftConfig()) } func (c *FilesGenerator) createConfigFilesGroupCommonGeneric(configSections map[string]string, options *FilesGeneratorOptions) { @@ -115,7 +116,7 @@ func (c *FilesGenerator) createConfigFilesGroupHost(options *FilesGeneratorOptio } func (c *FilesGenerator) createConfigFilesGroupHostDomain(configSections map[string]string, options *FilesGeneratorOptions) { - util.IncludeNonEmpty(configSections, createConfigSectionFilename(configRaft), c.configGenerator.getHostRaft(options.GetHost())) + util.IncludeNonEmpty(configSections, createConfigSectionFilename(configServerId), c.configGenerator.getHostServerId(options.GetHost())) } func (c *FilesGenerator) createConfigFilesGroupHostGeneric(configSections map[string]string, options *FilesGeneratorOptions) { diff --git a/pkg/model/chk/config/generator.go b/pkg/model/chk/config/generator.go index 7da513389..8b29b99d6 100644 --- a/pkg/model/chk/config/generator.go +++ b/pkg/model/chk/config/generator.go @@ -51,9 +51,9 @@ func (c *Generator) generateXMLConfig(settings *chi.Settings, prefix string) str // // XML code // - util.Iline(b, 0, "<"+xmlTagYandex+">") + util.Iline(b, 0, "<"+xmlTagClickHouse+">") xml.GenerateFromSettings(b, settings, prefix) - util.Iline(b, 0, "") + util.Iline(b, 0, "") return b.String() } @@ -86,13 +86,11 @@ func (c *Generator) getSectionFromFiles(section chi.SettingsSection, includeUnsp return files.GetSection(section, includeUnspecified) } -// getHostRaft builds host raft config -func (c *Generator) getHostRaft(host *chi.Host) string { +// getRaftConfig builds raft config for the chk +func (c *Generator) getRaftConfig() string { settings := chi.NewSettings() - settings.Set("keeper_server/server_id", chi.MustNewSettingScalarFromAny(getServerId(host))) - - host.GetCR().WalkHosts(func(_host *chi.Host) error { + c.cr.WalkHosts(func(_host *chi.Host) error { settings.Set("keeper_server/raft_configuration/server/id", chi.MustNewSettingScalarFromAny(getServerId(_host))) settings.Set("keeper_server/raft_configuration/server/hostname", chi.NewSettingScalar(c.namer.Name(interfaces.NameInstanceHostname, _host))) settings.Set("keeper_server/raft_configuration/server/port", chi.MustNewSettingScalarFromAny(_host.RaftPort.Value())) @@ -104,7 +102,23 @@ func (c *Generator) getHostRaft(host *chi.Host) string { // settings as xml // config := &bytes.Buffer{} - xml.GenerateFromSettings(config, settings, "clickhouse") + xml.GenerateFromSettings(config, settings, xmlTagClickHouse) + + return config.String() +} + +// getHostServerId builds server id config for the host +func (c *Generator) getHostServerId(host *chi.Host) string { + settings := chi.NewSettings() + + settings.Set("keeper_server/server_id", chi.MustNewSettingScalarFromAny(getServerId(host))) + + // Write xml as: + // + // settings as xml + // + config := &bytes.Buffer{} + xml.GenerateFromSettings(config, settings, xmlTagClickHouse) return config.String() }