hashicorp / raft-wal

experimental raft storage
Mozilla Public License 2.0
86 stars 8 forks source link

Changes needed to make raft-wal work in Vault #4

Closed ncabatoff closed 3 years ago

ncabatoff commented 3 years ago

These may not be Vault-specific, it's just that it was while integrating raft-wal in Vault that this work was done.

Add wal methods Vault wants: DeleteAll to delete all logs without needing to know FirstIndex/LastIndex, and GetSealedLogPath to make it easy to archive sealed segments. Also as a debugging convenience, allow passing in an hclog as part of config.

When opening an existing logstore, set lastIndex based on last log segment.

Support deleting all logs, whether via DeleteAll or a DeleteRange that covers all indexes. This is needed for when the node applies a snapshot, rendering all logs obsolete. Since after deleting all logs lastIndex must be zero, some code had to change to tolerate lastIndex=0 but nextIndex!=1, e.g. updateIndexs, StoreLogs.

Fix a few small bugs, e.g. createSegment shouldn't allow opening in O_RDONLY, openExistingSegment wasn't specifying a filemode, celarCachedSegment had a nil pointer panic.

Finally, lots of changes to segment.go to add godoc and replace literals with constants. Along the way I replaced a bunch of uint32 types with int. The on-disk format still uses uint32 for these cases (record size, record offset) but most of the code that doesn't involve (de)serialization now works with ints because I felt it was more readable.