kfaraz commented on code in PR #18314:
URL: https://github.com/apache/druid/pull/18314#discussion_r2230219536
##########
server/src/main/java/org/apache/druid/client/BrokerServerView.java:
##########
@@ -281,6 +286,7 @@ private void serverAddedSegment(final DruidServerMetadata
server, final DataSegm
timeline.add(segment.getInterval(), segment.getVersion(),
segment.getShardSpec().createChunk(selector));
selectors.put(segmentId, selector);
+ incrementSegmentCount(getMetricKey(segment));
Review Comment:
Sorry, I missed this in the original feedback, I think we need to
de-duplicate the segment counts as the same segment may be served by multiple
processes. So, for every `RowKey` (which already has datasource, interval,
version), you can keep a `Set` of partition numbers. The size of this set will
give the overall `segment/available/count`.
Looking at the embedded tests, I think your original idea of emitting events
upon addition/removal might be useful too. You can either add it in this PR or
a follow up.
So, you can emit a detailed event
`serverview/segment/added`/`serverview/segment/removed` which has `datasource`,
`server`, `description` (containing full segment ID).
##########
server/src/main/java/org/apache/druid/client/BrokerServerView.java:
##########
@@ -436,4 +443,30 @@ public List<ImmutableDruidServer> getDruidServers()
.map(queryableDruidServer ->
queryableDruidServer.getServer().toImmutableDruidServer())
.collect(Collectors.toList());
}
+
+ @Override
+ public Map<RowKey, Long> getAvailableSegmentCount()
+ {
+ return segmentAvailableCount;
+ }
+
+ private void incrementSegmentCount(RowKey key)
+ {
+ segmentAvailableCount.compute(key, (k, currentValue) -> currentValue ==
null ? 1 : currentValue + 1);
+ }
+
+ private void decrementSegmentCount(RowKey key)
+ {
+ segmentAvailableCount.computeIfPresent(key, (k, currentValue) -> {
+ long newValue = currentValue - 1;
+ return newValue > 0 ? newValue : null;
+ });
Review Comment:
Nit: for similarity with the increment method, this can also be:
```suggestion
segmentAvailableCount.compute(key, (k, currentValue) -> currentValue ==
null || currentValue <= 1 ? null : currentValue - 1);
```
--
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]