Skip to content

Commit

Permalink
Rename negative flags
Browse files Browse the repository at this point in the history
`canBeMaster` and `canBeSynchronousReplica` are default to true when nil
  • Loading branch information
rnaveiras committed Sep 18, 2019
1 parent 3705fb2 commit a978806
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 40 deletions.
21 changes: 10 additions & 11 deletions cmd/keeper/cmd/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,8 @@ type config struct {
pgInitialSUUsername string
pgInitialSUPasswordFile string

neverMaster bool
neverSynchronousReplica bool
canBeMaster bool
canBeSynchronousReplica bool
}

var cfg config
Expand Down Expand Up @@ -147,8 +147,8 @@ func init() {
CmdKeeper.PersistentFlags().StringVar(&cfg.pgSUPasswordFile, "pg-su-passwordfile", "", "postgres superuser password file. Only one of --pg-su-password or --pg-su-passwordfile must be provided. Must be the same for all keepers)")
CmdKeeper.PersistentFlags().BoolVar(&cfg.debug, "debug", false, "enable debug logging")

CmdKeeper.PersistentFlags().BoolVar(&cfg.neverMaster, "never-master", false, "prevent keeper from being elected as master")
CmdKeeper.PersistentFlags().BoolVar(&cfg.neverSynchronousReplica, "never-synchronous-replica", false, "prevent keeper from being chosen as synchronous replica")
CmdKeeper.PersistentFlags().BoolVar(&cfg.canBeMaster, "can-be-master", true, "prevent keeper from being elected as master")
CmdKeeper.PersistentFlags().BoolVar(&cfg.canBeSynchronousReplica, "can-be-synchronous-replica", true, "prevent keeper from being chosen as synchronous replica")

CmdKeeper.PersistentFlags().MarkDeprecated("id", "please use --uid")
CmdKeeper.PersistentFlags().MarkDeprecated("debug", "use --log-level=debug instead")
Expand Down Expand Up @@ -463,8 +463,8 @@ type PostgresKeeper struct {

waitSyncStandbysSynced bool

neverMaster bool
neverSynchronousReplica bool
canBeMaster *bool
canBeSynchronousReplica *bool
}

func NewPostgresKeeper(cfg *config, end chan error) (*PostgresKeeper, error) {
Expand Down Expand Up @@ -505,8 +505,8 @@ func NewPostgresKeeper(cfg *config, end chan error) (*PostgresKeeper, error) {
keeperLocalState: &KeeperLocalState{},
dbLocalState: &DBLocalState{},

neverMaster: cfg.neverMaster,
neverSynchronousReplica: cfg.neverSynchronousReplica,
canBeMaster: &cfg.canBeMaster,
canBeSynchronousReplica: &cfg.canBeSynchronousReplica,

e: e,
end: end,
Expand Down Expand Up @@ -574,11 +574,10 @@ func (p *PostgresKeeper) updateKeeperInfo() error {
Maj: maj,
Min: min,
},

PostgresState: p.getLastPGState(),

NeverMaster: p.neverMaster,
NeverSynchronousReplica: p.neverSynchronousReplica,
CanBeMaster: p.canBeMaster,
CanBeSynchronousReplica: p.canBeSynchronousReplica,
}

// The time to live is just to automatically remove old entries, it's
Expand Down
12 changes: 6 additions & 6 deletions cmd/sentinel/cmd/sentinel.go
Original file line number Diff line number Diff line change
Expand Up @@ -234,8 +234,8 @@ func (s *Sentinel) updateKeepersStatus(cd *cluster.ClusterData, keepersInfo clus
// the cluster that take into consideration the configuration of each keeper.
for keeperUID, k := range cd.Keepers {
if ki, ok := keepersInfo[keeperUID]; ok {
k.Status.NeverMaster = ki.NeverMaster
k.Status.NeverSynchronousReplica = ki.NeverSynchronousReplica
k.Status.CanBeMaster = ki.CanBeMaster
k.Status.CanBeSynchronousReplica = ki.CanBeSynchronousReplica
}
}

Expand Down Expand Up @@ -741,8 +741,8 @@ func (s *Sentinel) findBestStandbys(cd *cluster.ClusterData, masterDB *cluster.D
func (s *Sentinel) findBestNewMasters(cd *cluster.ClusterData, masterDB *cluster.DB) []*cluster.DB {
bestNewMasters := []*cluster.DB{}
for _, db := range s.findBestStandbys(cd, masterDB) {
if k, ok := cd.Keepers[db.Spec.KeeperUID]; ok && k.Status.NeverMaster {
log.Infow("ignoring keeper since it cannot be master (--never-master)", "db", db.UID, "keeper", db.Spec.KeeperUID)
if k, ok := cd.Keepers[db.Spec.KeeperUID]; ok && (k.Status.CanBeMaster != nil && !*k.Status.CanBeMaster) {
log.Infow("ignoring keeper since it cannot be master (--can-be-master=false)", "db", db.UID, "keeper", db.Spec.KeeperUID)
continue
}

Expand Down Expand Up @@ -1344,8 +1344,8 @@ func (s *Sentinel) updateCluster(cd *cluster.ClusterData, pis cluster.ProxiesInf

// ignore standbys that cannot be synchronous standbys
if db, ok := newcd.DBs[bestStandby.UID]; ok {
if keeper, ok := newcd.Keepers[db.Spec.KeeperUID]; ok && keeper.Status.NeverSynchronousReplica {
log.Infow("cannot choose standby as synchronous (--never-synchronous-replica)", "db", db.UID, "keeper", keeper.UID)
if keeper, ok := newcd.Keepers[db.Spec.KeeperUID]; ok && (keeper.Status.CanBeSynchronousReplica != nil && !*keeper.Status.CanBeSynchronousReplica) {
log.Infow("cannot choose standby as synchronous (--can-be-synchronous-replica=false)", "db", db.UID, "keeper", keeper.UID)
continue
}
}
Expand Down
12 changes: 8 additions & 4 deletions cmd/sentinel/cmd/sentinel_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4998,7 +4998,7 @@ func TestUpdateCluster(t *testing.T) {
Status: cluster.KeeperStatus{
Healthy: true,
LastHealthyTime: now,
NeverSynchronousReplica: true,
CanBeSynchronousReplica: newBool(false),
},
},
},
Expand Down Expand Up @@ -5092,7 +5092,7 @@ func TestUpdateCluster(t *testing.T) {
Status: cluster.KeeperStatus{
Healthy: true,
LastHealthyTime: now,
NeverSynchronousReplica: true,
CanBeSynchronousReplica: newBool(false),
},
},
},
Expand Down Expand Up @@ -5192,7 +5192,7 @@ func TestUpdateCluster(t *testing.T) {
Status: cluster.KeeperStatus{
Healthy: true,
LastHealthyTime: now,
NeverMaster: true,
CanBeMaster: newBool(false),
},
},
},
Expand Down Expand Up @@ -5286,7 +5286,7 @@ func TestUpdateCluster(t *testing.T) {
Status: cluster.KeeperStatus{
Healthy: true,
LastHealthyTime: now,
NeverMaster: true,
CanBeMaster: newBool(false),
},
},
},
Expand Down Expand Up @@ -5493,3 +5493,7 @@ func testEqualCD(cd1, cd2 *cluster.ClusterData) bool {
return reflect.DeepEqual(cd1, cd2)

}

func newBool(b bool) *bool {
return &b
}
4 changes: 1 addition & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ require (
github.com/PuerkitoBio/purell v1.1.0 // indirect
github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578 // indirect
github.com/armon/go-metrics v0.0.0-20180917152333-f0300d1749da // indirect
github.com/boltdb/bolt v1.3.1 // indirect
github.com/cockroachdb/cmux v0.0.0-20170110192607-30d10be49292 // indirect
github.com/coreos/bbolt v1.3.2 // indirect
github.com/coreos/etcd v3.3.13+incompatible
github.com/coreos/go-semver v0.0.0-20150725033620-d043ae190b32 // indirect
Expand Down Expand Up @@ -77,8 +75,8 @@ require (
github.com/spf13/cobra v0.0.0-20171204131325-de2d9c4eca8f
github.com/spf13/pflag v1.0.0
github.com/tmc/grpc-websocket-proxy v0.0.0-20190109142713-0ad062ec5ee5 // indirect
github.com/ugorji/go v0.0.0-20151028022000-f1f1a805ed36 // indirect
github.com/xiang90/probing v0.0.0-20160813154853-07dd2e8dfe18 // indirect
go.etcd.io/bbolt v1.3.3 // indirect
go.uber.org/atomic v1.3.1 // indirect
go.uber.org/zap v1.4.1
golang.org/x/net v0.0.0-20190311183353-d8887717615a // indirect
Expand Down
15 changes: 3 additions & 12 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,9 @@ github.com/armon/go-metrics v0.0.0-20180917152333-f0300d1749da h1:8GUt8eRujhVEGZ
github.com/armon/go-metrics v0.0.0-20180917152333-f0300d1749da/go.mod h1:Q73ZrmVTwzkszR9V5SSuryQ31EELlFMUz1kKyl939pY=
github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973 h1:xJ4a3vCFaGF/jqvzLMYoU8P317H5OQ+Via4RmuPwCS0=
github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24TaqPxmxbtue+5NUziq4I4S80YR8gNf3Q=
github.com/boltdb/bolt v1.3.1 h1:JQmyP4ZBrce+ZQu0dY660FMfatumYDLun9hBCUVIkF4=
github.com/boltdb/bolt v1.3.1/go.mod h1:clJnj/oiGkjum5o1McbSZDSLxVThjynRyGBgiAx27Ps=
github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw=
github.com/cockroachdb/cmux v0.0.0-20170110192607-30d10be49292 h1:dzj1/xcivGjNPwwifh/dWTczkwcuqsXXFHY1X/TZMtw=
github.com/cockroachdb/cmux v0.0.0-20170110192607-30d10be49292/go.mod h1:qRiX68mZX1lGBkTWyp3CLcenw9I94W2dLeRvMzcn9N4=
github.com/coreos/bbolt v1.3.0 h1:HIgH5xUWXT914HCI671AxuTTqjj64UOFr7pHn48LUTI=
github.com/coreos/bbolt v1.3.0/go.mod h1:iRUV2dpdMOn7Bo10OQBFzIJO9kkE559Wcmn+qkEiiKk=
github.com/coreos/bbolt v1.3.2 h1:wZwiHHUieZCquLkDL0B8UhzreNWsPHooDAG3q34zk0s=
github.com/coreos/bbolt v1.3.2/go.mod h1:iRUV2dpdMOn7Bo10OQBFzIJO9kkE559Wcmn+qkEiiKk=
github.com/coreos/etcd v3.2.11+incompatible h1:S3HFWk+1nkDWvYPJnWNNqi/dWnXJa3S3zQgFOycHbC8=
github.com/coreos/etcd v3.2.11+incompatible/go.mod h1:uF7uidLiAD3TWHmW31ZFd/JWoc32PjwdhPthX9715RE=
github.com/coreos/etcd v3.3.13+incompatible h1:8F3hqu9fGYLBifCmRCJsicFqDx/D68Rt3q1JMazcgBQ=
github.com/coreos/etcd v3.3.13+incompatible/go.mod h1:uF7uidLiAD3TWHmW31ZFd/JWoc32PjwdhPthX9715RE=
github.com/coreos/go-semver v0.0.0-20150725033620-d043ae190b32 h1:xJaHWjQvN5ZJj3p1xdeiDQd6W0wv50Gdd6bzSZcNKvk=
Expand Down Expand Up @@ -127,15 +119,14 @@ github.com/inconshreveable/mousetrap v1.0.0 h1:Z8tu5sraLXCXIcARxBp/8cbvlwVa7Z1NH
github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8=
github.com/jonboulle/clockwork v0.1.0 h1:VKV+ZcuP6l3yW9doeqz6ziZGgcynBVQO+obU0+0hcPo=
github.com/jonboulle/clockwork v0.1.0/go.mod h1:Ii8DK3G1RaLaWxj9trq07+26W01tbo22gdxWY5EU2bo=
github.com/json-iterator/go v0.0.0-20180128090011-28452fcdec4e h1:Dt5zqkK0PFBHYLNt+8OFuZRwDV4mOJWQA2FdLhd1rqU=
github.com/json-iterator/go v0.0.0-20180128090011-28452fcdec4e/go.mod h1:+SdeFBvtyEkXs7REEP0seUULqWtbJapLOCVDaaPEHmU=
github.com/json-iterator/go v1.1.6 h1:MrUvLMLTMxbqFJ9kzlvat/rYZqZnW3u4wkLzWTaFwKs=
github.com/json-iterator/go v1.1.6/go.mod h1:+SdeFBvtyEkXs7REEP0seUULqWtbJapLOCVDaaPEHmU=
github.com/juju/ratelimit v1.0.1 h1:+7AIFJVQ0EQgq/K9+0Krm7m530Du7tIz0METWzN0RgY=
github.com/juju/ratelimit v1.0.1/go.mod h1:qapgC/Gy+xNh9UxzV13HGGl/6UXNN+ct+vwSgWNm/qk=
github.com/julienschmidt/httprouter v1.2.0/go.mod h1:SYymIcj16QtmaHHD7aYtjjsJG7VTCxuUUipMqKk8s4w=
github.com/kballard/go-shellquote v0.0.0-20140719004912-e5c918b80c17 h1:u+orMffAJQdm1czF5Jx5JoYGIkH4HFmzX3OsloiSfWE=
github.com/kballard/go-shellquote v0.0.0-20140719004912-e5c918b80c17/go.mod h1:CzGEWj7cYgsdH8dAjBGEr58BoE7ScuLd+fwFZ44+/x8=
github.com/konsorten/go-windows-terminal-sequences v1.0.1 h1:mweAR1A6xJ3oS2pRaGiHgQ4OO8tzTaLawm8vnODuwDk=
github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
github.com/kr/logfmt v0.0.0-20140226030751-b84e30acd515/go.mod h1:+0opPa2QZZtGFBFZlji/RkVcI2GknAs/DXo4wKdlNEc=
github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI=
Expand Down Expand Up @@ -213,10 +204,10 @@ github.com/stretchr/testify v1.2.2 h1:bSDNvY7ZPG5RlJ8otE/7V6gMiyenm9RtJ7IUVIAoJ1
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
github.com/tmc/grpc-websocket-proxy v0.0.0-20190109142713-0ad062ec5ee5 h1:LnC5Kc/wtumK+WB441p7ynQJzVuNRJiqddSIE3IlSEQ=
github.com/tmc/grpc-websocket-proxy v0.0.0-20190109142713-0ad062ec5ee5/go.mod h1:ncp9v5uamzpCO7NfCPTXjqaC+bZgJeR0sMTm6dMHP7U=
github.com/ugorji/go v0.0.0-20151028022000-f1f1a805ed36 h1:vKlfv8sKDcjM5WIkcAzl5CZkKB8pppsrdmqczMTuapo=
github.com/ugorji/go v0.0.0-20151028022000-f1f1a805ed36/go.mod h1:hnLbHMwcvSihnDhEfx2/BzKp2xb0Y+ErdfYcrs9tkJQ=
github.com/xiang90/probing v0.0.0-20160813154853-07dd2e8dfe18 h1:MPPkRncZLN9Kh4MEFmbnK4h3BD7AUmskWv2+EeZJCCs=
github.com/xiang90/probing v0.0.0-20160813154853-07dd2e8dfe18/go.mod h1:UETIi67q53MR2AWcXfiuqkDkRtnGDLqkBTpCHuJHxtU=
go.etcd.io/bbolt v1.3.3 h1:MUGmc65QhB3pIlaQ5bB4LwqSj6GIonVJXpZiaKNyaKk=
go.etcd.io/bbolt v1.3.3/go.mod h1:IbVyRI1SCnLcuJnV2u8VeU0CEYM7e686BmAb1XKL+uU=
go.uber.org/atomic v1.3.1 h1:U8WaWEmp56LGz7PReduqHRVF6zzs9GbMC2NEZ42dxSQ=
go.uber.org/atomic v1.3.1/go.mod h1:gD2HeocX3+yG+ygLZcrzQJaqmWj9AIm7n08wl/qW/PE=
go.uber.org/zap v1.4.1 h1:SNpwY112Mv6x3CAt0P9fKKXYIec9Ocx34g5+iP/uzas=
Expand Down
4 changes: 2 additions & 2 deletions internal/cluster/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -561,8 +561,8 @@ type KeeperStatus struct {

ForceFail bool `json:"forceFail,omitempty"`

NeverMaster bool `json:"neverMaster,omitempty"`
NeverSynchronousReplica bool `json:"neverSynchronousReplica,omitempty"`
CanBeMaster *bool `json:"canBeMaster,omitempty"`
CanBeSynchronousReplica *bool `json:"canBeSynchronousReplica,omitempty"`
}

type Keeper struct {
Expand Down
4 changes: 2 additions & 2 deletions internal/cluster/member.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ type KeeperInfo struct {

PostgresState *PostgresState `json:"postgresState,omitempty"`

NeverMaster bool `json:"neverMaster,omitempty"`
NeverSynchronousReplica bool `json:"neverSynchronousReplica,omitempty"`
CanBeMaster *bool `json:"canBeMaster,omitempty"`
CanBeSynchronousReplica *bool `json:"canBeSynchronousReplica,omitempty"`
}

func (k *KeeperInfo) DeepCopy() *KeeperInfo {
Expand Down

0 comments on commit a978806

Please sign in to comment.