You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@druid.apache.org by "dulu98Kurz (via GitHub)" <gi...@apache.org> on 2023/10/04 17:51:35 UTC

[PR] Dun bugfix statemap (druid)

dulu98Kurz opened a new pull request, #15090:
URL: https://github.com/apache/druid/pull/15090

   <!-- Thanks for trying to help us make Apache Druid be the best it can be! Please fill out as much of the following information as is possible (where relevant, and remove it when irrelevant) to help make the intention and scope of this PR clear in order to ease review. -->
   
   <!-- Please read the doc for contribution (https://github.com/apache/druid/blob/master/CONTRIBUTING.md) before making this PR. Also, once you open a PR, please _avoid using force pushes and rebasing_ since these make it difficult for reviewers to see what you've changed in response to their reviews. See [the 'If your pull request shows conflicts with master' section](https://github.com/apache/druid/blob/master/CONTRIBUTING.md#if-your-pull-request-shows-conflicts-with-master) for more details. -->
   
   Fixes #XXXX.
   
   <!-- Replace XXXX with the id of the issue fixed in this PR. Remove this section if there is no corresponding issue. Don't reference the issue in the title of this pull-request. -->
   
   <!-- If you are a committer, follow the PR action item checklist for committers:
   https://github.com/apache/druid/blob/master/dev/committer-instructions.md#pr-and-issue-action-item-checklist-for-committers. -->
   
   ### Description
   
   <!-- Describe the goal of this PR, what problem are you fixing. If there is a corresponding issue (referenced above), it's not necessary to repeat the description here, however, you may choose to keep one summary sentence. -->
   
   <!-- Describe your patch: what did you change in code? How did you fix the problem? -->
   
   <!-- If there are several relatively logically separate changes in this PR, create a mini-section for each of them. For example: -->
   
   #### Fixed the bug ...
   #### Renamed the class ...
   #### Added a forbidden-apis entry ...
   
   <!--
   In each section, please describe design decisions made, including:
    - Choice of algorithms
    - Behavioral aspects. What configuration values are acceptable? How are corner cases and error conditions handled, such as when there are insufficient resources?
    - Class organization and design (how the logic is split between classes, inheritance, composition, design patterns)
    - Method organization and design (how the logic is split between methods, parameters and return types)
    - Naming (class, method, API, configuration, HTTP endpoint, names of emitted metrics)
   -->
   
   
   <!-- It's good to describe an alternative design (or mention an alternative name) for every design (or naming) decision point and compare the alternatives with the designs that you've implemented (or the names you've chosen) to highlight the advantages of the chosen designs and names. -->
   
   <!-- If there was a discussion of the design of the feature implemented in this PR elsewhere (e. g. a "Proposal" issue, any other issue, or a thread in the development mailing list), link to that discussion from this PR description and explain what have changed in your final design compared to your original proposal or the consensus version in the end of the discussion. If something hasn't changed since the original discussion, you can omit a detailed discussion of those aspects of the design here, perhaps apart from brief mentioning for the sake of readability of this PR description. -->
   
   <!-- Some of the aspects mentioned above may be omitted for simple and small changes. -->
   
   #### Release note
   <!-- Give your best effort to summarize your changes in a couple of sentences aimed toward Druid users. 
   
   If your change doesn't have end user impact, you can skip this section.
   
   For tips about how to write a good release note, see [Release notes](https://github.com/apache/druid/blob/master/CONTRIBUTING.md#release-notes).
   
   -->
   
   
   <hr>
   
   ##### Key changed/added classes in this PR
    * `MyFoo`
    * `OurBar`
    * `TheirBaz`
   
   <hr>
   
   <!-- Check the items by putting "x" in the brackets for the done things. Not all of these items apply to every PR. Remove the items which are not done or not relevant to the PR. None of the items from the checklist below are strictly necessary, but it would be very helpful if you at least self-review the PR. -->
   
   This PR has:
   
   - [ ] been self-reviewed.
      - [ ] using the [concurrency checklist](https://github.com/apache/druid/blob/master/dev/code-review/concurrency.md) (Remove this item if the PR doesn't have any relation to concurrency.)
   - [ ] added documentation for new or modified features or behaviors.
   - [ ] a release note entry in the PR description.
   - [ ] added Javadocs for most classes and all non-trivial methods. Linked related entities via Javadoc links.
   - [ ] added or updated version, license, or notice information in [licenses.yaml](https://github.com/apache/druid/blob/master/dev/license.md)
   - [ ] added comments explaining the "why" and the intent of the code wherever would not be obvious for an unfamiliar reader.
   - [ ] added unit tests or modified existing tests to cover new code paths, ensuring the threshold for [code coverage](https://github.com/apache/druid/blob/master/dev/code-review/code-coverage.md) is met.
   - [ ] added integration tests.
   - [ ] been tested in a test Druid cluster.
   


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


Re: [PR] Remediate ingestion failures when number of segments in time period is larger than 32767 (druid)

Posted by "dulu98Kurz (via GitHub)" <gi...@apache.org>.
dulu98Kurz commented on code in PR #15090:
URL: https://github.com/apache/druid/pull/15090#discussion_r1350578049


##########
processing/src/main/java/org/apache/druid/timeline/partition/OvershadowableManager.java:
##########
@@ -418,9 +420,11 @@ private Iterator<Entry<RootPartitionRange, Short2ObjectSortedMap<AtomicUpdateGro
       TreeMap<RootPartitionRange, Short2ObjectSortedMap<AtomicUpdateGroup<T>>> stateMap
   )
   {
-    final RootPartitionRange lowFench = new RootPartitionRange(partitionId, partitionId);
+    // remediate submap `fromKey > toKey` issue when partitionId overflows
+    final short partitionIdLowFence = partitionId < 0 ? Short.MAX_VALUE : partitionId;

Review Comment:
   Hi @abhishekagarwal87 , thanks for checking on this!
   You are right our investigation suggesting both late-messages from upstream and compactions falling behind, specifically we found there were random late-messages mixed in the kafka topics, it keep adding tiny segments to finalized trunk and eventually goes beyond `short` range and broke live ingestion tasks of new data, setting rejection period was not ideal because it means we will lose data, and because compaction falling behind we can`t afford to wait for it to catch up , I end up hard deleting the problematic time-trunk and then I realized solely relying on compaction seems inadequate.
   
   Admittedly it is not an ideal use-case for Druid to handle random late messages, but it was a really difficult choice when user had to chose between letting ingestion broke vs deleting problematic time trunk.
   



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


Re: [PR] Remediate ingestion failures when number of segments in time period is larger than 32767 (druid)

Posted by "dulu98Kurz (via GitHub)" <gi...@apache.org>.
dulu98Kurz commented on PR #15090:
URL: https://github.com/apache/druid/pull/15090#issuecomment-1747635491

   Let me know if it is appropriate to refactor partitionId to `Int` instead of `short`, which I believe solve this problem more completely.


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


Re: [PR] Remediate ingestion failures when number of segments in time period is larger than 32767 (druid)

Posted by "dulu98Kurz (via GitHub)" <gi...@apache.org>.
dulu98Kurz commented on code in PR #15090:
URL: https://github.com/apache/druid/pull/15090#discussion_r1350650766


##########
processing/src/main/java/org/apache/druid/timeline/partition/OvershadowableManager.java:
##########
@@ -418,9 +420,11 @@ private Iterator<Entry<RootPartitionRange, Short2ObjectSortedMap<AtomicUpdateGro
       TreeMap<RootPartitionRange, Short2ObjectSortedMap<AtomicUpdateGroup<T>>> stateMap
   )
   {
-    final RootPartitionRange lowFench = new RootPartitionRange(partitionId, partitionId);
+    // remediate submap `fromKey > toKey` issue when partitionId overflows
+    final short partitionIdLowFence = partitionId < 0 ? Short.MAX_VALUE : partitionId;

Review Comment:
   From code quality perspective, `Short.toUnsignedInt` is a precision-loss conversion and we used it in 2 files for 18 times, we can simplify the logic and improve readability if we change to `int`
   <img width="606" alt="image" src="https://github.com/apache/druid/assets/14854898/47a36432-d6fb-4f7e-9fdf-1610bf54e39b">
   
   Lastly, when partitionId is out of range, the [logic](https://github.com/apache/druid/blob/master/processing/src/main/java/org/apache/druid/timeline/partition/OvershadowableManager.java#L421-L423) we use to handle it right now is simply wrong:
   ```
   final RootPartitionRange lowFench = new RootPartitionRange(partitionId, partitionId);
   final RootPartitionRange highFence = new RootPartitionRange(Short.MAX_VALUE, Short.MAX_VALUE);
   return stateMap.subMap(lowFench, false, highFence, false).entrySet().iterator();
   ```
   For example when:
   <img width="304" alt="image" src="https://github.com/apache/druid/assets/14854898/03d6e2c1-ed5d-4e10-b708-e05699fb12f2">
   Then  `stateMap.subMap(lowFench, false, highFence, false)` will return all entries instead of empty ...
   
   If we are ok with remediation in this PR, we can proceed with merging, if we are OK with refactoring please allow me to send another PR to fix it more completely.



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


Re: [PR] Remediate ingestion failures when number of segments in time period is larger than 32767 (druid)

Posted by "kfaraz (via GitHub)" <gi...@apache.org>.
kfaraz commented on code in PR #15090:
URL: https://github.com/apache/druid/pull/15090#discussion_r1348188109


##########
processing/src/main/java/org/apache/druid/timeline/partition/OvershadowableManager.java:
##########
@@ -418,9 +420,11 @@ private Iterator<Entry<RootPartitionRange, Short2ObjectSortedMap<AtomicUpdateGro
       TreeMap<RootPartitionRange, Short2ObjectSortedMap<AtomicUpdateGroup<T>>> stateMap
   )
   {
-    final RootPartitionRange lowFench = new RootPartitionRange(partitionId, partitionId);
+    // remediate submap `fromKey > toKey` issue when partitionId overflows
+    final short partitionIdLowFence = partitionId < 0 ? Short.MAX_VALUE : partitionId;

Review Comment:
   I think just checking the argument in the constructor of `RootPartitionRange` is enough. Since `RootPartitionRange` does not accept `startPartitionId` or `endPartitionId` less than 0, we will not have a case where `partitionId` passed to this method is less than 0.
   And even if it is, we should throw an exception rather than silently convert it to max value.



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


Re: [PR] Remediate ingestion failures when number of segments in time period is larger than 32767 (druid)

Posted by "dulu98Kurz (via GitHub)" <gi...@apache.org>.
dulu98Kurz commented on code in PR #15090:
URL: https://github.com/apache/druid/pull/15090#discussion_r1348855469


##########
processing/src/main/java/org/apache/druid/timeline/partition/OvershadowableManager.java:
##########
@@ -418,9 +420,11 @@ private Iterator<Entry<RootPartitionRange, Short2ObjectSortedMap<AtomicUpdateGro
       TreeMap<RootPartitionRange, Short2ObjectSortedMap<AtomicUpdateGroup<T>>> stateMap
   )
   {
-    final RootPartitionRange lowFench = new RootPartitionRange(partitionId, partitionId);
+    // remediate submap `fromKey > toKey` issue when partitionId overflows
+    final short partitionIdLowFence = partitionId < 0 ? Short.MAX_VALUE : partitionId;

Review Comment:
   Thanks for checking on this! @kfaraz , the [constructor](https://github.com/apache/druid/blob/master/processing/src/main/java/org/apache/druid/timeline/partition/OvershadowableManager.java#L1055C19-L1055C19) of `RootPartitionRange` that takes short type of `startPartitionId` was defined as `private` and we are forced to use :
   ```
   static RootPartitionRange of(int startPartitionId, int endPartitionId)
       {
         return new RootPartitionRange((short) startPartitionId, (short) endPartitionId);
       }
   ```
   Since `startPartitionId` is in Integer range, when `startPartitionId` > Short.MAV_VALUE ( 32767 ), the casting from int -> short start producing negative number, for example 
   <img width="304" alt="image" src="https://github.com/apache/druid/assets/14854898/26e91ef5-6f1e-4a5f-acbc-d99ea5ceb791">
   And the loop repeats when `startPartitionId` continued going because casting from Int to Short losses precision:
   <img width="201" alt="image" src="https://github.com/apache/druid/assets/14854898/9f6da102-ad6c-41d5-958c-817962ff6794">
   We happen to ran into this short overflow scenario described in https://github.com/apache/druid/issues/15091 and our ingestion task for new data was completely broken because of this, throwing exception would still make the ingestion fail.
   Here I'm making `startPartitionId` to be Short.MAX_VALUE so that it won't produce `java.lang.IllegalArgumentException: fromKey > toKey` and broke ingestion when we do `stateMap.subMap(lowFence, false, highFence, false)` , this is just an remediation.
   
   I believe a better way to handle this is to allow `startPartitionId` and `endPartitionId` to be integer and avoid the problematic precision-loss casting, I can send another PR to this solution if you can confirm why we had this `short` limit originally and it is appropriate to do so.
   
   Best,
   Dun



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


Re: [PR] Remediate ingestion failures when number of segments in time period is larger than 32767 (druid)

Posted by "dulu98Kurz (via GitHub)" <gi...@apache.org>.
dulu98Kurz commented on code in PR #15090:
URL: https://github.com/apache/druid/pull/15090#discussion_r1351512203


##########
processing/src/main/java/org/apache/druid/timeline/partition/OvershadowableManager.java:
##########
@@ -418,9 +420,11 @@ private Iterator<Entry<RootPartitionRange, Short2ObjectSortedMap<AtomicUpdateGro
       TreeMap<RootPartitionRange, Short2ObjectSortedMap<AtomicUpdateGroup<T>>> stateMap
   )
   {
-    final RootPartitionRange lowFench = new RootPartitionRange(partitionId, partitionId);
+    // remediate submap `fromKey > toKey` issue when partitionId overflows
+    final short partitionIdLowFence = partitionId < 0 ? Short.MAX_VALUE : partitionId;

Review Comment:
   Adding the PR that refactor partitionId from short to int so that we can compare the scope of changes
   https://github.com/apache/druid/pull/15116



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


Re: [PR] Remediate ingestion failures when number of segments in time period is larger than 32767 (druid)

Posted by "cryptoe (via GitHub)" <gi...@apache.org>.
cryptoe commented on PR #15090:
URL: https://github.com/apache/druid/pull/15090#issuecomment-1771211179

   @dulu98Kurz Thank you for the patience. Since most of the committers are busy with druid 28 things there might be some delay. 
   
   I think we have a ugly fail safe here. What I would prefer is to change the exception message to something nicer so that the user does not need to read through the druid's code base. 
   
   Like @abhishekagarwal87 32K partitions per interval just seem to massive and is generally an issue where in either compaction is lagging behind or late data is coming. 
   If we change this variable to int, the ticking time bomb has a larger impact and can lead to a full cluster outage where the number of segments in the cluster balloons up in millions.
   
   I think we we do want to change this to INT, we should add a guard rail to the number of partitions per interval from the implicit 32K to something larger maybe 50K ? 
   
   


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


Re: [PR] Remediate ingestion failures when number of segments in time period is larger than 32767 (druid)

Posted by "dulu98Kurz (via GitHub)" <gi...@apache.org>.
dulu98Kurz commented on code in PR #15090:
URL: https://github.com/apache/druid/pull/15090#discussion_r1350650766


##########
processing/src/main/java/org/apache/druid/timeline/partition/OvershadowableManager.java:
##########
@@ -418,9 +420,11 @@ private Iterator<Entry<RootPartitionRange, Short2ObjectSortedMap<AtomicUpdateGro
       TreeMap<RootPartitionRange, Short2ObjectSortedMap<AtomicUpdateGroup<T>>> stateMap
   )
   {
-    final RootPartitionRange lowFench = new RootPartitionRange(partitionId, partitionId);
+    // remediate submap `fromKey > toKey` issue when partitionId overflows
+    final short partitionIdLowFence = partitionId < 0 ? Short.MAX_VALUE : partitionId;

Review Comment:
   From code quality perspective, `Short.toUnsignedInt` is a precision-loss conversion and we used it in 2 files for 18 times, we can simplify the logic and improve readability if we change to `int`
   <img width="606" alt="image" src="https://github.com/apache/druid/assets/14854898/47a36432-d6fb-4f7e-9fdf-1610bf54e39b">
   
   Lastly, when partitionId is out of range, the [logic](https://github.com/apache/druid/blob/master/processing/src/main/java/org/apache/druid/timeline/partition/OvershadowableManager.java#L421-L423) we use to handle it right now is simply wrong:
   ```
   final RootPartitionRange lowFench = new RootPartitionRange(partitionId, partitionId);
   final RootPartitionRange highFence = new RootPartitionRange(Short.MAX_VALUE, Short.MAX_VALUE);
   return stateMap.subMap(lowFench, false, highFence, false).entrySet().iterator();
   ```
   For example when:
   <img width="304" alt="image" src="https://github.com/apache/druid/assets/14854898/03d6e2c1-ed5d-4e10-b708-e05699fb12f2">
   And  `stateMap.subMap(lowFench, false, highFence, false)` will return all entries instead of empty ...
   
   If we are ok with remediation in this PR, we can proceed with merging, if we are OK with refactoring please allow me to send another PR to fix it more completely.



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


Re: [PR] Remediate ingestion failures when number of segments in time period is larger than 32767 (druid)

Posted by "dulu98Kurz (via GitHub)" <gi...@apache.org>.
dulu98Kurz commented on PR #15090:
URL: https://github.com/apache/druid/pull/15090#issuecomment-1763802903

   Hi @kfaraz @abhishekagarwal87 sorry for being verbose on thread, I hope I had our issue well described , please let me know your thoughts, I`m open to any solutions that can keep our ingestion alive without deleting historical data.


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


Re: [PR] Remediate ingestion failures when number of segments in time period is larger than 32767 (druid)

Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #15090:
URL: https://github.com/apache/druid/pull/15090#issuecomment-1982083409

   This pull request has been marked as stale due to 60 days of inactivity.
   It will be closed in 4 weeks if no further activity occurs. If you think
   that's incorrect or this pull request should instead be reviewed, please simply
   write any comment. Even if closed, you can still revive the PR at any time or
   discuss it on the dev@druid.apache.org list.
   Thank you for your contributions.


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


Re: [PR] Remediate ingestion failures when number of segments in time period is larger than 32767 (druid)

Posted by "dulu98Kurz (via GitHub)" <gi...@apache.org>.
dulu98Kurz commented on code in PR #15090:
URL: https://github.com/apache/druid/pull/15090#discussion_r1349895468


##########
processing/src/main/java/org/apache/druid/timeline/partition/OvershadowableManager.java:
##########
@@ -418,9 +420,11 @@ private Iterator<Entry<RootPartitionRange, Short2ObjectSortedMap<AtomicUpdateGro
       TreeMap<RootPartitionRange, Short2ObjectSortedMap<AtomicUpdateGroup<T>>> stateMap
   )
   {
-    final RootPartitionRange lowFench = new RootPartitionRange(partitionId, partitionId);
+    // remediate submap `fromKey > toKey` issue when partitionId overflows
+    final short partitionIdLowFence = partitionId < 0 ? Short.MAX_VALUE : partitionId;

Review Comment:
   Hi @kfaraz thanks again for spending time on this! 
   Bumping again just in case you missed my last message , I‘m more than glad to if there’s anything need further clarification , I can also connect on a zoom call if it‘s convenient for you!
   
   Best Regards,
   Dun 



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


Re: [PR] Remediate ingestion failures when number of segments in time period is larger than 32767 (druid)

Posted by "dulu98Kurz (via GitHub)" <gi...@apache.org>.
dulu98Kurz commented on code in PR #15090:
URL: https://github.com/apache/druid/pull/15090#discussion_r1350650766


##########
processing/src/main/java/org/apache/druid/timeline/partition/OvershadowableManager.java:
##########
@@ -418,9 +420,11 @@ private Iterator<Entry<RootPartitionRange, Short2ObjectSortedMap<AtomicUpdateGro
       TreeMap<RootPartitionRange, Short2ObjectSortedMap<AtomicUpdateGroup<T>>> stateMap
   )
   {
-    final RootPartitionRange lowFench = new RootPartitionRange(partitionId, partitionId);
+    // remediate submap `fromKey > toKey` issue when partitionId overflows
+    final short partitionIdLowFence = partitionId < 0 ? Short.MAX_VALUE : partitionId;

Review Comment:
   From code quality perspective, `Short.toUnsignedInt` is a precision-loss conversion and we used it in 2 files for 18 times, we can simplify the logic and improve readability if we change to `int`
   <img width="606" alt="image" src="https://github.com/apache/druid/assets/14854898/47a36432-d6fb-4f7e-9fdf-1610bf54e39b">
   
   Lastly, when partitionId is out of range, the [logic](https://github.com/apache/druid/blob/master/processing/src/main/java/org/apache/druid/timeline/partition/OvershadowableManager.java#L421-L423) we use to handle it right now is simply wrong:
   ```
   final RootPartitionRange lowFench = new RootPartitionRange(partitionId, partitionId);
   final RootPartitionRange highFence = new RootPartitionRange(Short.MAX_VALUE, Short.MAX_VALUE);
   return stateMap.subMap(lowFench, false, highFence, false).entrySet().iterator();
   ```
   For example when:
   <img width="304" alt="image" src="https://github.com/apache/druid/assets/14854898/03d6e2c1-ed5d-4e10-b708-e05699fb12f2">
   And  `stateMap.subMap(lowFench, false, highFence, false)` will return all entries instead of empty ...



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


Re: [PR] Remediate ingestion failures when number of segments in time period is larger than 32767 (druid)

Posted by "dulu98Kurz (via GitHub)" <gi...@apache.org>.
dulu98Kurz commented on code in PR #15090:
URL: https://github.com/apache/druid/pull/15090#discussion_r1348855469


##########
processing/src/main/java/org/apache/druid/timeline/partition/OvershadowableManager.java:
##########
@@ -418,9 +420,11 @@ private Iterator<Entry<RootPartitionRange, Short2ObjectSortedMap<AtomicUpdateGro
       TreeMap<RootPartitionRange, Short2ObjectSortedMap<AtomicUpdateGroup<T>>> stateMap
   )
   {
-    final RootPartitionRange lowFench = new RootPartitionRange(partitionId, partitionId);
+    // remediate submap `fromKey > toKey` issue when partitionId overflows
+    final short partitionIdLowFence = partitionId < 0 ? Short.MAX_VALUE : partitionId;

Review Comment:
   Thanks for checking on this! @kfaraz , the [constructor](https://github.com/apache/druid/blob/master/processing/src/main/java/org/apache/druid/timeline/partition/OvershadowableManager.java#L1055C19-L1055C19) of `RootPartitionRange` that takes short type of `startPartitionId` was defined as `private` and we are forced to use :
   ```
   static RootPartitionRange of(int startPartitionId, int endPartitionId)
       {
         return new RootPartitionRange((short) startPartitionId, (short) endPartitionId);
       }
   ```
   Since `startPartitionId` is in Integer range, when `startPartitionId` > Short.MAV_VALUE ( 32767 ), the casting from int -> short start producing negative number, for example 
   <img width="304" alt="image" src="https://github.com/apache/druid/assets/14854898/26e91ef5-6f1e-4a5f-acbc-d99ea5ceb791">
   And the loop repeats when `startPartitionId` continued going because casting from Int to Short losses precision:
   <img width="201" alt="image" src="https://github.com/apache/druid/assets/14854898/9f6da102-ad6c-41d5-958c-817962ff6794">
   We happen to ran into this short overflow scenario described in https://github.com/apache/druid/issues/15091 and our ingestion task for new data was completely broken because of this, throwing exception would still make the ingestion fail.
   Here I'm making `startPartitionId` to be Short.MAX_VALUE so that it won't produce `java.lang.IllegalArgumentException: fromKey > toKey` when we do `stateMap.subMap(lowFence, false, highFence, false)` , this is just an remediation.
   
   I believe a better way to handle this is to allow `startPartitionId` and `endPartitionId` to be integer and avoid the problematic precision-loss casting, I can send another PR to this solution if you can confirm why we had this `short` limit originally and it is appropriate to do so.
   
   Best,
   Dun



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


Re: [PR] Remediate ingestion failures when number of segments in time period is larger than 32767 (druid)

Posted by "dulu98Kurz (via GitHub)" <gi...@apache.org>.
dulu98Kurz commented on PR #15090:
URL: https://github.com/apache/druid/pull/15090#issuecomment-1773713402

   Hi @cryptoe @abhishekagarwal87 @kfaraz , please find updates in PR (https://github.com/apache/druid/pull/15116) , it includes changes as per discussion:
   1. More informative exception language
   2. Refactored partitionId in `RootPartitionRange` from `short` to `int`, but with a max value of 65536 to prevent memory pressure out of control.
   3. Removed unnecessary problematic `short` to `int` conversion.
   
   Please let me know for any concerns, I`ll close this PR when https://github.com/apache/druid/pull/15116 is merged.


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


Re: [PR] Remediate ingestion failures when number of segments in time period is larger than 32767 (druid)

Posted by "abhishekagarwal87 (via GitHub)" <gi...@apache.org>.
abhishekagarwal87 commented on code in PR #15090:
URL: https://github.com/apache/druid/pull/15090#discussion_r1350003044


##########
processing/src/main/java/org/apache/druid/timeline/partition/OvershadowableManager.java:
##########
@@ -418,9 +420,11 @@ private Iterator<Entry<RootPartitionRange, Short2ObjectSortedMap<AtomicUpdateGro
       TreeMap<RootPartitionRange, Short2ObjectSortedMap<AtomicUpdateGroup<T>>> stateMap
   )
   {
-    final RootPartitionRange lowFench = new RootPartitionRange(partitionId, partitionId);
+    // remediate submap `fromKey > toKey` issue when partitionId overflows
+    final short partitionIdLowFence = partitionId < 0 ? Short.MAX_VALUE : partitionId;

Review Comment:
   @dulu98Kurz - I am not entirely sure but `short` was likely chosen to save on memory that storing these ids will take. 32K partitions in one single interval is too high. Can you describe a bit more as to how your cluster ends up in this situation and why is that a genuine scenario? In my experience, almost every time, an interval touching this high number means that compaction is not configured or ingestion is misconfigured. 



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


Re: [PR] Remediate ingestion failures when number of segments in time period is larger than 32767 (druid)

Posted by "dulu98Kurz (via GitHub)" <gi...@apache.org>.
dulu98Kurz commented on code in PR #15090:
URL: https://github.com/apache/druid/pull/15090#discussion_r1349895468


##########
processing/src/main/java/org/apache/druid/timeline/partition/OvershadowableManager.java:
##########
@@ -418,9 +420,11 @@ private Iterator<Entry<RootPartitionRange, Short2ObjectSortedMap<AtomicUpdateGro
       TreeMap<RootPartitionRange, Short2ObjectSortedMap<AtomicUpdateGroup<T>>> stateMap
   )
   {
-    final RootPartitionRange lowFench = new RootPartitionRange(partitionId, partitionId);
+    // remediate submap `fromKey > toKey` issue when partitionId overflows
+    final short partitionIdLowFence = partitionId < 0 ? Short.MAX_VALUE : partitionId;

Review Comment:
   Hi @kfaraz thanks again for spending time on this! 
   Bumping again just in case you missed my last message , I`m more than glad to if there`s anything need further clarification , I can also connect on a zoom call if it`s convenient for you!
   
   Best Regards,
   Dun 



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


Re: [PR] Remediate ingestion failures when number of segments in time period is larger than 32767 (druid)

Posted by "dulu98Kurz (via GitHub)" <gi...@apache.org>.
dulu98Kurz commented on code in PR #15090:
URL: https://github.com/apache/druid/pull/15090#discussion_r1350608551


##########
processing/src/main/java/org/apache/druid/timeline/partition/OvershadowableManager.java:
##########
@@ -418,9 +420,11 @@ private Iterator<Entry<RootPartitionRange, Short2ObjectSortedMap<AtomicUpdateGro
       TreeMap<RootPartitionRange, Short2ObjectSortedMap<AtomicUpdateGroup<T>>> stateMap
   )
   {
-    final RootPartitionRange lowFench = new RootPartitionRange(partitionId, partitionId);
+    // remediate submap `fromKey > toKey` issue when partitionId overflows
+    final short partitionIdLowFence = partitionId < 0 ? Short.MAX_VALUE : partitionId;

Review Comment:
   So instead of capping at `short` max, we can possibly cover the gap by:
   - Allowing partitionId goes into `Int` range
   - Logging error messages to strongly remind user we need to compact/reduce num of segments.
   
   For users who do not have late messages or compaction issues, this change has no impact to them because they won't store more than `short` max segments anyway, so we don`t break the initial intension of saving on mem.
   
   For users who actually can produce segments beyond `short` max, this will buy them more time to compact/reduc number of segments, which may eventually avoid the difficult situation 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.

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


Re: [PR] Remediate ingestion failures when number of segments in time period is larger than 32767 (druid)

Posted by "dulu98Kurz (via GitHub)" <gi...@apache.org>.
dulu98Kurz commented on PR #15090:
URL: https://github.com/apache/druid/pull/15090#issuecomment-1771949769

   @cryptoe thanks for checking on this!
   Agreed, letting the segments number growing wildly to the Integer MAX would definitely accumulate a bigger problem.
   
   I`ll update the PR to include a CAP of 50K or 65536(if we want to go by binary convention), also making the exception message more meaningful, will send update soon, thanks again for attention! @cryptoe 


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


Re: [PR] Remediate ingestion failures when number of segments in time period is larger than 32767 (druid)

Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #15090:
URL: https://github.com/apache/druid/pull/15090#issuecomment-2038484838

   This pull request/issue has been closed due to lack of activity. If you think that
   is incorrect, or the pull request requires review, you can revive the PR at any time.


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


Re: [PR] Remediate ingestion failures when number of segments in time period is larger than 32767 (druid)

Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] closed pull request #15090: Remediate ingestion failures when number of segments in time period is larger than 32767
URL: https://github.com/apache/druid/pull/15090


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