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

Purging subjects using file storage doesn't update the first seq correctly #4041

Closed
2 tasks done
MauriceVanVeen opened this issue Apr 12, 2023 · 2 comments · Fixed by #4042
Closed
2 tasks done

Purging subjects using file storage doesn't update the first seq correctly #4041

MauriceVanVeen opened this issue Apr 12, 2023 · 2 comments · Fixed by #4042

Comments

@MauriceVanVeen
Copy link
Contributor

Defect

Make sure that these boxes are checked before submitting your issue -- thank you!

[1] 2023/04/12 08:26:57.409824 [INF] Starting nats-server
[1] 2023/04/12 08:26:57.409898 [INF]   Version:  2.9.15
[1] 2023/04/12 08:26:57.409900 [INF]   Git:      [b91fa85]
[1] 2023/04/12 08:26:57.409901 [INF]   Name:     NDPQFSNXRAAYAREAM4CLTMZAKMLPMI4GHOS4XPQEU46NEBPZEPS4QSZD
[1] 2023/04/12 08:26:57.409905 [INF]   Node:     gpgKsVwa
[1] 2023/04/12 08:26:57.409907 [INF]   ID:       NDPQFSNXRAAYAREAM4CLTMZAKMLPMI4GHOS4XPQEU46NEBPZEPS4QSZD
[1] 2023/04/12 08:26:57.412407 [INF] Starting JetStream
[1] 2023/04/12 08:26:57.412692 [INF]     _ ___ _____ ___ _____ ___ ___   _   __  __
[1] 2023/04/12 08:26:57.412696 [INF]  _ | | __|_   _/ __|_   _| _ \ __| /_\ |  \/  |
[1] 2023/04/12 08:26:57.412697 [INF] | || | _|  | | \__ \ | | |   / _| / _ \| |\/| |
[1] 2023/04/12 08:26:57.412698 [INF]  \__/|___| |_| |___/ |_| |_|_\___/_/ \_\_|  |_|
[1] 2023/04/12 08:26:57.412699 [INF] 
[1] 2023/04/12 08:26:57.412700 [INF]          https://docs.nats.io/jetstream
[1] 2023/04/12 08:26:57.412701 [INF] 
[1] 2023/04/12 08:26:57.412702 [INF] ---------------- JETSTREAM ----------------
[1] 2023/04/12 08:26:57.412705 [INF]   Max Memory:      11.25 GB
[1] 2023/04/12 08:26:57.412706 [INF]   Max Storage:     125.81 GB
[1] 2023/04/12 08:26:57.412707 [INF]   Store Directory: "/tmp/nats/jetstream"
[1] 2023/04/12 08:26:57.412708 [INF] -------------------------------------------
[1] 2023/04/12 08:26:57.413328 [INF] Listening for client connections on 0.0.0.0:4222
[1] 2023/04/12 08:26:57.413648 [INF] Server is ready

Versions of nats-server and affected client libraries used:

nats-server 2.9.15
natsio/nats-box latest

OS/Container environment:

Using docker:

docker run --network host nats -js
docker run --rm --network host -it --name nats-cli natsio/nats-box

Steps or code to reproduce the issue:

  1. Create an OBJ bucket:
    nats obj add bucket --storage=file
    (to demonstrate when having many messages spanning multiple message blocks)

  2. Create a file with random data:
    head -c 100000000 </dev/urandom > bucket_data

  3. Put the data into the bucket:
    nats obj put bucket bucket_data -f

  4. nats str info -a OBJ_bucket
    Expected: state.FirstSeq = 1, state.LastSeq = 764, state.NumDeleted = 0
    Actual: equals ^

  5. Put the data into the bucket again, to start purging previous data:
    nats obj put bucket bucket_data -f

  6. nats str info -a OBJ_bucket
    Expected: state.FirstSeq = 765, state.LastSeq = 1528, state.NumDeleted = 0
    Actual: state.FirstSeq = 63, state.LastSeq = 1528, state.NumDeleted = 702

Expected result:

A stream's first seq should be correct after purging from a subject.

Only occurs when using file storage, memory storage works as expected.

Actual result:

A stream's first seq stops being updated.

@derekcollison
Copy link
Member

What is message 63? nats str get OBJ_bucket 63

derekcollison added a commit that referenced this issue Apr 12, 2023
…4042)

Resolves #4041

Keeps `firstSeqNeedsUpdate` set if set previously, to ensure the
FirstSeq gets updated.
@MauriceVanVeen
Copy link
Contributor Author

The fix is already merged, but for completeness:

State:

             Messages: 764
                Bytes: 95 MiB
             FirstSeq: 63 @ 2023-04-12T19:14:20 UTC
              LastSeq: 1,528 @ 2023-04-12T19:14:34 UTC
     Deleted Messages: 702
     Active Consumers: 0
   Number of Subjects: 2

:~# nats str get -a
? Select a Stream OBJ_bucket
? Message Sequence to retrieve 63
nats: error: could not retrieve OBJ_bucket#63: no message found (10037)

After purging the subject there is no message there any more, the FirstSeq was not being updated if multiple blocks were removed.

@bruth bruth removed the 🐞 bug label Aug 18, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants