poorbarcode commented on code in PR #130:
URL:
https://github.com/apache/flink-connector-pulsar/pull/130#discussion_r4332552906
##########
flink-connector-pulsar/src/main/java/org/apache/flink/connector/pulsar/sink/writer/PulsarWriter.java:
##########
@@ -167,14 +174,25 @@ public void write(IN element, Context context) throws
IOException, InterruptedEx
CompletableFuture<MessageId> future = builder.sendAsync();
future.whenComplete(
(id, ex) -> {
- pendingMessages.decrementAndGet();
if (ex != null) {
mailboxExecutor.execute(
() -> throwSendingException(topic, ex),
"Failed to send data to Pulsar");
} else {
+ // Safe cast: all MessageId implementations in
Pulsar implement
+ // MessageIdAdv.
+ MessageIdAdv messageIdAdv = (MessageIdAdv) id;
+ latestPublishedMessages.put(
+ topic,
+ new MessageIdPojo(
+ messageIdAdv.getLedgerId(),
+ messageIdAdv.getEntryId(),
+ messageIdAdv.getBatchSize(),
+ messageIdAdv.getBatchIndex(),
+ messageIdAdv.getPartitionIndex()));
LOG.debug("Sent message to Pulsar {} with message
id {}", topic, id);
}
+ pendingMessages.decrementAndGet();
Review Comment:
Updated the callback to decrement pendingMessages in a finally block,
preserving the ordering while preventing a failed callback path from hanging
flush().
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]