@@ -52,14 +52,14 @@ type partitionDeadlockDetector struct {
52
52
closePartition chan struct {}
53
53
done chan struct {}
54
54
incrementAllPartitionMsgCount func ()
55
- closed bool
55
+ disabled bool
56
56
}
57
57
58
58
type allPartitionsDeadlockDetector struct {
59
59
msgConsumed * uint64
60
60
logger * zap.Logger
61
61
done chan struct {}
62
- closed bool
62
+ disabled bool
63
63
}
64
64
65
65
func newDeadlockDetector (metricsFactory metrics.Factory , logger * zap.Logger , interval time.Duration ) deadlockDetector {
@@ -84,12 +84,10 @@ func newDeadlockDetector(metricsFactory metrics.Factory, logger *zap.Logger, int
84
84
func (s * deadlockDetector ) startMonitoringForPartition (partition int32 ) * partitionDeadlockDetector {
85
85
var msgConsumed uint64
86
86
w := & partitionDeadlockDetector {
87
- msgConsumed : & msgConsumed ,
88
- partition : partition ,
89
- closePartition : make (chan struct {}, 1 ),
90
- done : make (chan struct {}),
91
- logger : s .logger ,
92
- closed : false ,
87
+ msgConsumed : & msgConsumed ,
88
+ partition : partition ,
89
+ logger : s .logger ,
90
+ disabled : 0 == s .interval ,
93
91
94
92
incrementAllPartitionMsgCount : func () {
95
93
s .allPartitionsDeadlockDetector .incrementMsgCount ()
@@ -98,8 +96,9 @@ func (s *deadlockDetector) startMonitoringForPartition(partition int32) *partiti
98
96
99
97
if s .interval == 0 {
100
98
s .logger .Debug ("Partition deadlock detector disabled" )
101
- w .closed = true
102
99
} else {
100
+ w .closePartition = make (chan struct {}, 1 )
101
+ w .done = make (chan struct {})
103
102
go s .monitorForPartition (w , partition )
104
103
}
105
104
@@ -141,16 +140,15 @@ func (s *deadlockDetector) start() {
141
140
var msgConsumed uint64
142
141
detector := & allPartitionsDeadlockDetector {
143
142
msgConsumed : & msgConsumed ,
144
- done : make (chan struct {}),
145
143
logger : s .logger ,
146
- closed : false ,
144
+ disabled : 0 == s . interval ,
147
145
}
148
146
149
147
if s .interval == 0 {
150
148
s .logger .Debug ("Global deadlock detector disabled" )
151
- detector .closed = true
152
149
} else {
153
150
s .logger .Debug ("Starting global deadlock detector" )
151
+ detector .done = make (chan struct {})
154
152
go func () {
155
153
ticker := time .NewTicker (s .interval )
156
154
defer ticker .Stop ()
@@ -175,34 +173,39 @@ func (s *deadlockDetector) start() {
175
173
}
176
174
177
175
func (s * deadlockDetector ) close () {
178
- if ! s .allPartitionsDeadlockDetector .closed {
179
- s .logger .Debug ("Closing all partitions deadlock detector" )
180
- s .allPartitionsDeadlockDetector .closed = true
181
- s .allPartitionsDeadlockDetector .done <- struct {}{}
182
- } else {
183
- s .logger .Debug ("All partitions deadlock detector already closed" )
176
+ if s .allPartitionsDeadlockDetector .disabled {
177
+ return
184
178
}
179
+ s .logger .Debug ("Closing all partitions deadlock detector" )
180
+ s .allPartitionsDeadlockDetector .done <- struct {}{}
185
181
}
186
182
187
183
func (s * allPartitionsDeadlockDetector ) incrementMsgCount () {
184
+ if s .disabled {
185
+ return
186
+ }
188
187
atomic .AddUint64 (s .msgConsumed , 1 )
189
188
}
190
189
191
190
func (w * partitionDeadlockDetector ) closePartitionChannel () chan struct {} {
191
+ if w .disabled {
192
+ return nil
193
+ }
192
194
return w .closePartition
193
195
}
194
196
195
197
func (w * partitionDeadlockDetector ) close () {
196
- if ! w .closed {
197
- w .logger .Debug ("Closing deadlock detector" , zap .Int32 ("partition" , w .partition ))
198
- w .closed = true
199
- w .done <- struct {}{}
200
- } else {
201
- w .logger .Debug ("Deadlock detector already closed" , zap .Int32 ("partition" , w .partition ))
198
+ if w .disabled {
199
+ return
202
200
}
201
+ w .logger .Debug ("Closing deadlock detector" , zap .Int32 ("partition" , w .partition ))
202
+ w .done <- struct {}{}
203
203
}
204
204
205
205
func (w * partitionDeadlockDetector ) incrementMsgCount () {
206
+ if w .disabled {
207
+ return
208
+ }
206
209
w .incrementAllPartitionMsgCount ()
207
210
atomic .AddUint64 (w .msgConsumed , 1 )
208
211
}
0 commit comments