uds5501 commented on code in PR #18314:
URL: https://github.com/apache/druid/pull/18314#discussion_r2237001028
##########
server/src/main/java/org/apache/druid/client/BrokerServerView.java:
##########
@@ -436,4 +449,55 @@ public List<ImmutableDruidServer> getDruidServers()
.map(queryableDruidServer ->
queryableDruidServer.getServer().toImmutableDruidServer())
.collect(Collectors.toList());
}
+
+ private void incrementSegmentCount(RowKey key)
+ {
+ totalSegmentAddCount.compute(key, (k, currentValue) -> currentValue ==
null ? 1 : currentValue + 1);
+ }
+
+ @Override
+ public Map<RowKey, Long> getSegmentAddedCount()
+ {
+ final ConcurrentHashMap<RowKey, Long> total = totalSegmentAddCount;
+ synchronized (totalSegmentAddCount) {
+ final Map<RowKey, Long> delta = getDeltaValues(total,
previousSegmentAddCount);
+ previousSegmentAddCount = total;
+ return delta;
+ }
+ }
+
+ @Override
+ public Map<RowKey, Long> getSegmentRemovedCount()
+ {
+ final ConcurrentHashMap<RowKey, Long> total = totalSegmentRemoveCount;
+ synchronized (totalSegmentRemoveCount) {
+ final Map<RowKey, Long> delta = getDeltaValues(total,
previousSegmentRemoveCount);
+ previousSegmentRemoveCount = total;
+ return delta;
+ }
+ }
+
+ private void decrementSegmentCount(RowKey key)
+ {
+ totalSegmentRemoveCount.compute(key, (k, currentValue) -> currentValue ==
null ? 1 : currentValue + 1);
+ }
+
+ private Map<RowKey, Long> getDeltaValues(Map<RowKey, Long> total,
Map<RowKey, Long> prev)
+ {
+ final Map<RowKey, Long> deltaValues = new HashMap<>();
+ total.forEach(
+ (dataSource, totalCount) -> deltaValues.put(
+ dataSource,
+ totalCount - prev.getOrDefault(dataSource, 0L)
+ )
+ );
+ return deltaValues;
+ }
+
+ private static RowKey getMetricKey(final DataSegment segment)
+ {
+ return RowKey.with(Dimension.DATASOURCE, segment.getDataSource())
+ .with(Dimension.INTERVAL,
String.valueOf(segment.getInterval()))
+ .and(Dimension.VERSION, segment.getVersion());
Review Comment:
done
##########
server/src/main/java/org/apache/druid/client/BrokerServerView.java:
##########
@@ -76,6 +80,12 @@ public class BrokerServerView implements TimelineServerView
private final CountDownLatch initialized = new CountDownLatch(1);
private final FilteredServerInventoryView baseView;
private final BrokerViewOfCoordinatorConfig brokerViewOfCoordinatorConfig;
+ private final ConcurrentHashMap<RowKey, Long> totalSegmentAddCount = new
ConcurrentHashMap<>();
+ private final ConcurrentHashMap<RowKey, Long> totalSegmentRemoveCount = new
ConcurrentHashMap<>();
+ @GuardedBy("totalSegmentAddCount")
+ private Map<RowKey, Long> previousSegmentAddCount = new HashMap<>();
+ @GuardedBy("totalSegmentRemoveCount")
+ private Map<RowKey, Long> previousSegmentRemoveCount = new HashMap<>();
Review Comment:
done
--
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.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]