Gleiphir2769 commented on code in PR #805:
URL: https://github.com/apache/pulsar-client-go/pull/805#discussion_r983303572


##########
pulsar/consumer_partition.go:
##########
@@ -1475,3 +1609,210 @@ func convertToMessageID(id *pb.MessageIdData) 
trackingMessageID {
 
        return msgID
 }
+
+type chunkedMsgCtx struct {
+       totalChunks      int32
+       chunkedMsgBuffer internal.Buffer
+       lastChunkedMsgID int32
+       chunkedMsgIDs    []messageID
+       receivedTime     int64
+
+       mu sync.Mutex
+}
+
+func newChunkedMsgCtx(numChunksFromMsg int32, totalChunkMsgSize int) 
*chunkedMsgCtx {
+       return &chunkedMsgCtx{
+               totalChunks:      numChunksFromMsg,
+               chunkedMsgBuffer: internal.NewBuffer(totalChunkMsgSize),
+               lastChunkedMsgID: -1,
+               chunkedMsgIDs:    make([]messageID, numChunksFromMsg),
+               receivedTime:     time.Now().Unix(),
+       }
+}
+
+func (c *chunkedMsgCtx) refresh(chunkID int32, msgID messageID, partPayload 
internal.Buffer) {
+       c.mu.Lock()
+       defer c.mu.Unlock()
+       c.chunkedMsgIDs[chunkID] = msgID
+       c.chunkedMsgBuffer.Write(partPayload.ReadableSlice())
+       c.lastChunkedMsgID = chunkID
+}
+
+func (c *chunkedMsgCtx) firstChunkID() messageID {
+       c.mu.Lock()
+       defer c.mu.Unlock()
+       if len(c.chunkedMsgIDs) == 0 {
+               return messageID{}
+       }
+       return c.chunkedMsgIDs[0]
+}
+
+func (c *chunkedMsgCtx) lastChunkID() messageID {
+       c.mu.Lock()
+       defer c.mu.Unlock()
+       if len(c.chunkedMsgIDs) == 0 {
+               return messageID{}
+       }
+       return c.chunkedMsgIDs[len(c.chunkedMsgIDs)-1]
+}
+
+func (c *chunkedMsgCtx) discard(pc *partitionConsumer) {
+       c.mu.Lock()
+       defer c.mu.Unlock()
+
+       for _, mid := range c.chunkedMsgIDs {
+               pc.log.Info("Removing chunk message-id", mid.String())
+               tmid, _ := toTrackingMessageID(mid)
+               pc.AckID(tmid)
+       }
+}
+
+type chunkedMsgCtxMap struct {
+       chunkedMsgCtxs map[string]*chunkedMsgCtx
+       pendingQueue   *list.List
+       maxPending     int
+       pc             *partitionConsumer
+       mu             sync.Mutex
+       closed         bool
+}
+
+func newChunkedMsgCtxMap(maxPending int, pc *partitionConsumer) 
*chunkedMsgCtxMap {
+       return &chunkedMsgCtxMap{
+               chunkedMsgCtxs: make(map[string]*chunkedMsgCtx, maxPending),
+               pendingQueue:   list.New(),
+               maxPending:     maxPending,
+               pc:             pc,
+               mu:             sync.Mutex{},
+       }
+}
+
+func (c *chunkedMsgCtxMap) addIfAbsent(uuid string, totalChunks int32, 
totalChunkMsgSize int) {
+       c.mu.Lock()
+       defer c.mu.Unlock()
+       if c.closed {
+               return
+       }
+       if _, ok := c.chunkedMsgCtxs[uuid]; !ok {
+               c.chunkedMsgCtxs[uuid] = newChunkedMsgCtx(totalChunks, 
totalChunkMsgSize)
+               c.pendingQueue.PushBack(uuid)
+               go c.removeChunkIfExpire(uuid, true, 
c.pc.options.expireTimeOfIncompleteChunk)
+       }
+       if c.maxPending > 0 && c.pendingQueue.Len() > c.maxPending {
+               go c.removeChunkMessage(uuid, 
c.pc.options.autoAckIncompleteChunk)

Review Comment:
   You r right. I will fix it.



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