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

Reply via email to