-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
[chore][exporter] Consolidate merge splitting for the case where maxLimit is set and the case it's not #12104
base: main
Are you sure you want to change the base?
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 |
---|---|---|
|
@@ -43,77 +43,41 @@ func (qb *DefaultBatcher) startReadingFlushingGoroutine() { | |
|
||
qb.currentBatchMu.Lock() | ||
|
||
if qb.batchCfg.MaxSizeItems > 0 { | ||
var reqList []internal.Request | ||
var mergeSplitErr error | ||
if qb.currentBatch == nil || qb.currentBatch.req == nil { | ||
qb.resetTimer() | ||
reqList, mergeSplitErr = req.MergeSplit(ctx, qb.batchCfg.MaxSizeConfig, nil) | ||
} else { | ||
reqList, mergeSplitErr = qb.currentBatch.req.MergeSplit(ctx, qb.batchCfg.MaxSizeConfig, req) | ||
} | ||
var reqList []internal.Request | ||
var mergeSplitErr error | ||
if qb.currentBatch == nil || qb.currentBatch.req == nil { | ||
qb.resetTimer() | ||
reqList, mergeSplitErr = req.MergeSplit(ctx, qb.batchCfg.MaxSizeConfig, nil) | ||
} else { | ||
reqList, mergeSplitErr = qb.currentBatch.req.MergeSplit(ctx, qb.batchCfg.MaxSizeConfig, req) | ||
} | ||
|
||
if mergeSplitErr != nil || reqList == nil { | ||
qb.queue.OnProcessingFinished(idx, mergeSplitErr) | ||
qb.currentBatchMu.Unlock() | ||
continue | ||
} | ||
if mergeSplitErr != nil || reqList == nil { | ||
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. A slice never compare to nil, you must most likely compare len to 0 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. Hmmm. In Go a slice can be nil and the comparison is valid. Note however that |
||
qb.queue.OnProcessingFinished(idx, mergeSplitErr) | ||
qb.currentBatchMu.Unlock() | ||
continue | ||
} | ||
|
||
// If there was a split, we flush everything immediately. | ||
if reqList[0].ItemsCount() >= qb.batchCfg.MinSizeItems || len(reqList) > 1 { | ||
qb.currentBatch = nil | ||
qb.currentBatchMu.Unlock() | ||
for i := 0; i < len(reqList); i++ { | ||
qb.flush(batch{ | ||
req: reqList[i], | ||
ctx: ctx, | ||
idxList: []uint64{idx}, | ||
}) | ||
// TODO: handle partial failure | ||
} | ||
qb.resetTimer() | ||
} else { | ||
qb.currentBatch = &batch{ | ||
req: reqList[0], | ||
// If there was a split, we flush everything immediately. | ||
if reqList[0].ItemsCount() >= qb.batchCfg.MinSizeItems || len(reqList) > 1 { | ||
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. What if len is 0, get a segfault here? |
||
qb.currentBatch = nil | ||
qb.currentBatchMu.Unlock() | ||
for i := 0; i < len(reqList); i++ { | ||
qb.flush(batch{ | ||
req: reqList[i], | ||
ctx: ctx, | ||
idxList: []uint64{idx}, | ||
} | ||
qb.currentBatchMu.Unlock() | ||
}) | ||
// TODO: handle partial failure | ||
} | ||
qb.resetTimer() | ||
} else { | ||
if qb.currentBatch == nil || qb.currentBatch.req == nil { | ||
qb.resetTimer() | ||
qb.currentBatch = &batch{ | ||
req: req, | ||
ctx: ctx, | ||
idxList: []uint64{idx}, | ||
} | ||
} else { | ||
// TODO: consolidate implementation for the cases where MaxSizeConfig is specified and the case where it is not specified | ||
mergedReq, mergeErr := qb.currentBatch.req.MergeSplit(qb.currentBatch.ctx, qb.batchCfg.MaxSizeConfig, req) | ||
if mergeErr != nil { | ||
qb.queue.OnProcessingFinished(idx, mergeErr) | ||
qb.currentBatchMu.Unlock() | ||
continue | ||
} | ||
qb.currentBatch = &batch{ | ||
req: mergedReq[0], | ||
ctx: qb.currentBatch.ctx, | ||
idxList: append(qb.currentBatch.idxList, idx), | ||
} | ||
} | ||
|
||
if qb.currentBatch.req.ItemsCount() >= qb.batchCfg.MinSizeItems { | ||
batchToFlush := *qb.currentBatch | ||
qb.currentBatch = nil | ||
qb.currentBatchMu.Unlock() | ||
|
||
// flush() blocks until successfully started a goroutine for flushing. | ||
qb.flush(batchToFlush) | ||
qb.resetTimer() | ||
} else { | ||
qb.currentBatchMu.Unlock() | ||
qb.currentBatch = &batch{ | ||
req: reqList[0], | ||
ctx: ctx, | ||
idxList: []uint64{idx}, | ||
} | ||
qb.currentBatchMu.Unlock() | ||
} | ||
} | ||
}() | ||
|
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.
Not sure you want to do anything if error, unless I am missing something.