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


##########
pulsar/transaction.go:
##########
@@ -17,7 +17,32 @@
 
 package pulsar
 
+import (
+       "context"
+)
+
+const (
+       Open = iota //The init state is open
+       Committing
+       Aborting
+       Committed
+       Aborted
+       Errored
+       TimeOut
+)
+
 type TxnID struct {
        mostSigBits  uint64
        leastSigBits uint64
 }
+
+// Transaction used to guarantee exactly-once
+type Transaction interface {
+       Commit(context.Context) error

Review Comment:
   Please add the API document.



##########
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:
   When I try to understand what it does, it doesn't feel very intuitive.
   
   How about we introduce an `eventCh`? All requests are queued in this ch, and 
then a coroutine is used to handle all events.
   
   Like `consumer_partition`:
   
   
https://github.com/apache/pulsar-client-go/blob/42ded0d59c46fd3fdaad45f045f7e8bf091131a5/pulsar/consumer_partition.go#L1343-L1363
   
    
   



-- 
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]

Reply via email to