kafka-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ij...@apache.org
Subject kafka git commit: KAFKA-4996; Fix findBugs warning in getOrCreateSegment
Date Fri, 05 May 2017 03:59:41 GMT
Repository: kafka
Updated Branches:
  refs/heads/trunk 1816e2998 -> 8c872762f


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


Project: http://git-wip-us.apache.org/repos/asf/kafka/repo
Commit: http://git-wip-us.apache.org/repos/asf/kafka/commit/8c872762
Tree: http://git-wip-us.apache.org/repos/asf/kafka/tree/8c872762
Diff: http://git-wip-us.apache.org/repos/asf/kafka/diff/8c872762

Branch: refs/heads/trunk
Commit: 8c872762f7ef47a4a2d2c7d49993cedacd50d8b4
Parents: 1816e29
Author: Amit Daga <adaga@adobe.com>
Authored: Fri May 5 04:58:11 2017 +0100
Committer: Ismael Juma <ismael@juma.me.uk>
Committed: Fri May 5 04:58:16 2017 +0100

----------------------------------------------------------------------
 gradle/findbugs-exclude.xml                                  | 7 -------
 .../org/apache/kafka/streams/state/internals/Segments.java   | 8 ++++----
 2 files changed, 4 insertions(+), 11 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/kafka/blob/8c872762/gradle/findbugs-exclude.xml
----------------------------------------------------------------------
diff --git a/gradle/findbugs-exclude.xml b/gradle/findbugs-exclude.xml
index eeea7fc..b0616a8 100644
--- a/gradle/findbugs-exclude.xml
+++ b/gradle/findbugs-exclude.xml
@@ -266,13 +266,6 @@ For a detailed description of findbugs bug categories, see http://findbugs.sourc
 
     <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>
             <Package name="org.apache.kafka.streams.state.internals"/>
             <Package name="org.apache.kafka.streams.processor.internals"/>

http://git-wip-us.apache.org/repos/asf/kafka/blob/8c872762/streams/src/main/java/org/apache/kafka/streams/state/internals/Segments.java
----------------------------------------------------------------------
diff --git a/streams/src/main/java/org/apache/kafka/streams/state/internals/Segments.java
b/streams/src/main/java/org/apache/kafka/streams/state/internals/Segments.java
index a02f87e..3036f79 100644
--- a/streams/src/main/java/org/apache/kafka/streams/state/internals/Segments.java
+++ b/streams/src/main/java/org/apache/kafka/streams/state/internals/Segments.java
@@ -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;
         }


Mime
View raw message