Browse Source

KAFKA-9384: Loop improvements (#7907)

Reviewers: Bruno Cadonna <bruno@confluent.io>, Guozhang Wang <wangguoz@gmail.com>
pull/7914/head
highluck 5 years ago committed by Guozhang Wang
parent
commit
bbbf431d6e
  1. 17
      streams/src/main/java/org/apache/kafka/streams/state/internals/AbstractSegments.java

17
streams/src/main/java/org/apache/kafka/streams/state/internals/AbstractSegments.java

@ -97,18 +97,11 @@ abstract class AbstractSegments<S extends Segment> implements Segments<S> {
if (dir.exists()) { if (dir.exists()) {
final String[] list = dir.list(); final String[] list = dir.list();
if (list != null) { if (list != null) {
final long[] segmentIds = new long[list.length]; Arrays.stream(list)
for (int i = 0; i < list.length; i++) { .map(segment -> segmentIdFromSegmentName(segment, dir))
segmentIds[i] = segmentIdFromSegmentName(list[i], dir); .sorted() // open segments in the id order
} .filter(segmentId -> segmentId >= 0)
.forEach(segmentId -> getOrCreateSegment(segmentId, context));
// open segments in the id order
Arrays.sort(segmentIds);
for (final long segmentId : segmentIds) {
if (segmentId >= 0) {
getOrCreateSegment(segmentId, context);
}
}
} }
} else { } else {
if (!dir.mkdir()) { if (!dir.mkdir()) {

Loading…
Cancel
Save