Skip to content

commit offset failed with No offset stored #295

Description

@joukosusi

Description

I create a new topic and try to commit offset on it with three different values: -2, -1, 99, but only 99 worked, others occurred 'Commit failed: Local: No offset stored'。I'm confused on it, could someone help me on this?

confluent-kafka-python: ('0.11.0', 720896)
libversion: ('0.11.3', 721919)
kafka : 0.10.2.1

log:
RESET offset to -2 for topic topic.sucl.new(0) commit offsets: [TopicPartition{topic=topic.sucl.new,partition=0,offset=-2,error=None}] COMMIT: commit offset failed with message: _NO_OFFSET(-168) >> Commit failed: Local: No offset stored
RESET offset to -1 for topic topic.sucl.new(0) commit offsets: [TopicPartition{topic=topic.sucl.new,partition=0,offset=-1,error=None}] COMMIT: commit offset failed with message: _NO_OFFSET(-168) >> Commit failed: Local: No offset stored
RESET offset to 99 for topic topic.sucl.new(0) commit offsets: [TopicPartition{topic=topic.sucl.new,partition=0,offset=99,error=None}]

How to reproduce

`

client = Test(
                hosts='xxx:9093',
                ssl_path=xxxx,
                passwd=None,
                logger=log.LogHandler('test', path='.', log_level='DEBUG').logger,
               new_version=True)

client.reset_offset({'topic.sucl.new': -2})
client.reset_offset({'topic.sucl.new': -1})
client.reset_offset({'topic.sucl.new': 99})

`

definition of class Test
`
class Test():

def __init__(self, hosts, ssl_path, passwd, new_version, logger):
    self._cfg = {
        'group.id': 'group.sucl',
        'bootstrap.servers': hosts,
        'log.connection.close': False,
        'security.protocol': 'ssl' if ssl_path else 'plaintext',
        'ssl.key.location': os.path.join(ssl_path, 'client.key.unsecure') if ssl_path else None,
        'ssl.ca.location': os.path.join(ssl_path, 'ca-cert') if ssl_path else None,
        'ssl.certificate.location': os.path.join(ssl_path, 'client.crt') if ssl_path else None,
        'ssl.key.password': passwd,
        'api.version.request': True if new_version else False,
        'broker.version.fallback': '0.10.2.1' if new_version else '0.9.0',
        'log_level': 6,
        'message.max.bytes': 1000000,
        'log.connection.close': True if new_version else False,
        # 'debug':'generic,broker,topic,metadata',
        'enable.auto.commit': False,
        'auto.commit.interval.ms': 1000,
        'fetch.min.bytes': 1024 * 1024,
        'fetch.wait.max.ms': 1000,
        'fetch.message.max.bytes': 1048576,
        'default.topic.config': {
            'auto.offset.reset': 'smallest',
        },
    }
    self._consumer = Consumer(**self._cfg)
    self._logger = logger

def reset_offset(self, offsets):
    def get_value(para):
        if para in ('min', 'max'):
            return confluent_kafka.OFFSET_BEGINNING if para == 'min' \
                                                    else confluent_kafka.OFFSET_END
        elif isinstance(para, int):
            return para

        self._logger.warning('unknown reset value: {}, will not reset offset'.format(para))
        return None

    if isinstance(offsets, dict):
        assigns = [TopicPartition(_topic, 0, get_value(_offset)) for _topic, _offset in offsets.items()
                   if get_value(_offset)]
    elif isinstance(offsets, list):
        assigns = [TopicPartition(_item[0], _item[1], get_value(_item[2])) for _item in offsets
                   if get_value(_item[2])]
    else:
        self._logger.warning('unknown type: {} for param[offsets], will not reset offset'.format(type(offsets).__name__))
        return None

    [self._logger.warning('RESET offset to {0} for topic {1}({2})'.format(_t.offset, _t.topic, _t.partition))
     for _t in assigns]

    return self.commit(assigns, if_format=True)

def commit(self, offsets=None, if_format=False):
    if if_format:
        topics = offsets
    else:
        src = self._end_offset if offsets is None else offsets
        topics = [TopicPartition(i, k, m) for i, j in src.items() for k, m in j.items()]

    for _ in range(3):
        try:
            self._consumer.commit(offsets=topics, async=False)
            return True
        except (confluent_kafka.KafkaException,) as e:
            _exp_name, exp_code = e.args[0].name(), e.args[0].code()
            if int(exp_code) == 27:  # REBALANCE_IN_PROGRESS
                self._logger.warning('COMMIT: kafka server is now in rebalancing, will retry...')
                time.sleep(1)
                continue
            self._logger.error('COMMIT: commit offset failed with message: {0}({1}) >> {2}'.format(
                e.args[0].name(), e.args[0].code(), e.args[0].str()
            ))
            return False

    self._logger.error('COMMIT: commit failed after 3 times retry')
    return False

`

Checklist

Please provide the following information:

  • [√] confluent-kafka-python and librdkafka version (confluent_kafka.version() and confluent_kafka.libversion()):
  • [√ ] Apache Kafka broker version:
  • [√] Client configuration: {...}
  • Operating system:
  • [√ ] Provide client logs (with 'debug': '..' as necessary)
  • Provide broker log excerpts
  • Critical issue

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions