Skip to content

KAFKA-19080 The constraint on segment.ms is not enforced at topic level #19371

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

Open
wants to merge 31 commits into
base: trunk
Choose a base branch
from

Conversation

m1a2st
Copy link
Collaborator

@m1a2st m1a2st commented Apr 4, 2025

The main reason is that we forgot setting the
TopicConfig.SEGMENT_BYTES_CONFIG at least to 1024 * 1024, thus
addressed it, and add a test for it.

@github-actions github-actions bot added triage PRs from the community tools storage Pull requests that target the storage module small Small PRs labels Apr 4, 2025
@m1a2st m1a2st changed the title KAFKA-19080 The constraint on segment.ms is not enforced at topic level [WIP]KAFKA-19080 The constraint on segment.ms is not enforced at topic level Apr 4, 2025
@github-actions github-actions bot added the core Kafka Broker label Apr 4, 2025
@m1a2st
Copy link
Collaborator Author

m1a2st commented Apr 4, 2025

Hello @junrao, @chia7712
I have a question about this problem.
In KAFKA-16368, only the ServerLogConfigs value for log.segment.bytes was modified to 1 MB. However, the TopicConfig which in LogConfig default for segment.bytes remains 14 bytes. Many tests rely on this small segment.bytes value to generate a large number of segments.

I think there are two possible approaches to resolve this:

  1. Add atLeast(1024 * 1024) validation in LogConfig, which would require fixing around 400 tests.
  2. Add a validator in LogManager#updateTopicConfig to validate the change request at runtime.

@junrao
Copy link
Contributor

junrao commented Apr 9, 2025

@m1a2st : Perhaps we could somehow allow the tests to set a small segment.bytes.

@github-actions github-actions bot removed the small Small PRs label Apr 9, 2025
@chia7712
Copy link
Member

chia7712 commented Apr 9, 2025

Maybe we can add a internal config to allow tests to define small size?

@chia7712
Copy link
Member

for example:

   this.internalSegmentSize = getString(TopicConfig.INTERNAL_SEGMENT_BYTES_CONFIG);

   ...
   
    public long segmentSize() {
        if (internalSegmentSize != null) return Long.parseLong(internalSegmentSize);
        return segmentMs;
    }

@m1a2st m1a2st changed the title [WIP]KAFKA-19080 The constraint on segment.ms is not enforced at topic level KAFKA-19080 The constraint on segment.ms is not enforced at topic level Apr 11, 2025
@m1a2st
Copy link
Collaborator Author

m1a2st commented Apr 11, 2025

Thanks for @junrao, @chia7712 comments, This PR is already for review, PTAL.

m1a2st added 4 commits April 11, 2025 19:53
# Conflicts:
#	core/src/main/scala/kafka/log/LogCleaner.scala
#	storage/src/main/java/org/apache/kafka/storage/internals/log/LogConfig.java
Copy link

A label of 'needs-attention' was automatically added to this PR in order to raise the
attention of the committers. Once this issue has been triaged, the triage label
should be removed to prevent this automation from happening again.

