-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[WIP]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
base: trunk
Are you sure you want to change the base?
Conversation
Hello @junrao, @chia7712 I think there are two possible approaches to resolve this:
|
@m1a2st : Perhaps we could somehow allow the tests to set a small |
Maybe we can add a internal config to allow tests to define small size? |
for example: this.internalSegmentSize = getString(TopicConfig.INTERNAL_SEGMENT_BYTES_CONFIG);
...
public long segmentSize() {
if (internalSegmentSize != null) return Long.parseLong(internalSegmentSize);
return segmentMs;
} |
@m1a2st could you please check the failed tests? |
There was a problem hiding this 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.
storage/src/main/java/org/apache/kafka/storage/internals/log/LogConfig.java
Outdated
Show resolved
Hide resolved
} | ||
|
||
// visible for testing | ||
def internalApply( |
There was a problem hiding this comment.
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
?
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
- remove
METADATA_LOG_SEGMENT_MIN_BYTES_CONFIG
- remove
MetadataLogConfig#logSegmentMinBytes
- add
internal.metadata.log.segment.bytes
- customize
MetadataLogConfig#logSegmentBytes
as following code
public int logSegmentBytes() {
if (internalSogSegmentBytes != null) return internalSogSegmentBytes;
return logSegmentBytes;
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, why do we need internalApply()
? MetadataLogConfig has both the product and internal segment bytes configs and we could just pass both into LogConfig in apply()
, right?
# Conflicts: # core/src/main/scala/kafka/raft/KafkaMetadataLog.scala
There was a problem hiding this 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 updated PR. A few more comments.
@@ -85,14 +82,13 @@ public class MetadataLogConfig { | |||
.define(METADATA_SNAPSHOT_MAX_INTERVAL_MS_CONFIG, LONG, METADATA_SNAPSHOT_MAX_INTERVAL_MS_DEFAULT, atLeast(0), HIGH, METADATA_SNAPSHOT_MAX_INTERVAL_MS_DOC) | |||
.define(METADATA_LOG_DIR_CONFIG, STRING, null, null, HIGH, METADATA_LOG_DIR_DOC) | |||
.define(METADATA_LOG_SEGMENT_BYTES_CONFIG, INT, METADATA_LOG_SEGMENT_BYTES_DEFAULT, atLeast(Records.LOG_OVERHEAD), HIGH, METADATA_LOG_SEGMENT_BYTES_DOC) | |||
.defineInternal(METADATA_LOG_SEGMENT_MIN_BYTES_CONFIG, INT, METADATA_LOG_SEGMENT_MIN_BYTES_DEFAULT, atLeast(Records.LOG_OVERHEAD), HIGH, METADATA_LOG_SEGMENT_MIN_BYTES_DOC) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We need to set the constraint for METADATA_LOG_SEGMENT_BYTES_CONFIG to be at least 8MB.
Also, I thought the plan is to remove METADATA_LOG_SEGMENT_MIN_BYTES_CONFIG, but add sth like METADATA_INTERNAL_LOG_SEGMENT_BYTES_CONFIG to match the design in LogConfig?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
val metadataLog: KafkaMetadataLog = createMetadataLog(topicPartition, topicId, dataDir, time, scheduler, config, nodeId, defaultLogConfig) | ||
|
||
// Print a warning if users have overridden the internal config | ||
if (config.logSegmentBytes() != KafkaRaftClient.MAX_BATCH_SIZE_BYTES) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, we don't need this if we add the constraint directly to METADATA_LOG_SEGMENT_BYTES_CONFIG, right?
@@ -112,15 +108,15 @@ public class MetadataLogConfig { | |||
* @param deleteDelayMillis The amount of time to wait before deleting a file from the filesystem | |||
*/ | |||
public MetadataLogConfig(int logSegmentBytes, | |||
int logSegmentMinBytes, | |||
int internalLogSegmentMinBytes, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, this should be renamed to internalLogSegmentBytes since it's no longer the minimum, right?
} | ||
|
||
// visible for testing | ||
def internalApply( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, why do we need internalApply()
? MetadataLogConfig has both the product and internal segment bytes configs and we could just pass both into LogConfig in apply()
, right?
@@ -601,7 +602,7 @@ class SaslSslAdminIntegrationTest extends BaseAdminIntegrationTest with SaslSetu | |||
assertNotEquals(Uuid.ZERO_UUID, createResult.topicId(topic1).get()) | |||
assertEquals(topicIds(topic1), createResult.topicId(topic1).get()) | |||
assertFutureThrows(classOf[TopicAuthorizationException], createResult.topicId(topic2)) | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please revert unrelated change
@@ -567,7 +568,7 @@ class SaslSslAdminIntegrationTest extends BaseAdminIntegrationTest with SaslSetu | |||
client.createAcls(List(denyAcl).asJava, new CreateAclsOptions()).all().get() | |||
|
|||
val topics = Seq(topic1, topic2) | |||
val configsOverride = Map(TopicConfig.SEGMENT_BYTES_CONFIG -> "100000").asJava | |||
val configsOverride = Map(LogConfig.INTERNAL_SEGMENT_BYTES_CONFIG -> "100000").asJava |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this test case is used to verify the custom topic-level config, so we can increase the value to make test pass.
public static final String METADATA_LOG_SEGMENT_BYTES_CONFIG = "metadata.log.segment.bytes"; | ||
public static final String METADATA_LOG_SEGMENT_BYTES_DOC = "The maximum size of a single metadata log file."; | ||
public static final int METADATA_LOG_SEGMENT_BYTES_DEFAULT = 1024 * 1024 * 1024; | ||
|
||
public static final String INTERNAL_METADATA_LOG_SEGMENT_BYTES_CONFIG = "internal.metadata.log.segment.bytes"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need another internal config? User can configure internal.segment.bytes
if they want to create small segment, right?
The main reason is that we forgot setting the
TopicConfig.SEGMENT_BYTES_CONFIG
at least to1024 * 1024
, thusaddressed it, and add a test for it.