Repository: nats-io/nats-server
Pull request #1681 (2020-10-29 19:25:32)

JetStream: clear erased bit when reading sequence number
Also changed the link to travis-ci.com instead of .org

Signed-off-by: Ivan Kozlovic <ivan@synadia.com>



Patch:
diff --git a/README.md b/README.md
index 61dc2695..d9b60244 100644
--- a/README.md
+++ b/README.md
@@ -27,8 +27,8 @@ If you are interested in contributing to NATS, read about our...
 [License-Image]: https://img.shields.io/badge/License-Apache2-blue.svg
 [Fossa-Url]: https://app.fossa.io/projects/git%2Bgithub.com%2Fnats-io%2Fgnatsd?ref=badge_shield
 [Fossa-Image]: https://app.fossa.io/api/projects/git%2Bgithub.com%2Fnats-io%2Fgnatsd.svg?type=shield
-[Build-Status-Url]: https://travis-ci.org/nats-io/nats-server
-[Build-Status-Image]: https://travis-ci.org/nats-io/nats-server.svg?branch=master
+[Build-Status-Url]: https://travis-ci.com/github/nats-io/nats-server
+[Build-Status-Image]: https://travis-ci.com/nats-io/nats-server.svg?branch=master
 [Release-Url]: https://github.com/nats-io/nats-server/releases/tag/v2.1.8
 [Release-image]: https://img.shields.io/badge/release-v2.1.8-1eb0fc.svg
 [Coverage-Url]: https://coveralls.io/r/nats-io/nats-server?branch=master
diff --git a/server/filestore.go b/server/filestore.go
index 3d05243d..afa4f25c 100644
--- a/server/filestore.go
+++ b/server/filestore.go
@@ -434,7 +434,8 @@ func (fs *fileStore) recoverMsgBlock(fi os.FileInfo, index uint64) *msgBlock {
 
 		// This is an old erased message, or a new one that we can track.
 		if seq == 0 || seq&ebit != 0 {
-			addToDmap(seq &^ ebit)
+			seq = seq &^ ebit
+			addToDmap(seq)
 			offset += int64(rl)
 			continue
 		}
@@ -2086,7 +2087,7 @@ func (mb *msgBlock) readIndexInfo() error {
 			return 0
 		}
 		bi += n
-		return seq
+		return seq &^ ebit
 	}
 	readCount := readSeq
 	readTimeStamp := func() int64 {


Test patch:
diff --git a/server/filestore_test.go b/server/filestore_test.go
index 6e079b9e..97e05772 100644
--- a/server/filestore_test.go
+++ b/server/filestore_test.go
@@ -293,13 +293,14 @@ func TestFileStoreSkipMsg(t *testing.T) {
 	fs.SkipMsg()
 	fs.SkipMsg()
 	fs.StoreMsg("zzz", nil, []byte("Hello World!"))
+	fs.SkipMsg()
 
 	state = fs.State()
 	if state.Msgs != 2 {
 		t.Fatalf("Expected %d msgs, got %d", 2, state.Msgs)
 	}
-	if state.FirstSeq != uint64(numSkips+1) || state.LastSeq != uint64(numSkips+4) {
-		t.Fatalf("Expected first to be %d and last to be %d. got first %d and last %d", numSkips+1, numSkips+4, state.FirstSeq, state.LastSeq)
+	if state.FirstSeq != uint64(numSkips+1) || state.LastSeq != uint64(numSkips+5) {
+		t.Fatalf("Expected first to be %d and last to be %d. got first %d and last %d", numSkips+1, numSkips+5, state.FirstSeq, state.LastSeq)
 	}
 
 	// Make sure we recover same state.
@@ -315,8 +316,8 @@ func TestFileStoreSkipMsg(t *testing.T) {
 	if state.Msgs != 2 {
 		t.Fatalf("Expected %d msgs, got %d", 2, state.Msgs)
 	}
-	if state.FirstSeq != uint64(numSkips+1) || state.LastSeq != uint64(numSkips+4) {
-		t.Fatalf("Expected first to be %d and last to be %d. got first %d and last %d", numSkips+1, numSkips+4, state.FirstSeq, state.LastSeq)
+	if state.FirstSeq != uint64(numSkips+1) || state.LastSeq != uint64(numSkips+5) {
+		t.Fatalf("Expected first to be %d and last to be %d. got first %d and last %d", numSkips+1, numSkips+5, state.FirstSeq, state.LastSeq)
 	}
 
 	subj, _, msg, _, err := fs.LoadMsg(11)
@@ -332,8 +333,8 @@ func TestFileStoreSkipMsg(t *testing.T) {
 	if err != nil {
 		t.Fatalf("Unexpected error looking up seq 11: %v", err)
 	}
-	if nseq != 16 {
-		t.Fatalf("Expected seq of %d but got %d", 16, nseq)
+	if nseq != 17 {
+		t.Fatalf("Expected seq of %d but got %d", 17, nseq)
 	}
 
 	// Make sure we recover same state.