You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pulsar.apache.org by "liangyepianzhou (via GitHub)" <gi...@apache.org> on 2023/03/16 12:19:16 UTC

[GitHub] [pulsar-client-go] liangyepianzhou commented on a diff in pull request #984: [feat][txn]Implement transactionImpl

liangyepianzhou commented on code in PR #984:
URL: https://github.com/apache/pulsar-client-go/pull/984#discussion_r1138565523


##########
pulsar/transaction_impl.go:
##########
@@ -0,0 +1,235 @@
+// 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 pulsar
+
+import (
+	"context"
+	"sync"
+	"sync/atomic"
+	"time"
+
+	pb "github.com/apache/pulsar-client-go/pulsar/internal/pulsar_proto"
+	"github.com/apache/pulsar-client-go/pulsar/log"
+	uAtomic "go.uber.org/atomic"
+)
+
+type TxnState int32
+type void struct{}
+type subscription struct {
+	topic        string
+	subscription string
+}
+
+type transaction struct {
+	sync.Mutex
+	txnID                    TxnID
+	state                    TxnState
+	tcClient                 *transactionCoordinatorClient
+	registerPartitions       map[string]void
+	registerAckSubscriptions map[subscription]void
+	/**
+	* opsFlow Wait all the operations of sending and acking messages with the transaction complete
+	* by reading msg from the chan.
+	* opsCount is record the number of the uncompleted operations.
+	* opsFlow
+	*        Write:
+	* 		      1. When the transaction is created, a new empty struct{} will be written to opsFlow chan.
+	*			  2. When the opsCount decrement from 1 to 0, a new empty struct{} will be written to opsFlow chan.
+	* 			  3. When get a retryable error after committing or aborting the transaction,
+	*	             a new empty struct{} will be written to opsFlow chan.
+	*        Read:
+	*			  1. When the transaction is committed or aborted, an empty struct{} will be read from opsFlow chan.
+	*			  2. When the opsCount increment from 0 to 1, an empty struct{} will be read from opsFlow chan.
+	 */
+	opsFlow   chan void

Review Comment:
   The `opsFlow` is different from the `event channel`.
   The `opsFlow` and `opsCount` are the same as the `opFuture` and `opCount` in the Java client.
   ```java
       private CompletableFuture<Void> opFuture;
   
       private volatile long opCount = 0L;
   ```



-- 
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: commits-unsubscribe@pulsar.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org