Fix inefficient available segment cache population in SQLMetadataSegmentManager (#5878)

This commit is contained in:
Jonathan Wei 2018-06-12 18:53:30 -07:00 committed by GitHub
parent bc9da54e12
commit 24efbb054c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 1 deletions

View File

@ -85,6 +85,14 @@ public class DruidDataSource
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()
{

View File

@ -475,7 +475,10 @@ public class SQLMetadataSegmentManager implements MetadataSegmentManager
}
}
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);
}
}