-
Notifications
You must be signed in to change notification settings - Fork 15.4k
KAFKA-9700:Fix negative estimatedCompressionRatio issue #8285
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 4 commits
61ae126
36d7cb7
f998cdf
0153dc7
7a34d39
e50dfdc
537c402
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,63 @@ | ||
| /* | ||
| * Licensed to the Apache Software Foundation (ASF) under one or more | ||
| * contributor license agreements. See the NOTICE file distributed with | ||
| * this work for additional information regarding copyright ownership. | ||
| * The ASF licenses this file to You under the Apache License, Version 2.0 | ||
| * (the "License"); you may not use this file except in compliance with | ||
| * the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
| package org.apache.kafka.common.record; | ||
|
|
||
| import org.junit.Test; | ||
| import static org.junit.Assert.assertTrue; | ||
|
|
||
| public class CompressionRatioEstimatorTest { | ||
| @Test | ||
| public void testUpdateEstimation() { | ||
| String topic = "tp"; | ||
| class EstimationsObservedRatios { | ||
| float currentEstimation; | ||
| float observedRatio; | ||
| float expected; | ||
| EstimationsObservedRatios(float currentEstimation, float observedRatio, float expected) { | ||
| this.currentEstimation = currentEstimation; | ||
| this.observedRatio = observedRatio; | ||
| this.expected = expected; | ||
| } | ||
| } | ||
|
|
||
| // Method updateEstimation is to update compressionRatioForTopic according to observedRatio and currentEstimation. | ||
| // If currentEstimation is smaller than observedRatio, update compressionRatioForTopic to | ||
| // Math.max(currentEstimation + COMPRESSION_RATIO_DETERIORATE_STEP, observedRatio) | ||
| // If currentEstimation is larger than observedRatio, update compressionRatioForTopic to | ||
| // Math.max(currentEstimation - COMPRESSION_RATIO_IMPROVING_STEP, observedRatio). | ||
| // COMPRESSION_RATIO_DETERIORATE_STEP is 0.05f. COMPRESSION_RATIO_IMPROVING_STEP is 0.005f. | ||
| // There are four cases: | ||
| // 1. currentEstimation < observedRatio && (currentEstimation + COMPRESSION_RATIO_DETERIORATE_STEP) < observedRatio | ||
| // 2. currentEstimation < observedRatio && (currentEstimation + COMPRESSION_RATIO_DETERIORATE_STEP) > observedRatio | ||
| // 3. currentEstimation > observedRatio && (currentEstimation - COMPRESSION_RATIO_IMPROVING_STEP) > observedRatio | ||
| // 4. currentEstimation > observedRatio && (currentEstimation - COMPRESSION_RATIO_IMPROVING_STEP) < observedRatio | ||
| // In all cases, updatedCompressionRatio shouldn't smaller than observedRatio | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It seems like we are duplicating a lot of the logic of the code in this comment. This is likely to get stale over time. Can we make the comment more concise and refer to the non test code for more detail? |
||
| EstimationsObservedRatios[] currentEstimationsObservedRatios = new EstimationsObservedRatios[] { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If we use a |
||
| new EstimationsObservedRatios(0.8f, 0.84f, 0.84f), | ||
| new EstimationsObservedRatios(0.6f, 0.7f, 0.7f), | ||
| new EstimationsObservedRatios(0.6f, 0.4f, 0.4f), | ||
| new EstimationsObservedRatios(0.004f, 0.001f, 0.001f) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It seems that |
||
| }; | ||
|
|
||
| float updatedCompressionRatio; | ||
| for (int i = 0; i < currentEstimationsObservedRatios.length; i++) { | ||
| CompressionRatioEstimator.setEstimation(topic, CompressionType.ZSTD, currentEstimationsObservedRatios[i].currentEstimation); | ||
| updatedCompressionRatio = CompressionRatioEstimator.updateEstimation(topic, CompressionType.ZSTD, currentEstimationsObservedRatios[i].observedRatio); | ||
| assertTrue(updatedCompressionRatio >= currentEstimationsObservedRatios[i].expected); | ||
| } | ||
| } | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.