-
Notifications
You must be signed in to change notification settings - Fork 950
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
bugfix: make ringbuffer right #1558
bugfix: make ringbuffer right #1558
Conversation
CRI tools validation fails:
ping @YaoZengzeng @starnop |
Codecov Report
@@ Coverage Diff @@
## master #1558 +/- ##
==========================================
- Coverage 41.59% 40.85% -0.74%
==========================================
Files 267 268 +1
Lines 17366 17778 +412
==========================================
+ Hits 7223 7264 +41
- Misses 9251 9618 +367
- Partials 892 896 +4
|
pkg/ringbuffer/list.go
Outdated
elem.val = val | ||
|
||
at := q.root.prev | ||
n := at.next |
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.
why we need this local var n, isn't it always q.root?
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 will make it clear.
LGTM, @yyb196 @HusterWan May review this PR more in detail 😄 |
As the original design says, the ringbuffer uses two pointer to represent push and pop position respectively in the circle list. The ringbuffer allows to override oldest data if the buffer is full. However, the Close action will be hang if the push pointer doesn't equal to pop pointer. Please check the case. ``` E = empty, H = has data At this time, the circle has full buffer, which means each node contains the data. 0H -> 1H -> 2H -> 3H -> 4H -> 0H ^ ^ | | | push pointer pop pointer In the following goroutine scheduled, the pop action will consume all the data. 0E -> 1E -> 2E -> 3E -> 4E -> 0E ^ ^ | | | push pointer pop pointer However, if there are not enough data to make the push pointer equals to the pop pointer, the Close action will be hang. ``` In order to make the ringbuffer right, use FIFO queue to as buffer. The front pointer contains the oldest data. When the buffer is full and there is new data coming, the ringbuffer can drop the front one and push new data into the back. However, the ringbuffer still contains the data after closed. The containerio should drain all the data and write it into the backend. Signed-off-by: Wei Fu <fhfuwei@163.com>
@yyb196 I have updated the code. Please take a look. cc @YaoZengzeng |
elem := elemPool.Get().(*element) | ||
elem.val = val | ||
|
||
at := q.root.prev |
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.
rename at to last or tail, it may more clear
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.
Hi @shaloulcy , the q.root.prev
means the tail or last. at
means the position. I think we can keep it here.
return nil | ||
} | ||
|
||
at := q.root.next |
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.
rename at to first or head, it may more clear
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.
Please check the last comment
@yyb196 @shaloulcy any comments? 😄 |
LGTM |
Signed-off-by: Wei Fu fhfuwei@163.com
Ⅰ. Describe what this PR did
Make ringbuffer right
Ⅱ. Does this pull request fix one issue?
NONE
Ⅲ. Describe how you did it
As the original design says, the ringbuffer uses two pointer to represent
push and pop position respectively in the circle list. The ringbuffer
allows to override oldest data if the buffer is full.
However, the Close action will be hang if the push pointer doesn't equal to
pop pointer. Please check the case.
In order to make the ringbuffer right, use FIFO queue to as buffer. The
front pointer contains the oldest data. When the buffer is full and
there is new data coming, the ringbuffer can drop the front one and push
new data into the back.
However, the ringbuffer still contains the data after closed. The
containerio should drain all the data and write it into the backend.
Ⅳ. Describe how to verify it
It should be closed successfully.
Ⅴ. Special notes for reviews
The ringbuffer means non-blocked IO, which loss the data if the consumer pops slowly.
Next action: