Skip to content
This repository was archived by the owner on Jan 24, 2024. It is now read-only.

Conversation

@BewareMyPower
Copy link
Collaborator

@BewareMyPower BewareMyPower commented Feb 8, 2022

This PR is an important fix, and it's first included in KoP 2.9.2.2, 2.8.2.7 (not released now) and 2.10.0.1 (not released now)


Fixes #1050

Motivation

Currently ReplicaManager#getPartitionLog transfers exceptions thrown from PartitionLog#appendRecords to Kafka's error code by calling Errors.forException and treats the unknown error as KAFKA_STORAGE_ERROR. However, the exception is thrown from broker side:

  • Control records are sent by ManagedLedger#asyncAddEntry, the ManagedLedgerException will be thrown if failed.
  • Normal records are sent by PersistentTopic#publishMessages, the BrokerServiceException that wraps ManagedLedgerException will be thrown if failed.

After a bundle unload event, some entries might still be cached in the managed ledger. In this case, all entries will be failed with ManagedLedgerAlreadyClosedException. However, if Kafka producer received an error other than InvalidMetadataException, it won't update the metadata and send records to the same broker and failed again. See https://github.com/apache/kafka/blob/7c2d6724130f8251aa255917b74d9c3ef1fe67f7/clients/src/main/java/org/apache/kafka/clients/producer/internals/Sender.java#L636-L647

We should return the error code associated with InvalidMetadataException to notify Kafka producer it's time to find the new leader of the partition.

Modifications

  • When the managed ledger's state is wrong, complete the future with NotLeaderForPartitionException, which implements InvalidMetadataException.
  • Add a test testIllegalManagedLedger to verify this error code is received when the managed ledger is closed.

@BewareMyPower BewareMyPower force-pushed the bewaremypower/handle-publish-error-gracefully branch from cf63b6e to 33f2b54 Compare February 9, 2022 07:54
@BewareMyPower BewareMyPower merged commit 3d48a3c into streamnative:master Feb 9, 2022
@BewareMyPower BewareMyPower deleted the bewaremypower/handle-publish-error-gracefully branch February 9, 2022 08:25
BewareMyPower added a commit that referenced this pull request Feb 9, 2022
…1054)

Fixes #1050

### Motivation

Currently `ReplicaManager#getPartitionLog` transfers exceptions thrown from `PartitionLog#appendRecords` to Kafka's error code by calling `Errors.forException` and treats the unknown error as `KAFKA_STORAGE_ERROR`. However, the exception is thrown from broker side:
- Control records are sent by `ManagedLedger#asyncAddEntry`, the `ManagedLedgerException` will be thrown if failed.
- Normal records are sent by `PersistentTopic#publishMessages`, the `BrokerServiceException` that wraps `ManagedLedgerException` will be thrown if failed.

After a bundle unload event, some entries might still be cached in the managed ledger. In this case, all entries will be failed with `ManagedLedgerAlreadyClosedException`. However, if Kafka producer received an error other than `InvalidMetadataException`, it won't update the metadata and send records to the same broker and failed again. See https://github.com/apache/kafka/blob/7c2d6724130f8251aa255917b74d9c3ef1fe67f7/clients/src/main/java/org/apache/kafka/clients/producer/internals/Sender.java#L636-L647

We should return the error code associated with `InvalidMetadataException` to notify Kafka producer it's time to find the new leader of the partition.

### Modifications

- When the managed ledger's state is wrong, complete the future with `NotLeaderForPartitionException`, which implements `InvalidMetadataException`.
- Add a test `testIllegalManagedLedger` to verify this error code is received when the managed ledger is closed.

(cherry picked from commit 3d48a3c)
BewareMyPower added a commit that referenced this pull request Feb 9, 2022
…1054)

Fixes #1050

### Motivation

Currently `ReplicaManager#getPartitionLog` transfers exceptions thrown from `PartitionLog#appendRecords` to Kafka's error code by calling `Errors.forException` and treats the unknown error as `KAFKA_STORAGE_ERROR`. However, the exception is thrown from broker side:
- Control records are sent by `ManagedLedger#asyncAddEntry`, the `ManagedLedgerException` will be thrown if failed.
- Normal records are sent by `PersistentTopic#publishMessages`, the `BrokerServiceException` that wraps `ManagedLedgerException` will be thrown if failed.

After a bundle unload event, some entries might still be cached in the managed ledger. In this case, all entries will be failed with `ManagedLedgerAlreadyClosedException`. However, if Kafka producer received an error other than `InvalidMetadataException`, it won't update the metadata and send records to the same broker and failed again. See https://github.com/apache/kafka/blob/7c2d6724130f8251aa255917b74d9c3ef1fe67f7/clients/src/main/java/org/apache/kafka/clients/producer/internals/Sender.java#L636-L647

We should return the error code associated with `InvalidMetadataException` to notify Kafka producer it's time to find the new leader of the partition.

### Modifications

- When the managed ledger's state is wrong, complete the future with `NotLeaderForPartitionException`, which implements `InvalidMetadataException`.
- Add a test `testIllegalManagedLedger` to verify this error code is received when the managed ledger is closed.
BewareMyPower added a commit that referenced this pull request Feb 9, 2022
…1054)

Fixes #1050

### Motivation

Currently `ReplicaManager#getPartitionLog` transfers exceptions thrown from `PartitionLog#appendRecords` to Kafka's error code by calling `Errors.forException` and treats the unknown error as `KAFKA_STORAGE_ERROR`. However, the exception is thrown from broker side:
- Control records are sent by `ManagedLedger#asyncAddEntry`, the `ManagedLedgerException` will be thrown if failed.
- Normal records are sent by `PersistentTopic#publishMessages`, the `BrokerServiceException` that wraps `ManagedLedgerException` will be thrown if failed.

After a bundle unload event, some entries might still be cached in the managed ledger. In this case, all entries will be failed with `ManagedLedgerAlreadyClosedException`. However, if Kafka producer received an error other than `InvalidMetadataException`, it won't update the metadata and send records to the same broker and failed again. See https://github.com/apache/kafka/blob/7c2d6724130f8251aa255917b74d9c3ef1fe67f7/clients/src/main/java/org/apache/kafka/clients/producer/internals/Sender.java#L636-L647

We should return the error code associated with `InvalidMetadataException` to notify Kafka producer it's time to find the new leader of the partition.

### Modifications

- When the managed ledger's state is wrong, complete the future with `NotLeaderForPartitionException`, which implements `InvalidMetadataException`.
- Add a test `testIllegalManagedLedger` to verify this error code is received when the managed ledger is closed.

(cherry picked from commit 3d48a3c)
eolivelli pushed a commit to eolivelli/kop that referenced this pull request Feb 24, 2022
…treamnative#1054)

Fixes streamnative#1050

### Motivation

Currently `ReplicaManager#getPartitionLog` transfers exceptions thrown from `PartitionLog#appendRecords` to Kafka's error code by calling `Errors.forException` and treats the unknown error as `KAFKA_STORAGE_ERROR`. However, the exception is thrown from broker side:
- Control records are sent by `ManagedLedger#asyncAddEntry`, the `ManagedLedgerException` will be thrown if failed.
- Normal records are sent by `PersistentTopic#publishMessages`, the `BrokerServiceException` that wraps `ManagedLedgerException` will be thrown if failed.

After a bundle unload event, some entries might still be cached in the managed ledger. In this case, all entries will be failed with `ManagedLedgerAlreadyClosedException`. However, if Kafka producer received an error other than `InvalidMetadataException`, it won't update the metadata and send records to the same broker and failed again. See https://github.com/apache/kafka/blob/7c2d6724130f8251aa255917b74d9c3ef1fe67f7/clients/src/main/java/org/apache/kafka/clients/producer/internals/Sender.java#L636-L647

We should return the error code associated with `InvalidMetadataException` to notify Kafka producer it's time to find the new leader of the partition.

### Modifications

- When the managed ledger's state is wrong, complete the future with `NotLeaderForPartitionException`, which implements `InvalidMetadataException`.
- Add a test `testIllegalManagedLedger` to verify this error code is received when the managed ledger is closed.

(cherry picked from commit 3d48a3c)
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] Fail to reconnect after bundle unload happen

2 participants