You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@druid.apache.org by GitBox <gi...@apache.org> on 2018/07/09 18:22:33 UTC

[GitHub] gianm closed pull request #5969: [Backport] Fix inefficient available segment cache population in SQLMetadataSegmentManager

gianm closed pull request #5969: [Backport] Fix inefficient available segment cache population in SQLMetadataSegmentManager
URL: https://github.com/apache/incubator-druid/pull/5969
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/server/src/main/java/io/druid/client/DruidDataSource.java b/server/src/main/java/io/druid/client/DruidDataSource.java
index ed2594b67c8..af9cb2b18a1 100644
--- a/server/src/main/java/io/druid/client/DruidDataSource.java
+++ b/server/src/main/java/io/druid/client/DruidDataSource.java
@@ -90,6 +90,14 @@ public ImmutableDruidDataSource toImmutableDruidDataSource()
     return new ImmutableDruidDataSource(name, properties, idToSegmentMap);
   }
 
+  // For performance reasons, make sure we check for the existence of a segment using containsSegment(),
+  // which performs a key-based lookup, instead of calling contains() on the collection returned by
+  // dataSource.getSegments(). In Map values collections, the contains() method is a linear scan.
+  public boolean containsSegment(DataSegment segment)
+  {
+    return idToSegmentMap.containsKey(segment.getIdentifier());
+  }
+
   @Override
   public String toString()
   {
diff --git a/server/src/main/java/io/druid/metadata/SQLMetadataSegmentManager.java b/server/src/main/java/io/druid/metadata/SQLMetadataSegmentManager.java
index 6f3f4581991..36f628c55d2 100644
--- a/server/src/main/java/io/druid/metadata/SQLMetadataSegmentManager.java
+++ b/server/src/main/java/io/druid/metadata/SQLMetadataSegmentManager.java
@@ -502,7 +502,10 @@ public DataSegment map(int index, ResultSet r, StatementContext ctx)
           }
         }
 
-        if (!dataSource.getSegments().contains(segment)) {
+        // For performance reasons, make sure we check for the existence of a segment using containsSegment(),
+        // which performs a key-based lookup, instead of calling contains() on the collection returned by
+        // dataSource.getSegments(). In Map values collections, the contains() method is a linear scan.
+        if (!dataSource.containsSegment(segment)) {
           dataSource.addSegment(segment);
         }
       }


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@druid.apache.org
For additional commands, e-mail: dev-help@druid.apache.org