You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@druid.apache.org by GitBox <gi...@apache.org> on 2021/07/28 10:05:00 UTC
[GitHub] [druid] yuanlihan commented on a change in pull request #11457: Improve concurrency between DruidSchema and BrokerServerView
yuanlihan commented on a change in pull request #11457:
URL: https://github.com/apache/druid/pull/11457#discussion_r678159621
##########
File path: sql/src/main/java/org/apache/druid/sql/calcite/schema/DruidSchema.java
##########
@@ -408,25 +479,35 @@ void addSegment(final DruidServerMetadata server, final DataSegment segment)
@VisibleForTesting
void removeSegment(final DataSegment segment)
{
+ // Get lock first so that we won't wait in ConcurrentMap.compute().
synchronized (lock) {
log.debug("Segment[%s] is gone.", segment.getId());
segmentsNeedingRefresh.remove(segment.getId());
- mutableSegments.remove(segment.getId());
-
- final Map<SegmentId, AvailableSegmentMetadata> dataSourceSegments =
- segmentMetadataInfo.get(segment.getDataSource());
- if (dataSourceSegments.remove(segment.getId()) != null) {
- totalSegments--;
- }
-
- if (dataSourceSegments.isEmpty()) {
- segmentMetadataInfo.remove(segment.getDataSource());
- tables.remove(segment.getDataSource());
- log.info("dataSource[%s] no longer exists, all metadata removed.", segment.getDataSource());
- } else {
- dataSourcesNeedingRebuild.add(segment.getDataSource());
- }
+ unmarkSegmentAsMutable(segment.getId());
+
+ segmentMetadataInfo.compute(
+ segment.getDataSource(),
+ (dataSource, segmentsMap) -> {
+ if (segmentsMap == null) {
+ log.warn("Unknown segment[%s] was removed from the cluster. Ignoring this event.", segment.getId());
+ return null;
+ } else {
+ if (segmentsMap.remove(segment.getId()) == null) {
+ log.warn("Unknown segment[%s] was removed from the cluster. Ignoring this event.", segment.getId());
+ }
+ totalSegments--;
Review comment:
is it better to change the count only when it's a known segment?
--
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: commits-unsubscribe@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org