mirror of https://github.com/apache/kafka.git
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:
parent
1816e29981
commit
8c872762f7
|
@ -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>
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue