-
Notifications
You must be signed in to change notification settings - Fork 109
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #298 from YenchangChan/main
v3.2.0 ready
- Loading branch information
Showing
77 changed files
with
5,141 additions
and
2,965 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,6 +14,7 @@ ckmanpasswd | |
migrate | ||
znodefix | ||
znode_count | ||
cmd/ckmanctl/ckmanctl | ||
pkged.go | ||
static/dist/ | ||
coverage.xml | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
package ckconfig | ||
|
||
import ( | ||
"path" | ||
|
||
"github.com/housepower/ckman/common" | ||
"github.com/housepower/ckman/model" | ||
"github.com/imdario/mergo" | ||
) | ||
|
||
func keeper_root(ipv6Enable bool) map[string]interface{} { | ||
output := make(map[string]interface{}) | ||
if ipv6Enable { | ||
output["listen_host"] = "::" | ||
} else { | ||
output["listen_host"] = "0.0.0.0" | ||
} | ||
output["max_connections"] = 4096 | ||
return output | ||
} | ||
|
||
func keeper_server(conf *model.CKManClickHouseConfig, ipv6Enable bool, idx int) map[string]interface{} { | ||
output := keeper_root(ipv6Enable) | ||
output["logger"] = keeper_logger(conf) | ||
keeper_server := make(map[string]interface{}) | ||
mergo.Merge(&keeper_server, conf.KeeperConf.Expert) | ||
keeper_server["tcp_port"] = conf.KeeperConf.TcpPort | ||
keeper_server["server_id"] = idx | ||
keeper_server["log_storage_path"] = conf.KeeperConf.LogPath + "clickhouse/coordination/logs" | ||
keeper_server["snapshot_storage_path"] = conf.KeeperConf.SnapshotPath + "clickhouse/coordination/snapshots" | ||
keeper_server["coordination_settings"] = coordination_settings(conf.KeeperConf.Coordination) | ||
keeper_server["raft_configuration"] = raft_configuration(conf.KeeperConf) | ||
output["keeper_server"] = keeper_server | ||
return output | ||
} | ||
|
||
// https://github.com/ClickHouse/ClickHouse/blob/master/src/Coordination/CoordinationSettings.h | ||
func coordination_settings(coordination model.Coordination) map[string]interface{} { | ||
output := make(map[string]interface{}) | ||
mergo.Merge(&output, coordination.Expert) | ||
output["operation_timeout_ms"] = coordination.OperationTimeoutMs | ||
output["session_timeout_ms"] = coordination.SessionTimeoutMs | ||
if coordination.ForceSync { | ||
output["force_sync"] = "true" | ||
} else { | ||
output["force_sync"] = "false" | ||
} | ||
if coordination.AutoForwarding { | ||
output["auto_forwarding"] = "true" | ||
} else { | ||
output["auto_forwarding"] = "false" | ||
} | ||
return output | ||
} | ||
|
||
func keeper_logger(conf *model.CKManClickHouseConfig) map[string]interface{} { | ||
output := make(map[string]interface{}) | ||
output["level"] = "debug" | ||
output["size"] = "1000M" | ||
output["count"] = 10 | ||
if !conf.NeedSudo { | ||
output["log"] = path.Join(conf.Cwd, "log", "clickhouse-keeper", "clickhouse-keeper.log") | ||
output["errorlog"] = path.Join(conf.Cwd, "log", "clickhouse-keeper", "clickhouse-keeper.err.log") | ||
} | ||
return output | ||
|
||
} | ||
|
||
func raft_configuration(conf *model.KeeperConf) []map[string]interface{} { | ||
var outputs []map[string]interface{} | ||
for idx, node := range conf.KeeperNodes { | ||
output := make(map[string]interface{}) | ||
output["server"] = map[string]interface{}{ | ||
"id": idx + 1, | ||
"hostname": node, | ||
"port": conf.RaftPort, | ||
} | ||
outputs = append(outputs, output) | ||
} | ||
return outputs | ||
} | ||
|
||
func GenerateKeeperXML(filename string, conf *model.CKManClickHouseConfig, ipv6Enable bool, idx int) (string, error) { | ||
xml := common.NewXmlFile(filename) | ||
rootTag := "clickhouse" | ||
xml.Begin(rootTag) | ||
xml.Merge(keeper_server(conf, ipv6Enable, idx)) | ||
xml.End(rootTag) | ||
if err := xml.Dump(); err != nil { | ||
return filename, err | ||
} | ||
return filename, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
<clickhouse> | ||
<keeper_server> | ||
<coordination_settings> | ||
<auto_forwarding>false</auto_forwarding> | ||
<force_sync>true</force_sync> | ||
<operation_timeout_ms>10000</operation_timeout_ms> | ||
<raft_log_level>Information</raft_log_level> | ||
<session_timeout_ms>30000</session_timeout_ms> | ||
</coordination_settings> | ||
<log_storage_path>/var/lib/clickhouse/coordination/log</log_storage_path> | ||
<raft_configuration> | ||
<server> | ||
<hostname>192.168.101.102</hostname> | ||
<id>1</id> | ||
<port>9181</port> | ||
</server> | ||
<server> | ||
<hostname>192.168.101.105</hostname> | ||
<id>2</id> | ||
<port>9181</port> | ||
</server> | ||
<server> | ||
<hostname>192.168.101.107</hostname> | ||
<id>3</id> | ||
<port>9181</port> | ||
</server> | ||
</raft_configuration> | ||
<server_id>2</server_id> | ||
<snapshot_storage_path>/var/lib/clickhouse/coordination/snapshots</snapshot_storage_path> | ||
<tcp_port>9181</tcp_port> | ||
</keeper_server> | ||
<listen_host>::</listen_host> | ||
<logger> | ||
<level>debug</level> | ||
</logger> | ||
<max_connections>4096</max_connections> | ||
</clickhouse> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package ckconfig | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/housepower/ckman/model" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestGenerateKeeperXML(t *testing.T) { | ||
conf := model.CKManClickHouseConfig{ | ||
KeeperConf: &model.KeeperConf{ | ||
KeeperNodes: []string{"192.168.101.102", "192.168.101.105", "192.168.101.107"}, | ||
TcpPort: 9181, | ||
RaftPort: 9234, | ||
LogPath: "/var/lib/clickhouse/coordination/log", | ||
SnapshotPath: "/var/lib/clickhouse/coordination/snapshots", | ||
Coordination: model.Coordination{ | ||
OperationTimeoutMs: 10000, | ||
SessionTimeoutMs: 30000, | ||
ForceSync: true, | ||
}, | ||
}, | ||
} | ||
_, err := GenerateKeeperXML("keeper_fake.xml", &conf, true, 2) | ||
assert.Nil(t, err) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.