Skip to content

Commit 8bc19bc

Browse files
Fix updating gaps code
When cleaning up gaps the case that a gaps start date can become older than the oldest stored value in the buffer wasn't covered. Furthermore the cases for cleaning up a single gap didn't run for the last gaps, since the loop was stopping too early. Signed-off-by: Matthias Wende <[email protected]>
1 parent 1d45fc9 commit 8bc19bc

File tree

1 file changed

+11
-4
lines changed
  • src/frequenz/sdk/timeseries/_ringbuffer

1 file changed

+11
-4
lines changed

src/frequenz/sdk/timeseries/_ringbuffer/buffer.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -328,17 +328,24 @@ def _cleanup_gaps(self) -> None:
328328
self._gaps = sorted(self._gaps, key=lambda x: x.start.timestamp())
329329

330330
i = 0
331-
while i < len(self._gaps) - 1:
331+
while i < len(self._gaps):
332332
w_1 = self._gaps[i]
333-
w_2 = self._gaps[i + 1]
333+
if i < len(self._gaps) - 1:
334+
w_2 = self._gaps[i + 1]
335+
else:
336+
w_2 = None
337+
334338
# Delete out-of-date gaps
335339
if w_1.end <= self._datetime_oldest:
336340
del self._gaps[i]
341+
# Update start of gap if it's rolled out of the buffer
342+
elif w_1.start < self._datetime_oldest:
343+
self._gaps[i].start = self._datetime_oldest
337344
# If w2 is a subset of w1 we can delete it
338-
elif w_1.start <= w_2.start and w_1.end >= w_2.end:
345+
elif w_2 and w_1.start <= w_2.start and w_1.end >= w_2.end:
339346
del self._gaps[i + 1]
340347
# If the gaps are direct neighbors, merge them
341-
elif w_1.end >= w_2.start:
348+
elif w_2 and w_1.end >= w_2.start:
342349
w_1.end = w_2.end
343350
del self._gaps[i + 1]
344351
else:

0 commit comments

Comments
 (0)