Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[CHANGED] JetStream: accept "Nats-Expected-Last-Sequence" with "0" #3038

Merged
merged 1 commit into from Jul 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 10 additions & 0 deletions server/jetstream_test.go
Expand Up @@ -3478,6 +3478,16 @@ func TestJetStreamPublishExpect(t *testing.T) {
t.Fatalf("Expected an error, got %q", resp.Data)
}

// Or if we expect that there are no messages by setting "0" as the expected last seq
m.Header.Set(JSExpectedLastSeq, "0")
resp, err = nc.RequestMsg(m, 100*time.Millisecond)
if err != nil {
t.Fatalf("Unexpected error: %v", err)
}
if pa := getPubAckResponse(resp.Data); pa == nil || pa.Error == nil {
t.Fatalf("Expected an error, got %q", resp.Data)
}

// Now send a message with a message ID and make sure we can match that.
m = nats.NewMsg("foo.bar")
m.Data = []byte("HELLO")
Expand Down
8 changes: 4 additions & 4 deletions server/stream.go
Expand Up @@ -3187,12 +3187,12 @@ func getExpectedStream(hdr []byte) string {
}

// Fast lookup of expected stream.
func getExpectedLastSeq(hdr []byte) uint64 {
func getExpectedLastSeq(hdr []byte) (uint64, bool) {
bseq := getHeader(JSExpectedLastSeq, hdr)
if len(bseq) == 0 {
return 0
return 0, false
}
return uint64(parseInt64(bseq))
return uint64(parseInt64(bseq)), true
}

// Fast lookup of rollups.
Expand Down Expand Up @@ -3472,7 +3472,7 @@ func (mset *stream) processJetStreamMsg(subject, reply string, hdr, msg []byte,
return errors.New("expected stream does not match")
}
// Expected last sequence.
if seq := getExpectedLastSeq(hdr); seq > 0 && seq != mset.lseq {
if seq, exists := getExpectedLastSeq(hdr); exists && seq != mset.lseq {
mlseq := mset.lseq
mset.clfs++
mset.mu.Unlock()
Expand Down