@@ -28,13 +28,14 @@ func (rc *resec) start() {
28
28
return
29
29
}
30
30
31
- log .Printf ("[DEBUG] Got redis replication status update: \n %s" , update . output )
31
+ log .Printf ("[DEBUG] Got redis replication info update" )
32
32
33
33
if rc .consul .healthy {
34
34
// if we don't have any check id, we haven't registered our service yet
35
35
// let's do that first
36
36
if rc .redis .replicationStatus != "" {
37
37
if rc .consul .checkID == "" {
38
+ log .Printf ("[DEBUG] Consul Check ID is not generated" )
38
39
rc .registerService ()
39
40
}
40
41
@@ -51,6 +52,8 @@ func (rc *resec) start() {
51
52
rc .handleConsulError (err )
52
53
log .Printf ("[ERROR] Failed to update consul Check TTL - %s" , err )
53
54
}
55
+ } else {
56
+ log .Printf ("[DEBUG] Redis replication status is not defined" )
54
57
}
55
58
} else {
56
59
log .Printf ("[INFO] Consul is not healthy, skipping service check update" )
@@ -66,21 +69,19 @@ func (rc *resec) start() {
66
69
// our state is now unhealthy, release the consul lock so someone else can
67
70
// acquire the consul leadership and become redis master
68
71
if ! update .healthy {
69
- log .Printf ("[INFO] Redis replication status changed to NOT healthy" )
72
+ log .Printf ("[INFO] Redis status changed to NOT healthy" )
70
73
rc .releaseConsulLock ()
71
74
continue
72
75
}
73
76
74
- log .Printf ("[INFO] Redis replication status changed to healthy" )
75
- if rc .redis .replicationStatus == "slave " {
77
+ log .Printf ("[INFO] Redis status changed to healthy" )
78
+ if rc .redis .replicationStatus != "master " {
76
79
if err := rc .runAsSlave (rc .lastKnownMasterInfo .address , rc .lastKnownMasterInfo .port ); err != nil {
77
80
log .Println (err )
78
81
continue
79
82
}
80
83
}
81
84
82
- go rc .acquireConsulLeadership ()
83
-
84
85
case update , ok := <- rc .consulMasterServiceCh :
85
86
if ! ok {
86
87
log .Printf ("[ERROR] Consul master service channel was closed, shutting down" )
@@ -99,7 +100,7 @@ func (rc *resec) start() {
99
100
go rc .acquireConsulLeadership ()
100
101
continue
101
102
}
102
- log .Printf ("[DEBUG] Redis is not healthy, nothing to do here" )
103
+ log .Printf ("[DEBUG] No Master found in consul, but redis is not healthy, nothing to do here" )
103
104
104
105
// multiple masters is not good
105
106
case masterCount > 1 :
@@ -126,21 +127,13 @@ func (rc *resec) start() {
126
127
127
128
// todo(jippi): if we can't enslave our redis, we shouldn't try to do any further work
128
129
// especially not updating our consul catalog entry
129
- if err := rc .runAsSlave (rc .lastKnownMasterInfo .address , rc .lastKnownMasterInfo .port ); err != nil {
130
- log .Println (err )
130
+ if ! rc .redis .healthy {
131
131
continue
132
132
}
133
-
134
- // change our internal state to being a slave
135
- rc .redis .replicationStatus = "slave"
136
- if err := rc .registerService (); err != nil {
137
- log .Printf ("[ERROR] Consul Service registration failed - %s" , err )
133
+ if err := rc .runAsSlave (rc .lastKnownMasterInfo .address , rc .lastKnownMasterInfo .port ); err != nil {
134
+ log .Println (err )
138
135
continue
139
136
}
140
-
141
- // if we are enslaved and our status is published in consul, lets go back to trying
142
- // to acquire leadership / master role as well
143
- go rc .acquireConsulLeadership ()
144
137
}
145
138
146
139
// if our consul lock status has changed
@@ -173,8 +166,9 @@ func (rc *resec) start() {
173
166
log .Printf ("[ERROR] %s" , update .err )
174
167
rc .handleConsulError (update .err )
175
168
169
+
176
170
if ! rc .consul .healthy {
177
- return
171
+ continue
178
172
}
179
173
180
174
if rc .redis .replicationStatus == "master" {
0 commit comments