-
Notifications
You must be signed in to change notification settings - Fork 3
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
fixed: offset replay mechanism #2
Conversation
devansh42
commented
Aug 5, 2023
- previously we were seeking for byte offset but now we'll seek entry offset
- changed wal file naming convention to ease offset replaying
…ffset but now we'll seek for entry offset, also changed wal file naming convention
Instead of fixing the byte size of the file, we can set a limit that we will store maximum 1000 lines in one segment. We can name the file with the starting segment. This will help us read from a particular monotonically incrementing counter for the entire wal.( the counter will increment once for every entry into the wal) |
The problem, here is the random seeks we need to make to go to exact
offset. With 1000 lines or entries max solution we would have the same
issue that is jumping on a given offset
…On Sun, 6 Aug, 2023, 2:14 pm Aarthik Rao, ***@***.***> wrote:
Instead of fixing the byte size of the file, we can set a limit that we
will store maximum 1000 lines in one segment. We can name the file with the
starting segment. This will help us read from a particular monotonically
incrementing counter for the entire wal.( the counter will increment once
for every entry into the wal)
—
Reply to this email directly, view it on GitHub
<#2 (comment)>, or
unsubscribe
<https://github.com/notifications/unsubscribe-auth/AFADX7VMYPRS55NSH62JHILXT5KQBANCNFSM6AAAAAA3FOYXSI>
.
You are receiving this because you authored the thread.Message ID:
***@***.***>
|
|
func (wal *WriteAheadLog) Replay(offset int64, f func([]byte) error) error { | ||
logFiles, err := filepath.Glob(wal.logFileName + "*") | ||
if err != nil { | ||
return err | ||
} | ||
|
||
for _, logFile := range logFiles { | ||
index, startingOffset, err := wal.findStartingLogFile(offset, logFiles) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we use sort the files and then start reading. It will be simpler.
wal.go
Outdated
file, err := os.Open(logFile) | ||
if err != nil { | ||
return err | ||
} | ||
defer file.Close() | ||
|
||
if _, err := file.Seek(offset, io.SeekStart); err != nil { | ||
if i > 0 { | ||
if _, err := file.Seek(0, io.SeekStart); err != nil { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm a little unclear on how this logic works. Can you please add comments.