@@ -49,6 +49,7 @@ func (mc *MetricsCache) metricFeed(index int) {
49
49
inFlight := 0
50
50
gotData := false
51
51
gotCompletion := false
52
+ potentialCompletion := false
52
53
var completeChan chan int
53
54
54
55
for {
@@ -61,11 +62,16 @@ func (mc *MetricsCache) metricFeed(index int) {
61
62
mc .logger .Debug (`Complete update cycle - "in-flight requests"=%d; "metric queue length"=%d\n` , inFlight , length )
62
63
63
64
// If data was sent and the queue is empty, mark as completion
64
- if length == 0 && gotData && len (mc .asyncAppendChan ) == 0 {
65
- gotCompletion = true
66
- if completeChan != nil {
67
- completeChan <- 0
68
- gotData = false
65
+ if length == 0 && gotData {
66
+ if len (mc .asyncAppendChan ) == 0 {
67
+ gotCompletion = true
68
+ if completeChan != nil {
69
+ completeChan <- 0
70
+ gotData = false
71
+ potentialCompletion = false
72
+ }
73
+ } else if len (mc .asyncAppendChan ) == 1 {
74
+ potentialCompletion = true
69
75
}
70
76
}
71
77
case app := <- mc .asyncAppendChan :
@@ -77,14 +83,17 @@ func (mc *MetricsCache) metricFeed(index int) {
77
83
if app .metric == nil {
78
84
// Handle update completion requests (metric == nil)
79
85
completeChan = app .resp
80
-
81
86
length := mc .metricQueue .Length ()
82
- if gotCompletion && length == 0 && len (mc .asyncAppendChan ) == 0 {
83
- completeChan <- 0
84
- gotCompletion = false
85
- gotData = false
87
+ if length == 0 && len (mc .asyncAppendChan ) == 0 {
88
+ if gotCompletion || (potentialCompletion && gotData ) {
89
+ completeChan <- 0
90
+ gotCompletion = false
91
+ gotData = false
92
+ }
86
93
}
94
+ potentialCompletion = false
87
95
} else {
96
+ potentialCompletion = false
88
97
// Handle append requests (Add / AddFast)
89
98
gotData = true
90
99
metric := app .metric
@@ -113,7 +122,6 @@ func (mc *MetricsCache) metricFeed(index int) {
113
122
}
114
123
metric .Unlock ()
115
124
}
116
-
117
125
// Poll if we have more updates (accelerate the outer select)
118
126
if i < mc .cfg .BatchSize {
119
127
select {
@@ -249,8 +257,14 @@ func (mc *MetricsCache) postMetricUpdates(metric *MetricState) {
249
257
} else if sent {
250
258
metric .setState (storeStateUpdate )
251
259
}
252
- if ! sent && metric .store .samplesQueueLength () == 0 {
253
- metric .setState (storeStateReady )
260
+ if ! sent {
261
+ if metric .store .samplesQueueLength () == 0 {
262
+ metric .setState (storeStateReady )
263
+ } else {
264
+ if mc .metricQueue .length () > 0 {
265
+ mc .newUpdates <- mc .metricQueue .length ()
266
+ }
267
+ }
254
268
}
255
269
}
256
270
0 commit comments