liangyepianzhou commented on a change in pull request #12219:
URL: https://github.com/apache/pulsar/pull/12219#discussion_r728010473
##########
File path:
pulsar-broker/src/main/java/org/apache/pulsar/broker/service/persistent/PersistentTopic.java
##########
@@ -2981,12 +2981,16 @@ public void publishTxnMessage(TxnID txnID, ByteBuf
headersAndPayload, PublishCon
// Message has been successfully persisted
messageDeduplication.recordMessagePersisted(publishContext,
(PositionImpl) position);
- publishContext.completed(null,
((PositionImpl) position).getLedgerId(),
- ((PositionImpl)
position).getEntryId());
+ publishContext.completed(null,
position.getLedgerId(),
+ position.getEntryId());
decrementPendingWriteOpsAndCheck();
})
.exceptionally(throwable -> {
+ throwable = throwable.getCause();
+ if (!(throwable instanceof
ManagedLedgerException)){
+ throwable = new
ManagedLedgerException(throwable);
+ }
Review comment:
The methoda of ddFailed() needs to accept ManagedLedgerException as a
parameter, and transaction will return exceptions that are not
ManagedLedgerException in two places. So unified packaging here
##########
File path:
pulsar-broker/src/main/java/org/apache/pulsar/broker/transaction/buffer/exceptions/TransactionBufferStatusException.java
##########
@@ -0,0 +1,34 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.pulsar.broker.transaction.buffer.exceptions;
+
+
+import
org.apache.pulsar.broker.transaction.buffer.impl.TopicTransactionBufferState;
+
+public class TransactionBufferStatusException extends
TransactionBufferException{
Review comment:
TransactionBufferException has ten similar implementation classes. If
you and @congbobo184 agree with this, I can mention another PR to do this later.
##########
File path:
pulsar-broker/src/main/java/org/apache/pulsar/broker/transaction/buffer/impl/TopicTransactionBuffer.java
##########
@@ -398,13 +451,14 @@ public void
syncMaxReadPositionForNormalPublish(PositionImpl position) {
synchronized (TopicTransactionBuffer.this) {
if (ongoingTxns.isEmpty()) {
maxReadPosition = position;
+ changeMaxReadPositionAndAddAbortTimes.incrementAndGet();
}
}
}
@Override
public PositionImpl getMaxReadPosition() {
- if (checkIfReady()) {
+ if (checkIfReady() || checkIfUnused()) {
Review comment:
If it is unused, it will return lastConfirmed
##########
File path:
pulsar-broker/src/main/java/org/apache/pulsar/broker/transaction/buffer/impl/TopicTransactionBufferState.java
##########
@@ -32,7 +32,8 @@
None,
Initializing,
Ready,
- Close
+ Close,
+ Unused
Review comment:
Thx, I have adopted your suggestion.
##########
File path:
pulsar-broker/src/main/java/org/apache/pulsar/broker/transaction/buffer/impl/TopicTransactionBufferState.java
##########
@@ -32,7 +32,8 @@
None,
Initializing,
Ready,
- Close
+ Close,
+ Unused
Review comment:
Which will be submitted together in this update
##########
File path:
pulsar-broker/src/main/java/org/apache/pulsar/broker/transaction/buffer/impl/TopicTransactionBuffer.java
##########
@@ -163,6 +174,34 @@ public void recoverExceptionally(Exception e) {
@Override
public CompletableFuture<Position> appendBufferToTxn(TxnID txnId, long
sequenceId, ByteBuf buffer) {
CompletableFuture<Position> completableFuture = new
CompletableFuture<>();
+ if (checkIfReady()){
+ addTxnEntry(completableFuture, txnId, buffer);
+ } else {
+ if (checkIfUnused() && changeToInitializingStateFromUnused()){
+ //`PulsarDecoder` will release this buffer in `finally` and
`takeSnapshot` is asynchronous
+ buffer.retain();
+ takeSnapshot().thenAccept(ignore -> {
+ changeToReadyState();
Review comment:
In order to ensure the orderliness of the messages and no ambiguity, we
hope that the first transaction will directly fail, and then the client will
resend the requests.
##########
File path:
pulsar-broker/src/main/java/org/apache/pulsar/broker/transaction/buffer/impl/TopicTransactionBuffer.java
##########
@@ -163,6 +174,34 @@ public void recoverExceptionally(Exception e) {
@Override
public CompletableFuture<Position> appendBufferToTxn(TxnID txnId, long
sequenceId, ByteBuf buffer) {
CompletableFuture<Position> completableFuture = new
CompletableFuture<>();
+ if (checkIfReady()){
+ addTxnEntry(completableFuture, txnId, buffer);
+ } else {
+ if (checkIfUnused() && changeToInitializingStateFromUnused()){
+ //`PulsarDecoder` will release this buffer in `finally` and
`takeSnapshot` is asynchronous
+ buffer.retain();
+ takeSnapshot().thenAccept(ignore -> {
+ changeToReadyState();
+ buffer.release();
+ timer.newTimeout(TopicTransactionBuffer.this,
+ takeSnapshotIntervalTime, TimeUnit.MILLISECONDS);
+ log.info("Topic {} take snapshot successfully when uses
TransactionBuffer at the first time",
+ this.topic.getName());
+ }).exceptionally(exception -> {
+ changeToUnUsedState();
+ buffer.release();
+ log.error("Topic {} fail to takeSnapshot before adding the
first message with transaction",
+ this.topic.getName(), exception);
+ return null;
+ });
+ }
+ completableFuture.completeExceptionally(new
TransactionBufferStatusException(this.topic.getName(),
Review comment:
If the state of TransactionBuffer is not Ready, we hope so
##########
File path:
pulsar-broker/src/main/java/org/apache/pulsar/broker/transaction/buffer/impl/TopicTransactionBufferState.java
##########
@@ -32,7 +32,8 @@
None,
Initializing,
Ready,
- Close
+ Close,
+ Unused
Review comment:
Which will be submitted together in this update
##########
File path:
pulsar-broker/src/main/java/org/apache/pulsar/broker/transaction/buffer/impl/TopicTransactionBufferState.java
##########
@@ -32,7 +32,8 @@
None,
Initializing,
Ready,
- Close
+ Close,
+ Unused
Review comment:
Thx, I have adopted your suggestion which will be submitted together in
this update.
--
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]