Skip to content

Commit

Permalink
dev: unify includer and excluder
Browse files Browse the repository at this point in the history
  • Loading branch information
sunsingerus committed Apr 9, 2024
1 parent 82f4ec5 commit 5412203
Showing 1 changed file with 21 additions and 15 deletions.
36 changes: 21 additions & 15 deletions pkg/controller/chi/worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -1098,19 +1098,20 @@ func (w *worker) excludeHostFromClickHouseCluster(ctx context.Context, host *api
return
}

// Remove host from cluster config and wait for ClickHouse to pick-up the change
if w.shouldWaitExcludeHost(host) {
w.a.V(1).
M(host).F().
Info("going to exclude host %d shard %d cluster %s",
host.Runtime.Address.ReplicaIndex, host.Runtime.Address.ShardIndex, host.Runtime.Address.ClusterName)
w.a.V(1).
M(host).F().
Info("going to exclude host %d shard %d cluster %s",
host.Runtime.Address.ReplicaIndex, host.Runtime.Address.ShardIndex, host.Runtime.Address.ClusterName)

// Specify in options to exclude this host from ClickHouse config file
options := w.options(host)
_ = w.reconcileCHIConfigMapCommon(ctx, host.GetCHI(), options)

// Specify in options to exclude host from ClickHouse config file
options := w.options(host)
_ = w.reconcileCHIConfigMapCommon(ctx, host.GetCHI(), options)
// Wait for ClickHouse to pick-up the change
_ = w.waitHostNotInCluster(ctx, host)
if !w.shouldWaitExcludeHost(host) {
return
}
// Wait for ClickHouse to pick-up the change
_ = w.waitHostNotInCluster(ctx, host)
}

// includeHostIntoClickHouseCluster includes host into ClickHouse configuration
Expand All @@ -1120,7 +1121,12 @@ func (w *worker) includeHostIntoClickHouseCluster(ctx context.Context, host *api
return
}

// Add host to the cluster config
w.a.V(1).
M(host).F().
Info("going to include host %d shard %d cluster %s",
host.Runtime.Address.ReplicaIndex, host.Runtime.Address.ShardIndex, host.Runtime.Address.ClusterName)

// Specify in options to add this host into ClickHouse config file
options := w.options()
_ = w.reconcileCHIConfigMapCommon(ctx, host.GetCHI(), options)

Expand Down Expand Up @@ -1181,20 +1187,20 @@ func (w *worker) shouldWaitExcludeHost(host *api.ChiHost) bool {
case host.GetCHI().GetReconciling().IsReconcilingPolicyWait():
w.a.V(1).
M(host).F().
Info("IsReconcilingPolicyWait() need to exclude host %d shard %d cluster %s",
Info("IsReconcilingPolicyWait() need to wait to exclude host %d shard %d cluster %s",
host.Runtime.Address.ReplicaIndex, host.Runtime.Address.ShardIndex, host.Runtime.Address.ClusterName)
return true
case host.GetCHI().GetReconciling().IsReconcilingPolicyNoWait():
w.a.V(1).
M(host).F().
Info("IsReconcilingPolicyNoWait() need NOT to exclude host %d shard %d cluster %s",
Info("IsReconcilingPolicyNoWait() need NOT to wait to exclude host %d shard %d cluster %s",
host.Runtime.Address.ReplicaIndex, host.Runtime.Address.ShardIndex, host.Runtime.Address.ClusterName)
return false
}

w.a.V(1).
M(host).F().
Info("fallback to operator's settings. host %d shard %d cluster %s",
Info("wait to exclude host fallback to operator's settings. host %d shard %d cluster %s",
host.Runtime.Address.ReplicaIndex, host.Runtime.Address.ShardIndex, host.Runtime.Address.ClusterName)
return chop.Config().Reconcile.Host.Wait.Exclude.Value()
}
Expand Down

0 comments on commit 5412203

Please sign in to comment.