mirror of https://github.com/tidwall/tile38.git
Issue #642 - Expose config and INFO response for slave_priority
This commit is contained in:
parent
37407f01bc
commit
2be07e4762
|
@ -25,6 +25,7 @@ const (
|
|||
FollowPort = "follow_port"
|
||||
FollowID = "follow_id"
|
||||
FollowPos = "follow_pos"
|
||||
SlavePriority = "slave_priority"
|
||||
ServerID = "server_id"
|
||||
ReadOnly = "read_only"
|
||||
RequirePass = "requirepass"
|
||||
|
@ -44,12 +45,13 @@ type Config struct {
|
|||
|
||||
mu sync.RWMutex
|
||||
|
||||
_followHost string
|
||||
_followPort int64
|
||||
_followID string
|
||||
_followPos int64
|
||||
_serverID string
|
||||
_readOnly bool
|
||||
_followHost string
|
||||
_followPort int64
|
||||
_followID string
|
||||
_followPos int64
|
||||
_slavePriority int64
|
||||
_serverID string
|
||||
_readOnly bool
|
||||
|
||||
_requirePassP string
|
||||
_requirePass string
|
||||
|
@ -99,6 +101,15 @@ func loadConfig(path string) (*Config, error) {
|
|||
config._serverID = randomKey(16)
|
||||
}
|
||||
|
||||
// Need to be sure we look for existence vs not zero because zero is an intentional setting
|
||||
// anything less than zero will be considered default and will result in no slave_priority
|
||||
// being output when INFO is called.
|
||||
if gjson.Get(json, SlavePriority).Exists() {
|
||||
config._slavePriority = gjson.Get(json, SlavePriority).Int()
|
||||
} else {
|
||||
config._slavePriority = -1
|
||||
}
|
||||
|
||||
// load properties
|
||||
if err := config.setProperty(RequirePass, config._requirePassP, true); err != nil {
|
||||
return nil, err
|
||||
|
@ -167,6 +178,9 @@ func (config *Config) write(writeProperties bool) {
|
|||
if config._followPos != 0 {
|
||||
m[FollowPos] = config._followPos
|
||||
}
|
||||
if config._slavePriority >= 0 {
|
||||
m[SlavePriority] = config._slavePriority
|
||||
}
|
||||
if config._serverID != "" {
|
||||
m[ServerID] = config._serverID
|
||||
}
|
||||
|
@ -426,6 +440,12 @@ func (config *Config) followPort() int {
|
|||
config.mu.RUnlock()
|
||||
return int(v)
|
||||
}
|
||||
func (config *Config) slavePriority() int {
|
||||
config.mu.RLock()
|
||||
v := config._slavePriority
|
||||
config.mu.RUnlock()
|
||||
return int(v)
|
||||
}
|
||||
func (config *Config) serverID() string {
|
||||
config.mu.RLock()
|
||||
v := config._serverID
|
||||
|
|
|
@ -408,6 +408,9 @@ func (s *Server) writeInfoReplication(w *bytes.Buffer) {
|
|||
fmt.Fprintf(w, "role:slave\r\n")
|
||||
fmt.Fprintf(w, "master_host:%s\r\n", s.config.followHost())
|
||||
fmt.Fprintf(w, "master_port:%v\r\n", s.config.followPort())
|
||||
if s.config.slavePriority() >= 0 {
|
||||
fmt.Fprintf(w, "slave_priority:%v\r\n", s.config.slavePriority())
|
||||
}
|
||||
} else {
|
||||
fmt.Fprintf(w, "role:master\r\n")
|
||||
var i int
|
||||
|
|
Loading…
Reference in New Issue