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

Loading…
Cancel
Save