surekhasaharan commented on a change in pull request #7425: Add is_overshadowed
column to sys.segments table
URL: https://github.com/apache/incubator-druid/pull/7425#discussion_r279509466
##########
File path:
server/src/main/java/org/apache/druid/server/http/MetadataResource.java
##########
@@ -159,14 +162,61 @@ public Response getDatabaseSegments(
}
final Stream<DataSegment> metadataSegments = dataSourceStream.flatMap(t ->
t.getSegments().stream());
- final Function<DataSegment, Iterable<ResourceAction>> raGenerator =
segment -> Collections.singletonList(
-
AuthorizationUtils.DATASOURCE_READ_RA_GENERATOR.apply(segment.getDataSource()));
+ if (includeOvershadowedStatus != null) {
+ final Iterable<SegmentWithOvershadowedStatus> authorizedSegments =
findAuthorizedSegmentWithOvershadowedStatus(
+ req,
+ druidDataSources,
+ metadataSegments
+ );
+ Response.ResponseBuilder builder = Response.status(Response.Status.OK);
+ return builder.entity(authorizedSegments).build();
+ } else {
+
+ final Function<DataSegment, Iterable<ResourceAction>> raGenerator =
segment -> Collections.singletonList(
+
AuthorizationUtils.DATASOURCE_READ_RA_GENERATOR.apply(segment.getDataSource()));
+
+ final Iterable<DataSegment> authorizedSegments =
AuthorizationUtils.filterAuthorizedResources(
+ req,
+ metadataSegments::iterator,
+ raGenerator,
+ authorizerMapper
+ );
+
+ Response.ResponseBuilder builder = Response.status(Response.Status.OK);
+ return builder.entity(authorizedSegments).build();
+ }
+ }
- final Iterable<DataSegment> authorizedSegments =
- AuthorizationUtils.filterAuthorizedResources(req,
metadataSegments::iterator, raGenerator, authorizerMapper);
+ private Iterable<SegmentWithOvershadowedStatus>
findAuthorizedSegmentWithOvershadowedStatus(
+ HttpServletRequest req,
+ Collection<ImmutableDruidDataSource> druidDataSources,
+ Stream<DataSegment> metadataSegments
+ )
+ {
+ // It's fine to add all overshadowed segments to a single collection
because only
+ // a small fraction of the segments in the cluster are expected to be
overshadowed,
+ // so building this collection shouldn't generate a lot of garbage.
+ final Set<DataSegment> overshadowedSegments = new HashSet<>();
+ for (ImmutableDruidDataSource dataSource : druidDataSources) {
+
overshadowedSegments.addAll(ImmutableDruidDataSource.determineOvershadowedSegments(dataSource.getSegments()));
Review comment:
Thanks for your suggestion, but this code change is not contained in this
method and would affect other places in the code, some of which are not part of
original PR( eg coordinator balancing logic). I would prefer to do this change
separately as it suggests changing `DataSegment` object and adding new
interfaces, so there may be more follow-up discussions. Created #7571 to
address this comment.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]