jon-wei commented on a change in pull request #7547: Add support minor 
compaction with segment locking
URL: https://github.com/apache/incubator-druid/pull/7547#discussion_r297411593
 
 

 ##########
 File path: 
server/src/main/java/org/apache/druid/metadata/IndexerSQLMetadataStorageCoordinator.java
 ##########
 @@ -630,24 +651,32 @@ private SegmentIdWithShardSpec createNewSegment(
     if (existingChunks.size() > 1) {
       // Not possible to expand more than one chunk with a single segment.
       log.warn(
-          "Cannot allocate new segment for dataSource[%s], interval[%s], 
maxVersion[%s]: already have [%,d] chunks.",
+          "Cannot allocate new segment for dataSource[%s], interval[%s]: 
already have [%,d] chunks.",
           dataSource,
           interval,
-          maxVersion,
           existingChunks.size()
       );
       return null;
+
     } else {
+      if (existingChunks
+          .stream()
+          .flatMap(holder -> 
StreamSupport.stream(holder.getObject().spliterator(), false))
+          .anyMatch(chunk -> 
!chunk.getObject().getShardSpec().isCompatible(shardSpecFactory.getShardSpecClass())))
 {
+        // All existing segments should have a compatible shardSpec with 
shardSpecFactory.
+        return null;
+      }
+
       SegmentIdWithShardSpec maxId = null;
 
       if (!existingChunks.isEmpty()) {
         TimelineObjectHolder<String, DataSegment> existingHolder = 
Iterables.getOnlyElement(existingChunks);
-        for (PartitionChunk<DataSegment> existing : 
existingHolder.getObject()) {
-          if (maxId == null ||
-              maxId.getShardSpec().getPartitionNum() < 
existing.getObject().getShardSpec().getPartitionNum()) {
-            maxId = 
SegmentIdWithShardSpec.fromDataSegment(existing.getObject());
-          }
-        }
+
+        maxId = StreamSupport.stream(existingHolder.getObject().spliterator(), 
false)
+                             .filter(chunk -> 
chunk.getObject().getShardSpec().getClass() == 
shardSpecFactory.getShardSpecClass())
 
 Review comment:
   Should `getShardSpec().getClass() ==` use `.getShardSpec().isCompatible` 
instead, like in the block above?

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