Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Public Interfaces

  • Plan is to add 4 3 enumeration values ​​to OffsetResetStrategy to represent four different strategies.

    Code Block
    languagejava
    firstline1
    titleOffsetResetStrategy.java
    linenumberstrue
    collapsetrue
    package org.apache.kafka.clients.consumer;
    
    import java.util.Locale;
    
    public enum OffsetResetStrategy {
        LATEST, EARLIEST, NONE, LATEST_ON_START, EARLIEST_ON_START, SAFE_LATEST;
    
        @Override
        public String toString() {
            return super.toString().toLowerCase(Locale.ROOT);
        }
    }


  • Add an additional enum class named OutOfRangeOffsetResetStrategy to represent strategies for handling out-of-range.

    Code Block
    languagejava
    firstline1
    titleOutOfRangeOffsetResetStrategy.java
    linenumberstrue
    collapsetrue
    package org.apache.kafka.clients.consumer;
    
    import java.util.Locale;
    
    public enum OutOfRangeOffsetResetStrategy {
        NONE, NEAREST;
    
        @Override
        public String toString() {
            return super.toString().toLowerCase(Locale.ROOT);
        }
    }


  • Then add a new consumer config named "offset.reset.strategy.offset-out-of-range"

    Code Block
    languagejava
    firstline1
    titleConsumerConfig
    linenumberstrue
    collapsetrue
    public static final String OUT_OF_RANGE_OFFSET_RESET_CONFIG = "offset.reset.strategy.offset-out-of-range";
    private static final String OUT_OF_RANGE_OFFSET_RESET_CONFIG_DOC = "If not NONE, then out of range errors will reset the consumer's offset according to strategy. For example of NEAREST, to the earliest end of the broker range if it was under the range, or to the latest end of the broker range if it was over the range";
    
    CONFIG = new ConfigDef().define(OUT_OF_RANGE_OFFSET_RESET_CONFIG,
                                    Type.STRING,
                                    OutOfRangeOffsetResetStrategy.NONE.toString(),
                                    in(Utils.enumOptions(OutOfRangeOffsetResetStrategy.class)),
                                    Importance.MEDIUM,
                                    OUT_OF_RANGE_OFFSET_RESET_CONFIG_DOC)


...

The first scenario is reset offset without committed offsets:

offset reset strategycurrent reset behaviorproposed reset behavior
nonethrow exceptionthrow exception
earliestreset to earliestreset to earliest
latestreset to latestreset to latest
earliest_on_startN/Areset to earliest
latest_on_startN/Areset to latest
safe_latestN/A

if group is started newly, reset to latest.

if some new partitions is expanded when group is consuming, reset to earliest for these new partitions.

nearest(offset.reset.strategy.offset-out-of-range)N/Ait only effect when trigger for out-of-range, for this scenario, its behavior is determined by the earliest, or latest, or safe_latest used together.

The other is when an out of range exception is triggered:

offset reset strategycurrent reset behaviorproposed reset behavior
nonethrow exceptionthrow exception
earliestreset to earliestreset to earliest
latestreset to latestreset to latest
earliest_on_startN/Athrow exception
latest_on_startN/Athrow exception
safe_latestN/Areset to latest, consistent with latest.
nearest(offset.reset.strategy.offset-out-of-range)N/Ato the earliest if it was under the range, or to the latest if it was over the range. It has nothing to do with the earliest, or latest, or safe_latest used together.

Compatibility, Deprecation, and Migration Plan

...