Skip to content

Commit

Permalink
dev: split chk config into server and raft sections
Browse files Browse the repository at this point in the history
  • Loading branch information
sunsingerus committed Oct 3, 2024
1 parent ba9037c commit e6dbc15
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 10 deletions.
3 changes: 2 additions & 1 deletion pkg/model/chk/config/const.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,11 @@ const (
)

const (
xmlTagYandex = "yandex"
xmlTagClickHouse = "clickhouse"
)

const (
configServerId = "server-id"
configRaft = "raft"
configSettings = "settings"
)
3 changes: 2 additions & 1 deletion pkg/model/chk/config/files_generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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) {
Expand Down
30 changes: 22 additions & 8 deletions pkg/model/chk/config/generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,9 @@ func (c *Generator) generateXMLConfig(settings *chi.Settings, prefix string) str
// <yandex>
// XML code
// </yandex>
util.Iline(b, 0, "<"+xmlTagYandex+">")
util.Iline(b, 0, "<"+xmlTagClickHouse+">")
xml.GenerateFromSettings(b, settings, prefix)
util.Iline(b, 0, "</"+xmlTagYandex+">")
util.Iline(b, 0, "</"+xmlTagClickHouse+">")

return b.String()
}
Expand Down Expand Up @@ -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()))
Expand All @@ -104,7 +102,23 @@ func (c *Generator) getHostRaft(host *chi.Host) string {
// settings as xml
// </clickhouse>
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:
// <clickhouse>
// settings as xml
// </clickhouse>
config := &bytes.Buffer{}
xml.GenerateFromSettings(config, settings, xmlTagClickHouse)

return config.String()
}
Expand Down

0 comments on commit e6dbc15

Please sign in to comment.