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

fixed: offset replay mechanism #2

Merged
merged 6 commits into from
Aug 8, 2023

Conversation

devansh42
Copy link
Contributor

  1. previously we were seeking for byte offset but now we'll seek entry offset
  2. changed wal file naming convention to ease offset replaying

…ffset but now we'll seek for entry offset, also changed wal file naming convention
@aarthikrao
Copy link
Owner

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)

@devansh42
Copy link
Contributor Author

devansh42 commented Aug 6, 2023 via email

@devansh42
Copy link
Contributor Author

  • Added buffer reader, it would fasten the process of offset seeking, as while seeking record by record we are going to read the same memory page multiple times. Reading one page at a time while reduce redundant page reads as well.

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)
Copy link
Owner

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 {
Copy link
Owner

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.

@aarthikrao aarthikrao merged commit c1907c1 into aarthikrao:main Aug 8, 2023
1 check passed
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 this pull request may close these issues.

2 participants