wjhypo opened a new pull request #11307:
URL: https://github.com/apache/druid/pull/11307


   <!-- 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 #11301
   
   <!-- 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: -->
   
   
   
   - Choice of algorithms
   
   If `enableInMemoryBitmap` is set to true in `tuningConfig` in the supervisor 
spec, a bitmap is maintained during the data is in incremental index for each 
dimension that uses bitmap in the schema, i.e., for a dimension, only if bitmap 
is to be created when creating the immutable segment during handoff, will a 
corresponding temporary in memory bitmap be created.
   
   This in memory bitmap is not serialized or reused during persistence to 
completely separate from the other bitmap created in the immutable segment for 
clean logic separation.
   
   In terms of the implementation of this in memory bitmap, currently user 
can't specify it anywhere and only Roaring bitmap is used as the default 
implementation. The PR doesn't add choices to pick other compressed bitmaps 
like Concise Bitmap because we don't see clear performance benefits to add 
other implementations at the moment.
   
   In terms of the implementation of Roaring bitmap, there are 3 
implementations available in the Roaring bitmap library: 
`MutableRoaringBitmap`, `ImmutableRoaringBitmap` and `RoaringBitmap`. 
`RoaringBitmap` is supposed to be more performant than the other two in this 
case because it doesn't need to maintain a byte buffer backend and byte buffer 
backend is only convenient if we need to do mmap or if there's serde involved, 
which is the case for batch ingested immutable segments querying. However, the 
implementation in the PR tries reusing the logic in the current classes built 
for the batch ingested immutable segments, so the byte buffer backed 
implementation `MutableRoaringBitmap` is used to store row indexes for each new 
rows. During query time, a snapshot of the bitmap is needed so 
`MutableRoaringBitmap` is cast to `ImmutableRoaringBitmap`, which involves 
copying at one of the stages of the conversion. During the copy, for high 
cardinality dimensions, the number of row indexes for
  a given row value should be small so the copying overhead should be minimal; 
for low cardinality dimensions, supposedly there are more data to copy than the 
previous case, we don't see obvious issue during testing and we can add metrics 
on the copying time and as long as the benefit outweigh the no bitmap full scan 
case, it should still be worthwhile.
   
    - Behavioral aspects. What configuration values are acceptable? How are 
corner cases and error conditions handled, such as when there are insufficient 
resources?
   
    Step 1: enable in memory bitmap construction in supervisor spec
   ```
   {
     "type": "kafka",
     "tuningConfig": {
       ...
       "enableInMemoryBitmap": true
       ...
     }
   }
   ```
   
   Step 2: during query time, add a flag in query context (default is false) to 
determine if to use the in memory bitmap index (if enabled in step 1):
   `"useInMemoryBitmapInQuery": true`
   
   If either configuration is `false` or not specified will not trigger the 
usage of in memory bitmap during query time.
   
    - Class organization and design (how the logic is split between classes, 
inheritance, composition, design patterns)
   
    The implementation tries piggybacking on the bitmap query related classes 
of batch generated immutable segment index (QueryableIndex and its support 
classes) as much as possible to reduce duplicate work.
   
   <!--
    - 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. 
   
   <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:
   - [x] 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.
   - [ ] added Javadocs for most classes and all non-trivial methods. Linked 
related entities via Javadoc links.
   - [ ] added comments explaining the "why" and the intent of the code 
wherever would not be obvious for an unfamiliar reader.
   - [x] 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.
   - [x] 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.

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