-
Notifications
You must be signed in to change notification settings - Fork 14k
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
KAFKA-18013: Add AutoOffsetResetStrategy internal class #17858
base: trunk
Are you sure you want to change the base?
Conversation
5fb0ba3
to
ab1a138
Compare
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.
Made a pass
|
||
// This may be null if the task we are currently processing was apart of a named topology that was just removed. | ||
// TODO KAFKA-13713: keep the StreamThreads and TopologyMetadata view of named topologies in sync until final thread has acked | ||
if (offsetResetStrategy != null) { | ||
switch (offsetResetStrategy) { | ||
case EARLIEST: | ||
switch (offsetResetStrategy.name()) { |
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.
Why do we need to switch to name()
here and do a string comparison? Can't we keep an enum comparison?
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.
As mentioned in other comment, enum wont help much here. We will be having different instances DurationBasedStrategy class. I have the updated code to avoid string comparisons.
public class AutoOffsetResetStrategy { | ||
public static final String EARLIEST_STRATEGY_NAME = "earliest"; | ||
public static final String LATEST_STRATEGY_NAME = "latest"; | ||
public static final String NONE_STRATEGY_NAME = "none"; |
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.
Should we still have an internal enum
for the different strategies, to avoid doing string comparisons?
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.
Enum wont help us as we still need to parse strings like `by_duration:PnDTnHnMn. n>. I prefer to keep string names for now. I will update in next PR if required. I will update code avoid string comparison in SteamsThread class
assertTrue(AutoOffsetResetStrategy.isValid("none")); | ||
assertFalse(AutoOffsetResetStrategy.isValid("invalid")); | ||
assertFalse(AutoOffsetResetStrategy.isValid("LATEST")); | ||
assertFalse(AutoOffsetResetStrategy.isValid("")); |
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.
Should we add a test case for null
?
assertEquals(AutoOffsetResetStrategy.NONE, AutoOffsetResetStrategy.valueOf("none")); | ||
assertThrows(IllegalArgumentException.class, () -> AutoOffsetResetStrategy.valueOf("invalid")); | ||
assertThrows(IllegalArgumentException.class, () -> AutoOffsetResetStrategy.valueOf("LATEST")); | ||
assertThrows(IllegalArgumentException.class, () -> AutoOffsetResetStrategy.valueOf("")); |
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.
Should we add a test case for null
?
assertDoesNotThrow(() -> validator.ensureValid("test", "none")); | ||
assertThrows(ConfigException.class, () -> validator.ensureValid("test", "invalid")); | ||
assertThrows(ConfigException.class, () -> validator.ensureValid("test", "LATEST")); | ||
assertThrows(ConfigException.class, () -> validator.ensureValid("test", "")); |
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.
null
?
|
||
public static final AutoOffsetResetStrategy EARLIEST = new AutoOffsetResetStrategy(EARLIEST_STRATEGY_NAME); | ||
public static final AutoOffsetResetStrategy LATEST = new AutoOffsetResetStrategy(LATEST_STRATEGY_NAME); | ||
public static final AutoOffsetResetStrategy NONE = new AutoOffsetResetStrategy(NONE_STRATEGY_NAME); |
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.
If we use an enum
we don't need this boiler plate objects?
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.
These are not boilerplate objects. These are static instances to represent current strategies.
The main reason for converting enum into class is to allow us to add additional reset strategies with some properties.
For example, we will be adding new class like below to represent duration based reset strategy:
DurationBasedOffsetResetStrategy extends AutoOffsetResetStrategy {
DurationBasedOffsetResetStrategy(String name, String isoDuration) {
}
}
ab1a138
to
85dbf98
Compare
This is preparatory change for KIP-1106.
This PR:
There are no functionality changes. We will add duration based offset reset support in subsequent PRs.