Deduplication fails when the batch message contains duplicate message and valid message

Aperta
#1,395 1 commento 9 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 2 giorni

Nessuno ha ancora preso questa issue.

  • #1565 di @Mohith26 — chiusa senza merge

Valutazione

Difficoltà
3/5
Tempo stimato
1-2 giorni
Idoneità per principianti
58/100
Tipo di issue
Bug
Chiarezza
Abbastanza chiara
Stato di attività
Tranquilla
Stack tecnologico
go

Direzione di ricerca

Inizia eseguendo la riproduzione Go fornita con Pulsar 4.0.5, quindi traccia il batching del client Go e la gestione degli identificatori di sequenza per SendAsync. Il lavoro è completato quando una SequenceID duplicata svuota il batch corrente prima che venga aggiunto il nuovo messaggio, così che consumando il topic venga mantenuto il messaggio realmente nuovo e venga eliminato solo il duplicato.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

Expected behavior

When a producer resends a duplicate SequenceID while batching is enabled, the client should flush the current batch and start a new one.
This guarantees that a batch never contains both old/duplicate and new SequenceIds, allowing the broker‑side deduplication logic to drop only the duplicates and accept the genuinely new messages.

This is the behavior of the Java client since PR apache/pulsar#6326.

Actual behavior

With the Go client (v0.15.0) the duplicate and new messages are added to the same batch.
Because the outer CommandSend carries only the lowest SequenceId in the batch, the broker cannot determine that newer messages are present; it treats the entire batch as a duplicate and drops it — including the fresh messages.

Steps to reproduce
package main

import (
	"context"
	"fmt"
	"log"
	"sync"
	"time"

	"github.com/apache/pulsar-client-go/pulsar"
)

func main() {
	// ---------- set up ----------
	client, err := pulsar.NewClient(pulsar.ClientOptions{
		URL:               "pulsar://localhost:6650",
		OperationTimeout:  5 * time.Second,
		ConnectionTimeout: 5 * time.Second,
	})
	if err != nil {
		log.Fatalf("client: %v", err)
	}
	defer client.Close()

	const topic = "persistent://public/default/dedupe-go-batch-bug"
	const producerName = "go-dedupe-test"

	prod, err := client.CreateProducer(pulsar.ProducerOptions{
		Topic:                   topic,
		Name:                    producerName,
		DisableBatching:         false,
		BatchingMaxPublishDelay: 1 * time.Second,
	})
	if err != nil {
		log.Fatalf("producer: %v", err)
	}
	defer prod.Close()

	// helper to send one async msg and wait for ack
	send := func(seq int64, wg *sync.WaitGroup) {
		wg.Add(1)
		prod.SendAsync(context.Background(),
			&pulsar.ProducerMessage{
				Payload:    []byte(fmt.Sprintf("seq-%d", seq)),
				SequenceID: &seq,
			},
			func(id pulsar.MessageID, _ *pulsar.ProducerMessage, err error) {
				log.Printf("Send cb seq=%d err=%v", seq, err)
				wg.Done()
			})
	}

	// ---------- 1) first batch: seq 0,1 ----------
	var wg sync.WaitGroup
	send(0, &wg)
	send(1, &wg)
	wg.Wait()                   // ensure broker acks first batch
	time.Sleep(1 * time.Second) // let batch window expire

	// ---------- 2) second batch with duplicate + new ----------
	//   we issue them back‑to‑back so they land in the SAME batch
	send(0, &wg) // duplicate
	send(2, &wg) // new
	wg.Wait()
	prod.Flush()

	// ---------- consume to see what really persisted ----------
	cons, _ := client.Subscribe(pulsar.ConsumerOptions{
		Topic:                       topic,
		SubscriptionName:            "check",
		Type:                        pulsar.Exclusive,
		SubscriptionInitialPosition: pulsar.SubscriptionPositionEarliest,
	})
	defer cons.Close()

	got := map[string]struct{}{}
	for {
		ctx, cancel := context.WithTimeout(context.Background(), 3*time.Second)
		msg, err := cons.Receive(ctx)
		cancel()
		if err != nil {
			break
		}
		got[string(msg.Payload())] = struct{}{}
		cons.Ack(msg)
	}

	fmt.Println("messages stored:")
	for k := range got {
		fmt.Println("  ", k)
	}
}

System configuration

Pulsar version: 4.0.5

Lingua principale
Go
Stelle
746
Fork
394
Merge medio
6g 13h
PR unite (30g)
7

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di apache/pulsar-client-go

Tutte le issue di apache/pulsar-client-go

Issue simili

Altre issue su Go

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.