Skip to content

How to truncate entire log?Β #20

@damemi

Description

@damemi

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!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions