egor-ryashin commented on a change in pull request #7306: Reconcile terminology 
and method naming to 'used/unused segments'; Rename MetadataSegmentManager to 
MetadataSegments
URL: https://github.com/apache/incubator-druid/pull/7306#discussion_r273721733
 
 

 ##########
 File path: 
server/src/main/java/org/apache/druid/server/coordinator/helper/DruidCoordinatorLogger.java
 ##########
 @@ -263,28 +259,25 @@ public DruidCoordinatorRuntimeParams 
run(DruidCoordinatorRuntimeParams params)
     );
 
     // Emit segment metrics
-    final Stream<DataSegment> allSegments = params
-        .getDataSources()
-        .values()
-        .stream()
-        .flatMap(timeline -> 
timeline.getAllTimelineEntries().values().stream())
-        .flatMap(entryMap -> entryMap.values().stream())
-        .flatMap(entry -> 
StreamSupport.stream(entry.getPartitionHolder().spliterator(), false))
-        .map(PartitionChunk::getObject);
-
-    allSegments
-        .collect(Collectors.groupingBy(DataSegment::getDataSource))
-        .forEach((final String name, final List<DataSegment> segments) -> {
-          final long size = 
segments.stream().mapToLong(DataSegment::getSize).sum();
+    params.getDataSourcesWithUsedSegments().forEach(
+        (String dataSource, VersionedIntervalTimeline<String, DataSegment> 
dataSourceWithUsedSegments) -> {
+          long totalSizeOfUsedSegments = dataSourceWithUsedSegments
+              .iterateAllObjects()
+              .stream()
+              .mapToLong(DataSegment::getSize)
+              .sum();
           emitter.emit(
-              new 
ServiceMetricEvent.Builder().setDimension(DruidMetrics.DATASOURCE, 
name).build("segment/size", size)
+              new ServiceMetricEvent.Builder()
+                  .setDimension(DruidMetrics.DATASOURCE, dataSource)
+                  .build("segment/size", totalSizeOfUsedSegments)
           );
           emitter.emit(
               new ServiceMetricEvent.Builder()
-                  .setDimension(DruidMetrics.DATASOURCE, name)
-                  .build("segment/count", segments.size())
+                  .setDimension(DruidMetrics.DATASOURCE, dataSource)
+                  .build("segment/count", 
dataSourceWithUsedSegments.getNumObjects())
 
 Review comment:
   It looks a bit inconsistent using `getNumObjects` to get a precalculated 
number of segments but using `stream()` to sum up segments size here
   
![image](https://user-images.githubusercontent.com/14215045/55837998-af0b8580-5b2b-11e9-8173-173a5762bc37.png)
   We could calculate both metrics using a single `stream()` for example.
   

----------------------------------------------------------------
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]

Reply via email to