@@ -214,6 +214,9 @@ public class TopicConfig {
"configuration. If message.timestamp.type=CreateTime, the message will be rejected if the difference in " +
"timestamps exceeds this specified threshold. This configuration is ignored if message.timestamp.type=LogAppendTime.";

// visible for testing
public static final String INTERNAL_SEGMENT_BYTES_CONFIG = "internal.segment.bytes";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TopicConfig is a public class, so could you please move it to LogConfig?

@github-actions github-actions bot removed needs-attention triage PRs from the community labels Apr 15, 2025
@chia7712
Copy link
Member

@m1a2st could you please check the failed tests?

Copy link
Contributor

@junrao junrao left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@m1a2st : Thanks for the PR. Left a couple of comments.

@@ -186,12 +188,13 @@ public Optional<String> serverConfigName(String configName) {
.define(ServerLogConfigs.CREATE_TOPIC_POLICY_CLASS_NAME_CONFIG, CLASS, null, LOW, ServerLogConfigs.CREATE_TOPIC_POLICY_CLASS_NAME_DOC)
.define(ServerLogConfigs.ALTER_CONFIG_POLICY_CLASS_NAME_CONFIG, CLASS, null, LOW, ServerLogConfigs.ALTER_CONFIG_POLICY_CLASS_NAME_DOC)
.define(ServerLogConfigs.LOG_DIR_FAILURE_TIMEOUT_MS_CONFIG, LONG, ServerLogConfigs.LOG_DIR_FAILURE_TIMEOUT_MS_DEFAULT, atLeast(1), LOW, ServerLogConfigs.LOG_DIR_FAILURE_TIMEOUT_MS_DOC)
.defineInternal(ServerLogConfigs.LOG_INITIAL_TASK_DELAY_MS_CONFIG, LONG, ServerLogConfigs.LOG_INITIAL_TASK_DELAY_MS_DEFAULT, atLeast(0), LOW, ServerLogConfigs.LOG_INITIAL_TASK_DELAY_MS_DOC);
.defineInternal(ServerLogConfigs.LOG_INITIAL_TASK_DELAY_MS_CONFIG, LONG, ServerLogConfigs.LOG_INITIAL_TASK_DELAY_MS_DEFAULT, atLeast(0), LOW, ServerLogConfigs.LOG_INITIAL_TASK_DELAY_MS_DOC)
.defineInternal(LogConfig.INTERNAL_SEGMENT_BYTES_CONFIG, INT, null, null, LOW, ServerLogConfigs.LOG_SEGMENT_BYTES_DOC);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we document that this config is for testing?

}

// visible for testing
def internalApply(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of having an internalApply, could we just use the existing apply and add INTERNAL_SEGMENT_BYTES_CONFIG to MetadataLogConfig?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1 to move the internal config to MetadataLogConfig, and it would be better to wait #19465 extracting the metadata-related configs from other class to MetadataLogConfig

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just realized that metadata log uses a different approach to allow tests to use a smaller segment bytes than allowed in production. That approach defines the original segment byte config with a small minimal requirement, but adds METADATA_LOG_SEGMENT_MIN_BYTES_CONFIG to enforce the actual minimal requirement in production. This new config could be changed in tests to allow for smaller minimal bytes. The benefit of this approach is that it allows the existing config to be used directly to set a smaller value for tests. The downside is that the doc for min value is inaccurate and the validation is done through a customized logic.

It would be useful to pick the same strategy between metadata log and regular log. The metadata log approach seems slightly better since it's less intrusive. We could fix the inaccurate min value description for production somehow.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Excuse me, the strategy used by metadata log is to add a "internal" config (METADATA_LOG_SEGMENT_MIN_BYTES_CONFIG) to change the (metadata) segment size in testing, and that is what we want to address in this PR - we add a "internal" config for regular log, and so the test can use the "smaller" segment size.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am just saying that we now have two different ways to achieve the same goal. In the metadata log approach, you set the desired value through the original config, which is segment.bytes. You then set an internal config to change the min constraint.

The approach in this PR is to set the desired value through a different internal config.

It would be useful to choose same approach for both the metadata log and the regular log.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Personally, I prefer the approach of adding "internal".xxx config as it provide better user experience for public configs, allowing users to see the "correct" min value. Additionally, we can remove the customized logic of validation.

In short, I suggest to add following changes to this PR.

  1. remove METADATA_LOG_SEGMENT_MIN_BYTES_CONFIG
  2. remove MetadataLogConfig#logSegmentMinBytes
  3. add internal.metadata.log.segment.bytes
  4. customize MetadataLogConfig#logSegmentBytes as following code
    public int logSegmentBytes() {
        if (internalSogSegmentBytes != null) return internalSogSegmentBytes;
        return logSegmentBytes;
    }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clients core Kafka Broker KIP-932 Queues for Kafka kraft storage Pull requests that target the storage module streams tools
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants