KAFKA-4996; Fix findBugs warning in getOrCreateSegment

The code was correct since the method is only called from
one thread, but the change is worthwhile anyway.

Author: Amit Daga <adaga@adobe.com>

Reviewers: Guozhang Wang <wangguoz@gmail.com>, Damian Guy <damian.guy@gmail.com>, Ismael Juma <ismael@juma.me.uk>

Closes #2966 from amitdaga/findbugs-streams-multithread
This commit is contained in:
Amit Daga 2017-05-05 04:58:11 +01:00 committed by Ismael Juma
parent 1816e29981
commit 8c872762f7
2 changed files with 4 additions and 11 deletions

View File

@ -264,13 +264,6 @@ For a detailed description of findbugs bug categories, see http://findbugs.sourc
<Bug pattern="EQ_COMPARETO_USE_OBJECT_EQUALS"/>
</Match>
<Match>
<!-- TODO: fix this (see KAFKA-4996) -->
<Class name="org.apache.kafka.streams.state.internals.Segments"/>
<Method name="getOrCreateSegment"/>
<Bug pattern="AT_OPERATION_SEQUENCE_ON_CONCURRENT_ABSTRACTION"/>
</Match>
<Match>
<!-- TODO: fix this (see KAFKA-4996) -->
<Or>

View File

@ -77,16 +77,16 @@ class Segments {
if (!isSegment(segment, segmentId)) {
cleanup(segmentId);
}
if (!segments.containsKey(key)) {
Segment newSegment = new Segment(segmentName(segmentId), name, segmentId);
Segment newSegment = new Segment(segmentName(segmentId), name, segmentId);
Segment previousSegment = segments.putIfAbsent(key, newSegment);
if (previousSegment == null) {
newSegment.openDB(context);
segments.put(key, newSegment);
maxSegmentId = segmentId > maxSegmentId ? segmentId : maxSegmentId;
if (minSegmentId == Long.MAX_VALUE) {
minSegmentId = maxSegmentId;
}
}
return segments.get(key);
return previousSegment == null ? newSegment : previousSegment;
} else {
return null;
}