You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pulsar.apache.org by GitBox <gi...@apache.org> on 2020/08/07 07:39:11 UTC
[GitHub] [pulsar] gaoran10 opened a new pull request #7781: Support consume transaction messages.
gaoran10 opened a new pull request #7781:
URL: https://github.com/apache/pulsar/pull/7781
Master Issue: #2664
Fix https://github.com/streamnative/pulsar/issues/1304
### Motivation
Currently, the consumer can't receive transaction messages.
### Modifications
Support process the commit marker in the topic partition and fetch transaction messages from TransactionBuffer.
### Verifying this change
- [ ] Make sure that the change passes the CI checks.
This change added tests and can be verified as follows:
- *Added unit test for consuming transaction messages*
`org.apache.pulsar.broker.transaction.TransactionConsumeTest`
### Does this pull request potentially affect one of the following parts:
*If `yes` was chosen, please highlight the changes*
- Dependencies (does it add or upgrade a dependency): (no)
- The public API: (yes)
- The schema: (no)
- The default values of configurations: (no)
- The wire protocol: (no)
- The rest endpoints: (no)
- The admin cli options: (no)
- Anything that affects deployment: (no)
### Documentation
- Does this pull request introduce a new feature? (no)
----------------------------------------------------------------
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.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [pulsar] gaoran10 commented on pull request #7781: [Transaction] Support consume transaction messages.
Posted by GitBox <gi...@apache.org>.
gaoran10 commented on pull request #7781:
URL: https://github.com/apache/pulsar/pull/7781#issuecomment-672569837
/pulsarbot run-failure-checks
----------------------------------------------------------------
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.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [pulsar] gaoran10 commented on pull request #7781: [Transaction] Support consume transaction messages.
Posted by GitBox <gi...@apache.org>.
gaoran10 commented on pull request #7781:
URL: https://github.com/apache/pulsar/pull/7781#issuecomment-670941360
/pulsarbot run-failure-checks
----------------------------------------------------------------
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.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [pulsar] gaoran10 commented on a change in pull request #7781: [Transaction] Support consume transaction messages.
Posted by GitBox <gi...@apache.org>.
gaoran10 commented on a change in pull request #7781:
URL: https://github.com/apache/pulsar/pull/7781#discussion_r467949910
##########
File path: pulsar-broker/src/main/java/org/apache/pulsar/broker/service/persistent/TransactionReader.java
##########
@@ -0,0 +1,94 @@
+/**
+ * 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.service.persistent;
+
+import lombok.extern.slf4j.Slf4j;
+import org.apache.bookkeeper.mledger.AsyncCallbacks;
+import org.apache.bookkeeper.mledger.Entry;
+import org.apache.bookkeeper.mledger.ManagedLedgerException;
+import org.apache.pulsar.broker.service.Consumer;
+import org.apache.pulsar.broker.service.Topic;
+import org.apache.pulsar.broker.transaction.buffer.TransactionBuffer;
+import org.apache.pulsar.client.api.transaction.TxnID;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.ConcurrentLinkedQueue;
+
+@Slf4j
+public class TransactionReader {
+
+ private TransactionBuffer transactionBuffer;
+ private volatile long startSequenceId = 0;
+
+ public void read(Topic topic, ConcurrentLinkedQueue<TxnID> transactionQueue,
+ int readMessageNum, Object ctx,
+ AsyncCallbacks.ReadEntriesCallback readEntriesCallback) {
+ if (transactionBuffer == null) {
+ topic.getTransactionBuffer(false).whenComplete((tb, throwable) -> {
+ if (throwable != null) {
+ log.error("Get transactionBuffer failed.", throwable);
+ readEntriesCallback.readEntriesFailed(
+ ManagedLedgerException.getManagedLedgerException(throwable), ctx);
+ return;
+ }
+ transactionBuffer = tb;
+ read(transactionQueue, readMessageNum, ctx, readEntriesCallback);
+ });
+ } else {
+ read(transactionQueue, readMessageNum, ctx, readEntriesCallback);
+ }
+ }
+
+ private void read(ConcurrentLinkedQueue<TxnID> transactionQueue,
+ int readMessageNum, Object ctx,
+ AsyncCallbacks.ReadEntriesCallback readEntriesCallback) {
Review comment:
I'll adjust this logic.
----------------------------------------------------------------
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.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [pulsar] codelipenghui commented on a change in pull request #7781: [Transaction] Support consume transaction messages.
Posted by GitBox <gi...@apache.org>.
codelipenghui commented on a change in pull request #7781:
URL: https://github.com/apache/pulsar/pull/7781#discussion_r467883245
##########
File path: pulsar-broker/src/main/java/org/apache/pulsar/broker/service/persistent/TransactionReader.java
##########
@@ -0,0 +1,94 @@
+/**
+ * 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.service.persistent;
+
+import lombok.extern.slf4j.Slf4j;
+import org.apache.bookkeeper.mledger.AsyncCallbacks;
+import org.apache.bookkeeper.mledger.Entry;
+import org.apache.bookkeeper.mledger.ManagedLedgerException;
+import org.apache.pulsar.broker.service.Consumer;
+import org.apache.pulsar.broker.service.Topic;
+import org.apache.pulsar.broker.transaction.buffer.TransactionBuffer;
+import org.apache.pulsar.client.api.transaction.TxnID;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.ConcurrentLinkedQueue;
+
+@Slf4j
+public class TransactionReader {
+
+ private TransactionBuffer transactionBuffer;
+ private volatile long startSequenceId = 0;
+
+ public void read(Topic topic, ConcurrentLinkedQueue<TxnID> transactionQueue,
+ int readMessageNum, Object ctx,
+ AsyncCallbacks.ReadEntriesCallback readEntriesCallback) {
+ if (transactionBuffer == null) {
+ topic.getTransactionBuffer(false).whenComplete((tb, throwable) -> {
+ if (throwable != null) {
+ log.error("Get transactionBuffer failed.", throwable);
+ readEntriesCallback.readEntriesFailed(
+ ManagedLedgerException.getManagedLedgerException(throwable), ctx);
+ return;
+ }
+ transactionBuffer = tb;
+ read(transactionQueue, readMessageNum, ctx, readEntriesCallback);
+ });
+ } else {
+ read(transactionQueue, readMessageNum, ctx, readEntriesCallback);
+ }
+ }
+
+ private void read(ConcurrentLinkedQueue<TxnID> transactionQueue,
+ int readMessageNum, Object ctx,
+ AsyncCallbacks.ReadEntriesCallback readEntriesCallback) {
Review comment:
Is the read txn message count is the size of the `transactionQueue `? I did not understand this method, is the transactionQueue only stores the first txn ID? I noticed you have only peek one item from this queue.
##########
File path: pulsar-broker/src/main/java/org/apache/pulsar/broker/service/persistent/TransactionReader.java
##########
@@ -0,0 +1,94 @@
+/**
+ * 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.service.persistent;
+
+import lombok.extern.slf4j.Slf4j;
+import org.apache.bookkeeper.mledger.AsyncCallbacks;
+import org.apache.bookkeeper.mledger.Entry;
+import org.apache.bookkeeper.mledger.ManagedLedgerException;
+import org.apache.pulsar.broker.service.Consumer;
+import org.apache.pulsar.broker.service.Topic;
+import org.apache.pulsar.broker.transaction.buffer.TransactionBuffer;
+import org.apache.pulsar.client.api.transaction.TxnID;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.ConcurrentLinkedQueue;
+
+@Slf4j
+public class TransactionReader {
+
+ private TransactionBuffer transactionBuffer;
+ private volatile long startSequenceId = 0;
+
+ public void read(Topic topic, ConcurrentLinkedQueue<TxnID> transactionQueue,
+ int readMessageNum, Object ctx,
+ AsyncCallbacks.ReadEntriesCallback readEntriesCallback) {
+ if (transactionBuffer == null) {
+ topic.getTransactionBuffer(false).whenComplete((tb, throwable) -> {
+ if (throwable != null) {
+ log.error("Get transactionBuffer failed.", throwable);
+ readEntriesCallback.readEntriesFailed(
+ ManagedLedgerException.getManagedLedgerException(throwable), ctx);
+ return;
+ }
+ transactionBuffer = tb;
+ read(transactionQueue, readMessageNum, ctx, readEntriesCallback);
+ });
+ } else {
+ read(transactionQueue, readMessageNum, ctx, readEntriesCallback);
+ }
+ }
+
+ private void read(ConcurrentLinkedQueue<TxnID> transactionQueue,
+ int readMessageNum, Object ctx,
+ AsyncCallbacks.ReadEntriesCallback readEntriesCallback) {
+ final TxnID txnID = transactionQueue.peek();
Review comment:
It's might peek null here.
----------------------------------------------------------------
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.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [pulsar] gaoran10 commented on pull request #7781: [Transaction] Support consume transaction messages.
Posted by GitBox <gi...@apache.org>.
gaoran10 commented on pull request #7781:
URL: https://github.com/apache/pulsar/pull/7781#issuecomment-673543536
/pulsarbot run-failure-checks
----------------------------------------------------------------
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.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [pulsar] gaoran10 commented on pull request #7781: [Transaction] Support consume transaction messages.
Posted by GitBox <gi...@apache.org>.
gaoran10 commented on pull request #7781:
URL: https://github.com/apache/pulsar/pull/7781#issuecomment-670948678
/pulsarbot run-failure-checks
----------------------------------------------------------------
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.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [pulsar] gaoran10 commented on a change in pull request #7781: [Transaction] Support consume transaction messages.
Posted by GitBox <gi...@apache.org>.
gaoran10 commented on a change in pull request #7781:
URL: https://github.com/apache/pulsar/pull/7781#discussion_r470346590
##########
File path: pulsar-broker/src/main/java/org/apache/pulsar/broker/service/persistent/TransactionReader.java
##########
@@ -0,0 +1,94 @@
+/**
+ * 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.service.persistent;
+
+import lombok.extern.slf4j.Slf4j;
+import org.apache.bookkeeper.mledger.AsyncCallbacks;
+import org.apache.bookkeeper.mledger.Entry;
+import org.apache.bookkeeper.mledger.ManagedLedgerException;
+import org.apache.pulsar.broker.service.Consumer;
+import org.apache.pulsar.broker.service.Topic;
+import org.apache.pulsar.broker.transaction.buffer.TransactionBuffer;
+import org.apache.pulsar.client.api.transaction.TxnID;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.ConcurrentLinkedQueue;
+
+@Slf4j
+public class TransactionReader {
+
+ private TransactionBuffer transactionBuffer;
+ private volatile long startSequenceId = 0;
+
+ public void read(Topic topic, ConcurrentLinkedQueue<TxnID> transactionQueue,
+ int readMessageNum, Object ctx,
+ AsyncCallbacks.ReadEntriesCallback readEntriesCallback) {
+ if (transactionBuffer == null) {
+ topic.getTransactionBuffer(false).whenComplete((tb, throwable) -> {
+ if (throwable != null) {
+ log.error("Get transactionBuffer failed.", throwable);
+ readEntriesCallback.readEntriesFailed(
+ ManagedLedgerException.getManagedLedgerException(throwable), ctx);
+ return;
+ }
+ transactionBuffer = tb;
+ read(transactionQueue, readMessageNum, ctx, readEntriesCallback);
+ });
+ } else {
+ read(transactionQueue, readMessageNum, ctx, readEntriesCallback);
+ }
+ }
+
+ private void read(ConcurrentLinkedQueue<TxnID> transactionQueue,
+ int readMessageNum, Object ctx,
+ AsyncCallbacks.ReadEntriesCallback readEntriesCallback) {
+ final TxnID txnID = transactionQueue.peek();
Review comment:
Ok, I'll add a check.
----------------------------------------------------------------
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.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [pulsar] codelipenghui merged pull request #7781: [Transaction] Support consume transaction messages.
Posted by GitBox <gi...@apache.org>.
codelipenghui merged pull request #7781:
URL: https://github.com/apache/pulsar/pull/7781
----------------------------------------------------------------
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.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org