kafka __consumer_offsets topic has excessive partition count

Viewed 4835

I am using Kafka 0.8.2 and I'm getting an error in my consumer saying "offset commit failed with ...". When looking at the topic "__consumer_offsets". I saw that it had 50 partition count. Is that normal? I was only able to resolve this issue by deleting all the Kafka logs and restarting my Kafka server. Is there a way I can delete this topic when it reaches a certain number of partitions or am I committing my offsets wrong?

Here is how I commit my offsets:

 public void commitOffsets(BlockingChannel channel, String topic, String    groupid, int partition, String clientName, int corrilationid, long offset)   throws Exception{

    if (commitTryCount > 100){
        throw new Exception("Offset commit failed with " + channel.host());
    }

    long now = System.currentTimeMillis();
    Map<TopicAndPartition, OffsetAndMetadata> offsets = new LinkedHashMap<TopicAndPartition, OffsetAndMetadata>();
    //for (int i = 0; i < this.totalPartitions; i++){
        TopicAndPartition topicPartition = new TopicAndPartition(topic, partition);
        offsets.put(topicPartition, new OffsetAndMetadata(offset, topic, now));
    //}     

    //initialize offset commit
    OffsetCommitRequest commitRequest = new OffsetCommitRequest(groupid, offsets, corrilationid, clientName, (short) 1);
    channel.send(commitRequest.underlying());
    OffsetCommitResponse commitResponse = OffsetCommitResponse.readFrom(channel.receive().buffer());
    if (commitResponse.hasError()){         
        for (Object partitionErrorCode: commitResponse.errors().values()){
            if (Short.parseShort(partitionErrorCode.toString()) == ErrorMapping.OffsetMetadataTooLargeCode()){
                //reduce the size of the metadata and retry
                offset--;
                commitOffsets(channel, topic, groupid, partition, clientName, corrilationid, offset);
                commitTryCount++;
            } else if (Short.parseShort(partitionErrorCode.toString()) == ErrorMapping.NotCoordinatorForConsumerCode()
                    || Short.parseShort(partitionErrorCode.toString()) == ErrorMapping.ConsumerCoordinatorNotAvailableCode()) {
                //discover new coordinator and retry
                int newCorrilation = corrilationid;
                newCorrilation++;
                this.channel = discoverChannel(channel.host(), port, groupid, clientName, newCorrilation);
                commitOffsets(this.channel, topic, groupid, partition, clientName, newCorrilation, offset);
                commitTryCount++;
            } else{
                //retry
                commitOffsets(channel, topic, groupid, partition, clientName, corrilationid, offset);
                commitTryCount++;
            }//end of else              
        }//end of for
    }//end of if
}//end of method
2 Answers
Related