# org.apache.kafka.common.errors.InvalidCommitOffsetSizeException: 提交偏移量大小 1048577 超过了最大允许大小 1048576

- **ID:** `kafka/invalid-commit-offset-size`
- **领域:** kafka
- **类别:** data_error
- **验证级别:** ai_generated
- **修复率:** 75%

## 根因

消费者组偏移量提交元数据超过了配置的最大大小（默认 1 MB），通常是由于在提交请求中存储了大型自定义元数据。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| kafka_2.13-3.5.0 | active | — | — |
| kafka_2.13-3.6.0 | active | — | — |
| kafka_2.13-3.7.0 | active | — | — |

## 解决方案

1. ```
   Reduce the size of custom metadata passed to `commitSync(Map<TopicPartition, OffsetAndMetadata>)` by removing large objects or storing references externally. Example: `consumer.commitSync(Collections.singletonMap(partition, new OffsetAndMetadata(offset, "small_metadata")));`
   ```
2. ```
   Increase `offset.commit.metadata.max.size` in the broker configuration (e.g., to 2097152 bytes) and restart the broker. This setting is dynamic but requires broker restart to take effect.
   ```
3. ```
   If metadata is not needed, set it to empty string: `consumer.commitSync(Collections.singletonMap(partition, new OffsetAndMetadata(offset, "")));`
   ```

## 无效尝试

- **** — This affects replication, not the metadata size limit; the commit size limit is independent. (95% 失败率)
- **** — This controls how many records are polled, not the offset metadata size; the error occurs during commit, not poll. (85% 失败率)
- **** — This removes all committed offsets for all groups, causing data loss and does not fix the size limit; the topic is recreated with default config. (99% 失败率)
