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

How to truncate entire log? #20

Open
damemi opened this issue Jun 2, 2023 · 0 comments · May be fixed by #29
Open

How to truncate entire log? #20

damemi opened this issue Jun 2, 2023 · 0 comments · May be fixed by #29

Comments

@damemi
Copy link

damemi commented Jun 2, 2023

Hi, from testing this library out and reading the code it looks like the log must always have at least one entry following a truncate. I am curious why this is a requirement?

The issue I'm hitting is when trying to truncate the final entry in the log. For example, if I push three objects onto the log:

err = log.Write(1, []byte(obj1))
err = log.Write(2, []byte(obj2))
err = log.Write(3, []byte(obj3))

As I read these entries, I want to remove them from the log once I'm done with them. So I do something like:

data1, err := log.Read(1)
useData(data1)
// truncate index 1 and make index 2 the new front
err = log.TruncateFront(2)

data2, err := log.Read(2)
useData(data2)
// truncate index 2 and make index 3 the new front
err = log.TruncateFront(3)

data3, err := log.Read(3)
useData(data3)
// truncate index 3 and make index 4 the new front
// this fails with ErrOutOfRange
err = log.TruncateFront(4)

Obviously, the final log.TruncateFront(4) call fails with ErrOutOfRange. This keeps data3 in the log. At this point, if my process crashes and restarts, it will still see data3 in the log and try to call useData(data3), resulting in a duplicate transaction.

Is there a way to completely flush/truncate the log when no more entries are valid? I might be missing something obvious.

Thanks for the work on this!

@DStrand1 DStrand1 linked a pull request Jul 30, 2024 that will close this issue
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.

1 participant