# org.apache.kafka.common.errors.PartitionNotAssignedException：分区my-topic-0未分配给此消费者实例

- **ID:** `kafka/partition-not-assigned`
- **领域:** kafka
- **类别:** runtime_error
- **验证级别:** ai_generated
- **修复率:** 85%

## 根因

消费者尝试提交偏移或获取未分配给它的分区的数据，通常是由于再平衡后分区分配过期。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| kafka 2.8.0 | active | — | — |
| kafka 3.0.0 | active | — | — |
| kafka 3.3.0 | active | — | — |

## 解决方案

1. ```
   Use a ConsumerRebalanceListener to update partition assignments after a rebalance, and ensure commitSync() is only called for assigned partitions.
   ```
2. ```
   Increase 'session.timeout.ms' and 'heartbeat.interval.ms' to reduce the likelihood of spurious rebalances that cause stale assignments.
   ```

## 无效尝试

- **** — poll() may not trigger a rebalance if the group is stable; it can also cause a busy loop that degrades performance. (60% 失败率)
- **** — This bypasses the group coordinator and can lead to offset conflicts or duplicate consumption if other consumers exist. (75% 失败率)
