You signed in with another tab or window.Reload to refresh your session.You signed out in another tab or window.Reload to refresh your session.You switched accounts on another tab or window.Reload to refresh your session.Dismiss alert
Sentinel will promote keeper with higher priority than the current one if thisis possible. In async mode this is a bit non-deterministic because we alwayselect node with highest LSN, and under heavy load prioritized node might neverreport LSN higher than its stronger competitors. However, if nodes are equalthis should happen at some moment. In sync mode, we can just elect any ofsynchronous standbies.Priority can be set during keeper start (--priority) or later with new command'stolonctl set keeperpriority'. The latter allows to update priority withoutrestarting the keeper (and its Postgres instance), which can be used forcontrolled failover.Implementssorintlab#492
Copy file name to clipboardExpand all lines: cmd/keeper/cmd/keeper.go
+16Lines changed: 16 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -99,6 +99,8 @@ type config struct {
99
99
uidstring
100
100
dataDirstring
101
101
debugbool
102
+
priorityint
103
+
prioritySpecifiedbool// true iff explicitly set by user
102
104
pgListenAddressstring
103
105
pgAdvertiseAddressstring
104
106
pgPortstring
@@ -139,6 +141,7 @@ func init() {
139
141
CmdKeeper.PersistentFlags().StringVar(&cfg.pgSUPassword,"pg-su-password","","postgres superuser password. Only one of --pg-su-password or --pg-su-passwordfile must be provided. Must be the same for all keepers.")
140
142
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().IntVar(&cfg.priority,"priority",0,"keeper priority, integer. Stolon will promote available keeper with higher priority than current master, if this is possible. Healthy keeper with higher priority will be elected even if current master is online. If not specified, priority is set to "+strconv.Itoa(cluster.DefaultPriority)+" on first keeper invocation; on subsequent invocations, last value (which could be also set with 'stolonctl setkeeperpriority') is reused.")
142
145
143
146
CmdKeeper.PersistentFlags().BoolVar(&cfg.canBeMaster,"can-be-master",true,"prevent keeper from being elected as master")
144
147
CmdKeeper.PersistentFlags().BoolVar(&cfg.canBeSynchronousReplica,"can-be-synchronous-replica",true,"prevent keeper from being chosen as synchronous replica")
log.Warnw("cannot choose synchronous standby since there are no common elements between the latest master reported synchronous standbys and the db spec ones","reported",curMasterDB.Status.SynchronousStandbys,"spec",curMasterDB.Spec.SynchronousStandbys)
809
+
}
810
+
returnnil
811
+
}
812
+
// In synchronous mode there is no need to choose DB with
813
+
// highest LSN; all found dbs must be in sync, so pick the one
if (bestNewMasterDB==nil)|| (nmPriority>newMasterPriority) {
820
+
bestNewMasterDB=nm
821
+
newMasterPriority=nmPriority
822
+
}
823
+
}
824
+
}
825
+
ifbestNewMasterDB==nil&&logErrors {
826
+
log.Warnw("cannot choose synchronous standby since there's not match between the possible masters and the usable synchronousStandbys","reported",curMasterDB.Status.SynchronousStandbys,"spec",curMasterDB.Spec.SynchronousStandbys,"common",commonSyncStandbys,"possibleMasters",bestNewMasters)
log.Warnw("cannot choose synchronous standby since there are no common elements between the latest master reported synchronous standbys and the db spec ones","reported",curMasterDB.Status.SynchronousStandbys,"spec",curMasterDB.Spec.SynchronousStandbys)
1017
-
}else {
1018
-
for_,nm:=rangebestNewMasters {
1019
-
ifutil.StringInSlice(commonSyncStandbys,nm.UID) {
1020
-
bestNewMasterDB=nm
1021
-
break
1022
-
}
1023
-
}
1024
-
ifbestNewMasterDB==nil {
1025
-
log.Warnw("cannot choose synchronous standby since there's not match between the possible masters and the usable synchronousStandbys","reported",curMasterDB.Status.SynchronousStandbys,"spec",curMasterDB.Spec.SynchronousStandbys,"common",commonSyncStandbys,"possibleMasters",bestNewMasters)
1026
-
}
1027
-
}
1028
-
}else {
1029
-
bestNewMasterDB=bestNewMasters[0]
1030
-
}
1031
-
ifbestNewMasterDB!=nil {
1032
-
log.Infow("electing db as the new master","db",bestNewMasterDB.UID,"keeper",bestNewMasterDB.Spec.KeeperUID)
1064
+
// Even if current master is ok, we probably still
1065
+
// want to change it if there is ready DB with higher
log.Infow("electing db as the new master because it has higher priority","db",bestNewMasterDB.UID,"keeper",bestNewMasterDB.Spec.KeeperUID,"currPriority",curMasterPriority,"newPriority",newMasterPriority)