-
Notifications
You must be signed in to change notification settings - Fork 4.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix duplicate batches in retry queue #5520
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -107,15 +107,7 @@ func (c *asyncClient) AsyncPublishEvents( | |
return nil | ||
} | ||
|
||
ref := &msgRef{ | ||
client: c, | ||
count: 1, | ||
batch: data, | ||
batchSize: len(data), | ||
win: c.win, | ||
cb: cb, | ||
err: nil, | ||
} | ||
ref := newMsgRef(c, data, cb) | ||
defer ref.dec() | ||
|
||
for len(data) > 0 { | ||
|
@@ -171,7 +163,7 @@ func (c *asyncClient) sendEvents(ref *msgRef, data []outputs.Data) error { | |
for i, d := range data { | ||
window[i] = d | ||
} | ||
atomic.AddInt32(&ref.count, 1) | ||
ref.inc() | ||
return c.client.Send(ref.callback, window) | ||
} | ||
|
||
|
@@ -183,7 +175,33 @@ func (r *msgRef) callback(seq uint32, err error) { | |
} | ||
} | ||
|
||
func newMsgRef( | ||
client *asyncClient, | ||
data []outputs.Data, | ||
cb func([]outputs.Data, error), | ||
) *msgRef { | ||
r := &msgRef{ | ||
client: client, | ||
count: 1, | ||
batch: data, | ||
batchSize: len(data), | ||
win: client.win, | ||
cb: cb, | ||
err: nil, | ||
} | ||
|
||
debug("msgref(%p) new: batch=%p, cb=%p", r, &r.batch[0], cb) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This will create a lot of debug messages. I know that this info is for debugging, but I start to get the feeling we need something in between There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, some extra-debug would be nice to have. Normally the debug messages create about 4 new debug messages per batch (2048) events. Not too bad, but super helpful to identify potential issues, should we still face some problems. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Feel more like a |
||
return r | ||
} | ||
|
||
func (r *msgRef) inc() { | ||
count := atomic.AddInt32(&r.count, 1) | ||
debug("msgref(%p) inc -> %v", r, count) | ||
} | ||
|
||
func (r *msgRef) done(n uint32) { | ||
debug("msgref(%p) done(%v)", r, n) | ||
|
||
ackedEvents.Add(int64(n)) | ||
r.batch = r.batch[n:] | ||
if r.win != nil { | ||
|
@@ -193,6 +211,8 @@ func (r *msgRef) done(n uint32) { | |
} | ||
|
||
func (r *msgRef) fail(n uint32, err error) { | ||
debug("msgref(%p) fail(%v, %v)", r, n, err) | ||
|
||
ackedEvents.Add(int64(n)) | ||
if r.err == nil { | ||
r.err = err | ||
|
@@ -206,6 +226,7 @@ func (r *msgRef) fail(n uint32, err error) { | |
|
||
func (r *msgRef) dec() { | ||
i := atomic.AddInt32(&r.count, -1) | ||
debug("msgref(%p) dec -> %v", r, i) | ||
if i > 0 { | ||
return | ||
} | ||
|
@@ -214,9 +235,11 @@ func (r *msgRef) dec() { | |
if err != nil { | ||
eventsNotAcked.Add(int64(len(r.batch))) | ||
logp.Err("Failed to publish events (host: %v) caused by: %v", r.client.host, err) | ||
debug("msgref(%p) exec callback(%p, %v)", r, &r.batch[0], err) | ||
r.cb(r.batch, err) | ||
return | ||
} | ||
|
||
debug("msgref(%p) exec callback(nil, nil)", r) | ||
r.cb(nil, nil) | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -111,25 +111,10 @@ func (w *asyncWorker) sendLoop() (done bool) { | |
} | ||
|
||
func (w *asyncWorker) onMessage(msg eventsMessage) error { | ||
var err error | ||
if msg.datum.Event != nil { | ||
err = w.client.AsyncPublishEvent(w.handleResult(msg), msg.datum) | ||
} else { | ||
err = w.client.AsyncPublishEvents(w.handleResults(msg), msg.data) | ||
return w.client.AsyncPublishEvent(w.handleResult(msg), msg.datum) | ||
} | ||
|
||
if err != nil { | ||
if msg.attemptsLeft > 0 { | ||
msg.attemptsLeft-- | ||
} | ||
|
||
// asynchronously retry to insert message (if attempts left), so worker can not | ||
// deadlock on retries channel if client puts multiple failed outstanding | ||
// events into the pipeline | ||
w.onFail(msg, err) | ||
} | ||
|
||
return err | ||
return w.client.AsyncPublishEvents(w.handleResults(msg), msg.data) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Change in semantics is here. We always require the |
||
} | ||
|
||
func (w *asyncWorker) handleResult(msg eventsMessage) func(error) { | ||
|
@@ -193,7 +178,7 @@ func (w *asyncWorker) handleResults(msg eventsMessage) func([]outputs.Data, erro | |
} | ||
|
||
// all events published -> signal success | ||
debugf("async bulk publish success") | ||
debugf("async bulk publish success (signaler=%v)", msg.signaler) | ||
op.SigCompleted(msg.signaler) | ||
} | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would probably mention deadlock, duplicates can be seen in other scenario.