github-advanced-security[bot] commented on code in PR #19461:
URL: https://github.com/apache/druid/pull/19461#discussion_r3239361494


##########
server/src/test/java/org/apache/druid/server/coordination/SegmentChangeRequestLoadTest.java:
##########
@@ -131,6 +131,134 @@
     Assert.assertEquals(Long.valueOf(12345L), reread.getLoadedBytes());
   }
 
+  @Test
+  public void testForAnnouncementBareSegment()
+  {
+    // A segment loaded without a partial-load wrapper produces a plain 
announcement with no partial fields.
+    DataSegment segment = new DataSegment(
+        "ds",
+        Intervals.of("2024-01-01/2024-02-01"),
+        "v1",
+        Map.of("type", "local"),
+        List.of("d"),
+        List.of("m"),
+        NoneShardSpec.instance(),
+        IndexIO.CURRENT_VERSION_ID,
+        100
+    );
+    SegmentChangeRequestLoad announcement = 
SegmentChangeRequestLoad.forAnnouncement(segment);
+    Assert.assertNull(announcement.getFingerprint());
+    Assert.assertNull(announcement.getLoadedBytes());
+  }
+
+  @Test
+  public void testForAnnouncementPartialProjectionWrapperProducesFullFallback()
+  {
+    // When the segment's loadSpec is a partialProjection wrapper, the 
announcement stamps the wrapper's fingerprint
+    // and the segment's full size as loadedBytes — coordinator reads this as 
a full-fallback profile and counts the
+    // replica as matching, avoiding reload thrash on historicals that don't 
(yet) do real partial loading.
+    Map<String, Object> wrapped = Map.of(
+        "type", "partialProjection",
+        "delegate", Map.of("type", "local", "path", "/var/druid/segments/foo"),
+        "projections", List.of("revenue"),
+        "fingerprint", "v1:abcdef0123456789"
+    );
+    DataSegment segment = new DataSegment(
+        "ds",
+        Intervals.of("2024-01-01/2024-02-01"),
+        "v1",
+        wrapped,
+        List.of("d"),
+        List.of("m"),
+        NoneShardSpec.instance(),
+        IndexIO.CURRENT_VERSION_ID,
+        12345
+    );
+    SegmentChangeRequestLoad announcement = 
SegmentChangeRequestLoad.forAnnouncement(segment);
+    Assert.assertEquals("v1:abcdef0123456789", announcement.getFingerprint());
+    Assert.assertEquals(Long.valueOf(12345L), announcement.getLoadedBytes());
+  }
+
+  @Test
+  public void 
testForAnnouncementUnknownPartialTypeStillRecognizedByConvention()
+  {
+    // Any partial-load wire form (type starts with "partial", plus 
fingerprint + delegate at top level) gets the
+    // full-fallback treatment — the announcement layer doesn't need to know 
about specific subtypes. This is what
+    // makes future PartialLoadSpec subtypes work without touching this code.
+    Map<String, Object> wrapped = Map.of(
+        "type", "partialFutureScheme",
+        "delegate", Map.of("type", "local", "path", "/var/druid/segments/foo"),
+        "fingerprint", "v1:1111111111111111"
+    );
+    DataSegment segment = new DataSegment(
+        "ds",
+        Intervals.of("2024-01-01/2024-02-01"),
+        "v1",
+        wrapped,
+        List.of("d"),
+        List.of("m"),
+        NoneShardSpec.instance(),
+        IndexIO.CURRENT_VERSION_ID,
+        7777
+    );
+    SegmentChangeRequestLoad announcement = 
SegmentChangeRequestLoad.forAnnouncement(segment);
+    Assert.assertEquals("v1:1111111111111111", announcement.getFingerprint());
+    Assert.assertEquals(Long.valueOf(7777L), announcement.getLoadedBytes());
+  }
+
+  @Test
+  public void testForAnnouncementNonPartialTypeIgnoredEvenWithFingerprint()
+  {
+    // The type-prefix gate keeps non-partial LoadSpecs that happen to use a 
"fingerprint" key from being
+    // mis-classified as partial-load wrappers.
+    Map<String, Object> looksSuspicious = Map.of(
+        "type", "local",
+        "path", "/var/druid/segments/foo",
+        "fingerprint", "v1:notreallypartial",
+        "delegate", Map.of("ignored", "yes")
+    );
+    DataSegment segment = new DataSegment(
+        "ds",
+        Intervals.of("2024-01-01/2024-02-01"),
+        "v1",
+        looksSuspicious,
+        List.of("d"),
+        List.of("m"),
+        NoneShardSpec.instance(),
+        IndexIO.CURRENT_VERSION_ID,
+        100
+    );

Review Comment:
   ## CodeQL / Deprecated method or constructor invocation
   
   Invoking [DataSegment.DataSegment](1) should be avoided because it has been 
deprecated.
   
   [Show more 
details](https://github.com/apache/druid/security/code-scanning/11225)



##########
server/src/test/java/org/apache/druid/server/coordination/SegmentChangeRequestLoadTest.java:
##########
@@ -131,6 +131,134 @@
     Assert.assertEquals(Long.valueOf(12345L), reread.getLoadedBytes());
   }
 
+  @Test
+  public void testForAnnouncementBareSegment()
+  {
+    // A segment loaded without a partial-load wrapper produces a plain 
announcement with no partial fields.
+    DataSegment segment = new DataSegment(
+        "ds",
+        Intervals.of("2024-01-01/2024-02-01"),
+        "v1",
+        Map.of("type", "local"),
+        List.of("d"),
+        List.of("m"),
+        NoneShardSpec.instance(),
+        IndexIO.CURRENT_VERSION_ID,
+        100
+    );
+    SegmentChangeRequestLoad announcement = 
SegmentChangeRequestLoad.forAnnouncement(segment);
+    Assert.assertNull(announcement.getFingerprint());
+    Assert.assertNull(announcement.getLoadedBytes());
+  }
+
+  @Test
+  public void testForAnnouncementPartialProjectionWrapperProducesFullFallback()
+  {
+    // When the segment's loadSpec is a partialProjection wrapper, the 
announcement stamps the wrapper's fingerprint
+    // and the segment's full size as loadedBytes — coordinator reads this as 
a full-fallback profile and counts the
+    // replica as matching, avoiding reload thrash on historicals that don't 
(yet) do real partial loading.
+    Map<String, Object> wrapped = Map.of(
+        "type", "partialProjection",
+        "delegate", Map.of("type", "local", "path", "/var/druid/segments/foo"),
+        "projections", List.of("revenue"),
+        "fingerprint", "v1:abcdef0123456789"
+    );
+    DataSegment segment = new DataSegment(
+        "ds",
+        Intervals.of("2024-01-01/2024-02-01"),
+        "v1",
+        wrapped,
+        List.of("d"),
+        List.of("m"),
+        NoneShardSpec.instance(),
+        IndexIO.CURRENT_VERSION_ID,
+        12345
+    );
+    SegmentChangeRequestLoad announcement = 
SegmentChangeRequestLoad.forAnnouncement(segment);
+    Assert.assertEquals("v1:abcdef0123456789", announcement.getFingerprint());
+    Assert.assertEquals(Long.valueOf(12345L), announcement.getLoadedBytes());
+  }
+
+  @Test
+  public void 
testForAnnouncementUnknownPartialTypeStillRecognizedByConvention()
+  {
+    // Any partial-load wire form (type starts with "partial", plus 
fingerprint + delegate at top level) gets the
+    // full-fallback treatment — the announcement layer doesn't need to know 
about specific subtypes. This is what
+    // makes future PartialLoadSpec subtypes work without touching this code.
+    Map<String, Object> wrapped = Map.of(
+        "type", "partialFutureScheme",
+        "delegate", Map.of("type", "local", "path", "/var/druid/segments/foo"),
+        "fingerprint", "v1:1111111111111111"
+    );
+    DataSegment segment = new DataSegment(
+        "ds",
+        Intervals.of("2024-01-01/2024-02-01"),
+        "v1",
+        wrapped,
+        List.of("d"),
+        List.of("m"),
+        NoneShardSpec.instance(),
+        IndexIO.CURRENT_VERSION_ID,
+        7777
+    );

Review Comment:
   ## CodeQL / Deprecated method or constructor invocation
   
   Invoking [DataSegment.DataSegment](1) should be avoided because it has been 
deprecated.
   
   [Show more 
details](https://github.com/apache/druid/security/code-scanning/11224)



##########
server/src/test/java/org/apache/druid/server/coordination/SegmentChangeRequestLoadTest.java:
##########
@@ -131,6 +131,134 @@
     Assert.assertEquals(Long.valueOf(12345L), reread.getLoadedBytes());
   }
 
+  @Test
+  public void testForAnnouncementBareSegment()
+  {
+    // A segment loaded without a partial-load wrapper produces a plain 
announcement with no partial fields.
+    DataSegment segment = new DataSegment(
+        "ds",
+        Intervals.of("2024-01-01/2024-02-01"),
+        "v1",
+        Map.of("type", "local"),
+        List.of("d"),
+        List.of("m"),
+        NoneShardSpec.instance(),
+        IndexIO.CURRENT_VERSION_ID,
+        100
+    );
+    SegmentChangeRequestLoad announcement = 
SegmentChangeRequestLoad.forAnnouncement(segment);
+    Assert.assertNull(announcement.getFingerprint());
+    Assert.assertNull(announcement.getLoadedBytes());
+  }
+
+  @Test
+  public void testForAnnouncementPartialProjectionWrapperProducesFullFallback()
+  {
+    // When the segment's loadSpec is a partialProjection wrapper, the 
announcement stamps the wrapper's fingerprint
+    // and the segment's full size as loadedBytes — coordinator reads this as 
a full-fallback profile and counts the
+    // replica as matching, avoiding reload thrash on historicals that don't 
(yet) do real partial loading.
+    Map<String, Object> wrapped = Map.of(
+        "type", "partialProjection",
+        "delegate", Map.of("type", "local", "path", "/var/druid/segments/foo"),
+        "projections", List.of("revenue"),
+        "fingerprint", "v1:abcdef0123456789"
+    );
+    DataSegment segment = new DataSegment(
+        "ds",
+        Intervals.of("2024-01-01/2024-02-01"),
+        "v1",
+        wrapped,
+        List.of("d"),
+        List.of("m"),
+        NoneShardSpec.instance(),
+        IndexIO.CURRENT_VERSION_ID,
+        12345
+    );
+    SegmentChangeRequestLoad announcement = 
SegmentChangeRequestLoad.forAnnouncement(segment);
+    Assert.assertEquals("v1:abcdef0123456789", announcement.getFingerprint());
+    Assert.assertEquals(Long.valueOf(12345L), announcement.getLoadedBytes());
+  }
+
+  @Test
+  public void 
testForAnnouncementUnknownPartialTypeStillRecognizedByConvention()
+  {
+    // Any partial-load wire form (type starts with "partial", plus 
fingerprint + delegate at top level) gets the
+    // full-fallback treatment — the announcement layer doesn't need to know 
about specific subtypes. This is what
+    // makes future PartialLoadSpec subtypes work without touching this code.
+    Map<String, Object> wrapped = Map.of(
+        "type", "partialFutureScheme",
+        "delegate", Map.of("type", "local", "path", "/var/druid/segments/foo"),
+        "fingerprint", "v1:1111111111111111"
+    );
+    DataSegment segment = new DataSegment(
+        "ds",
+        Intervals.of("2024-01-01/2024-02-01"),
+        "v1",
+        wrapped,
+        List.of("d"),
+        List.of("m"),
+        NoneShardSpec.instance(),
+        IndexIO.CURRENT_VERSION_ID,
+        7777
+    );
+    SegmentChangeRequestLoad announcement = 
SegmentChangeRequestLoad.forAnnouncement(segment);
+    Assert.assertEquals("v1:1111111111111111", announcement.getFingerprint());
+    Assert.assertEquals(Long.valueOf(7777L), announcement.getLoadedBytes());
+  }
+
+  @Test
+  public void testForAnnouncementNonPartialTypeIgnoredEvenWithFingerprint()
+  {
+    // The type-prefix gate keeps non-partial LoadSpecs that happen to use a 
"fingerprint" key from being
+    // mis-classified as partial-load wrappers.
+    Map<String, Object> looksSuspicious = Map.of(
+        "type", "local",
+        "path", "/var/druid/segments/foo",
+        "fingerprint", "v1:notreallypartial",
+        "delegate", Map.of("ignored", "yes")
+    );
+    DataSegment segment = new DataSegment(
+        "ds",
+        Intervals.of("2024-01-01/2024-02-01"),
+        "v1",
+        looksSuspicious,
+        List.of("d"),
+        List.of("m"),
+        NoneShardSpec.instance(),
+        IndexIO.CURRENT_VERSION_ID,
+        100
+    );
+    SegmentChangeRequestLoad announcement = 
SegmentChangeRequestLoad.forAnnouncement(segment);
+    Assert.assertNull(announcement.getFingerprint());
+    Assert.assertNull(announcement.getLoadedBytes());
+  }
+
+  @Test
+  public void testForAnnouncementMalformedPartialTypeFallsThroughToPlainLoad()
+  {
+    // A partial-typed loadSpec missing the fingerprint contract should not 
stall the queue: announce as a plain
+    // load (the log.warn at the call site surfaces the bug).
+    Map<String, Object> malformed = Map.of(
+        "type", "partialProjection",
+        "delegate", Map.of("type", "local", "path", "/var/druid/segments/foo")
+        // no fingerprint
+    );
+    DataSegment segment = new DataSegment(
+        "ds",
+        Intervals.of("2024-01-01/2024-02-01"),
+        "v1",
+        malformed,
+        List.of("d"),
+        List.of("m"),
+        NoneShardSpec.instance(),
+        IndexIO.CURRENT_VERSION_ID,
+        100
+    );

Review Comment:
   ## CodeQL / Deprecated method or constructor invocation
   
   Invoking [DataSegment.DataSegment](1) should be avoided because it has been 
deprecated.
   
   [Show more 
details](https://github.com/apache/druid/security/code-scanning/11226)



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