pbacsko commented on code in PR #579:
URL: https://github.com/apache/yunikorn-core/pull/579#discussion_r1276097584
##########
pkg/events/event_ringbuffer.go:
##########
@@ -199,3 +199,41 @@ func newEventRingBuffer(capacity uint64) *eventRingBuffer {
events: make([]*si.EventRecord, capacity),
}
}
+
+// resize the existing ring buffer
+// this method will be called upon configuration reload
+func (e *eventRingBuffer) Resize(newSize uint64) {
+ e.Lock()
+ defer e.Unlock()
+
+ if newSize == e.capacity {
+ return // Nothing to do if the size is the same
+ }
+
+ // Create a new buffer with the desired size
+ newEvents := make([]*si.EventRecord, newSize)
+
+ // Determine the number of events to copy
+ numEventsToCopy := newSize
+ if newSize > e.capacity {
+ numEventsToCopy = e.capacity
+ }
+
+ // Copy existing events to the new buffer:
+ // We determine the range of elements to copy based on the relative
positions of the head and tail in the circular buffer.
+ // If the tail is ahead of the head (wrap-around scenario), we copy in
two steps to ensure the correct order.
+ startIndex := e.head
+ endIndex := (e.head + numEventsToCopy - 1) % e.capacity
+ if endIndex >= startIndex {
Review Comment:
Cover all cases:
* end < start
* end = start
* end > start
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]