Skip to content

Commit

Permalink
Check the host is in real cluster instead of all-sharded
Browse files Browse the repository at this point in the history
  • Loading branch information
alex-zaitsev committed Dec 20, 2024
1 parent d5b2995 commit 7cf2cd3
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 6 deletions.
4 changes: 2 additions & 2 deletions pkg/model/chi/schemer/schemer.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,9 +130,9 @@ func (s *ClusterSchemer) HostDropTables(ctx context.Context, host *api.Host) err
// IsHostInCluster checks whether host is a member of at least one ClickHouse cluster
func (s *ClusterSchemer) IsHostInCluster(ctx context.Context, host *api.Host) bool {
inside := false
SQLs := []string{s.sqlHostInCluster()}
sql := s.sqlHostInCluster(host.Runtime.Address.ClusterName)
opts := clickhouse.NewQueryOptions().SetSilent(true)
err := s.ExecHost(ctx, host, SQLs, opts)
err := s.ExecHost(ctx, host, []string{sql}, opts)
if err == nil {
log.V(1).M(host).F().Info("The host %s is inside the cluster", host.GetName())
inside = true
Expand Down
7 changes: 3 additions & 4 deletions pkg/model/chi/schemer/sql.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import (

api "github.com/altinity/clickhouse-operator/pkg/apis/clickhouse.altinity.com/v1"
"github.com/altinity/clickhouse-operator/pkg/interfaces"
"github.com/altinity/clickhouse-operator/pkg/model/chi/config"
)

const ignoredDBs = `'system', 'information_schema', 'INFORMATION_SCHEMA'`
Expand Down Expand Up @@ -246,8 +245,8 @@ func (s *ClusterSchemer) sqlVersion() string {
return `SELECT version()`
}

func (s *ClusterSchemer) sqlHostInCluster() string {
// TODO: Change to select count() query to avoid exception in operator and ClickHouse logs
func (s *ClusterSchemer) sqlHostInCluster(cluster string) string {
// TODO: Change throwIf to select count() query to avoid exception in operator and ClickHouse logs
return heredoc.Docf(`
SELECT
throwIf(count()=0)
Expand All @@ -256,6 +255,6 @@ func (s *ClusterSchemer) sqlHostInCluster() string {
WHERE
cluster='%s' AND is_local
`,
config.AllShardsOneReplicaClusterName,
cluster,
)
}

0 comments on commit 7cf2cd3

Please sign in to comment.