Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP][Client] Return the message ID of the first chunk when sending chunked messages #12171

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@
import org.apache.pulsar.common.schema.SchemaType;
import org.apache.pulsar.common.util.DateFormatter;
import org.apache.pulsar.common.util.FutureUtil;
import org.apache.pulsar.common.util.collections.ConcurrentOpenHashMap;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down Expand Up @@ -150,6 +151,8 @@ public class ProducerImpl<T> extends ProducerBase<T> implements TimerTask, Conne
private Optional<Long> topicEpoch = Optional.empty();
private final List<Throwable> previousExceptions = new CopyOnWriteArrayList<Throwable>();

private ConcurrentOpenHashMap<String, MessageIdImpl> chunkMessageIds;

@SuppressWarnings("rawtypes")
private static final AtomicLongFieldUpdater<ProducerImpl> msgIdGeneratorUpdater = AtomicLongFieldUpdater
.newUpdater(ProducerImpl.class, "msgIdGenerator");
Expand All @@ -170,6 +173,7 @@ public ProducerImpl(PulsarClientImpl client, String topic, ProducerConfiguration
} else {
this.semaphore = Optional.empty();
}
this.chunkMessageIds = new ConcurrentOpenHashMap<>();

this.compressor = CompressionCodecProvider.getCompressionCodec(conf.getCompressionType());

Expand Down Expand Up @@ -1000,6 +1004,19 @@ void ackReceived(ClientCnx cnx, long sequenceId, long highestSequenceId, long le
OpSendMsg finalOp = op;
LAST_SEQ_ID_PUBLISHED_UPDATER.getAndUpdate(this, last -> Math.max(last, getHighestSequenceId(finalOp)));
op.setMessageId(ledgerId, entryId, partitionIndex);
if (op.totalChunks > 1) {
if (op.chunkId == 0) {
chunkMessageIds.put(op.msg.getMessageBuilder().getUuid(),
new MessageIdImpl(ledgerId, entryId, partitionIndex));
} else if (op.chunkId == op.totalChunks - 1) {
MessageIdImpl firstChunkMsgId = chunkMessageIds.get(op.msg.getMessageBuilder().getUuid());
if (firstChunkMsgId != null) {
op.setMessageId(firstChunkMsgId.ledgerId, firstChunkMsgId.entryId, firstChunkMsgId.partitionIndex);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is the challenge here. last chunk is already published and persist at server side. this is at ackReceived method, means you have received the ack for already published message and updating messageId will not reflect any change to message which is already persist at server side.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is correct. But I think we don't need to reflect any change to the message on the server-side.

}
chunkMessageIds.remove(op.msg.getMessageBuilder().getUuid());
}
}

// if message is chunked then call callback only on last chunk
if (op.totalChunks <= 1 || (op.chunkId == op.totalChunks - 1)) {
try {
Expand Down