From 29a7e182a6a9c2970b9c2c2d55062d17f33f084e Mon Sep 17 00:00:00 2001 From: Corey Hulen Date: Wed, 16 Aug 2017 10:29:45 -0700 Subject: [PATCH] PLT-6079 Adding leader election (#7105) --- app/diagnostics.go | 2 +- einterfaces/cluster.go | 1 + model/cluster_info.go | 1 + utils/config.go | 8 ++++++++ 4 files changed, 11 insertions(+), 1 deletion(-) diff --git a/app/diagnostics.go b/app/diagnostics.go index 2eae5871d8..1df5b1feb7 100644 --- a/app/diagnostics.go +++ b/app/diagnostics.go @@ -49,7 +49,7 @@ const ( var client *analytics.Client func SendDailyDiagnostics() { - if *utils.Cfg.LogSettings.EnableDiagnostics { + if *utils.Cfg.LogSettings.EnableDiagnostics && utils.IsLeader() { initDiagnostics("") trackActivity() trackConfig() diff --git a/einterfaces/cluster.go b/einterfaces/cluster.go index 096a775fe4..9d61b75031 100644 --- a/einterfaces/cluster.go +++ b/einterfaces/cluster.go @@ -14,6 +14,7 @@ type ClusterInterface interface { StopInterNodeCommunication() RegisterClusterMessageHandler(event string, crm ClusterMessageHandler) GetClusterId() string + IsLeader() bool GetClusterInfos() []*model.ClusterInfo SendClusterMessage(cluster *model.ClusterMessage) NotifyMsg(buf []byte) diff --git a/model/cluster_info.go b/model/cluster_info.go index 1e468044e0..c4f7e89a60 100644 --- a/model/cluster_info.go +++ b/model/cluster_info.go @@ -10,6 +10,7 @@ import ( ) type ClusterInfo struct { + Id string `json:"id"` Version string `json:"version"` ConfigHash string `json:"config_hash"` IpAddress string `json:"ipaddress"` diff --git a/utils/config.go b/utils/config.go index 187af41255..af88f816ec 100644 --- a/utils/config.go +++ b/utils/config.go @@ -653,3 +653,11 @@ func Desanitize(cfg *model.Config) { cfg.SqlSettings.DataSourceSearchReplicas[i] = Cfg.SqlSettings.DataSourceSearchReplicas[i] } } + +func IsLeader() bool { + if IsLicensed && *Cfg.ClusterSettings.Enable && einterfaces.GetClusterInterface() != nil { + return einterfaces.GetClusterInterface().IsLeader() + } else { + return true + } +}