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

Implement WriteAheadLog #640

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open

Implement WriteAheadLog #640

wants to merge 8 commits into from

Conversation

Kubuxu
Copy link
Contributor

@Kubuxu Kubuxu commented Sep 12, 2024

Pushing the first commit with complete implementation of WAL for peliminary review.
Integration in progress.

@rjan90 rjan90 linked an issue Sep 12, 2024 that may be closed by this pull request
@Kubuxu
Copy link
Contributor Author

Kubuxu commented Sep 12, 2024

@masih @Stebalien I would appriciate a light review of the WAL itself, integration is incoming after I fix some issues in it.

Copy link

codecov bot commented Sep 12, 2024

Codecov Report

Attention: Patch coverage is 70.55215% with 48 lines in your changes missing coverage. Please review.

Please upload report for BASE (main@5724153). Learn more about missing BASE report.

Files with missing lines Patch % Lines
internal/writeaheadlog/wal.go 69.78% 23 Missing and 19 partials ⚠️
f3.go 64.70% 3 Missing and 3 partials ⚠️
Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff           @@
##             main     #640   +/-   ##
=======================================
  Coverage        ?   79.25%           
=======================================
  Files           ?       54           
  Lines           ?     4878           
  Branches        ?        0           
=======================================
  Hits            ?     3866           
  Misses          ?      635           
  Partials        ?      377           
Files with missing lines Coverage Δ
host.go 70.42% <100.00%> (ø)
wal.go 100.00% <100.00%> (ø)
f3.go 71.25% <64.70%> (ø)
internal/writeaheadlog/wal.go 69.78% <69.78%> (ø)

internal/writeaheadlog/wal.go Show resolved Hide resolved
internal/writeaheadlog/wal.go Outdated Show resolved Hide resolved
internal/writeaheadlog/wal.go Outdated Show resolved Hide resolved
internal/writeaheadlog/wal.go Outdated Show resolved Hide resolved
internal/writeaheadlog/wal.go Outdated Show resolved Hide resolved
internal/writeaheadlog/wal.go Outdated Show resolved Hide resolved
internal/writeaheadlog/wal.go Outdated Show resolved Hide resolved
internal/writeaheadlog/wal.go Outdated Show resolved Hide resolved
internal/writeaheadlog/wal.go Outdated Show resolved Hide resolved
internal/writeaheadlog/wal.go Show resolved Hide resolved
internal/writeaheadlog/wal.go Outdated Show resolved Hide resolved
internal/writeaheadlog/wal.go Show resolved Hide resolved
internal/writeaheadlog/wal.go Outdated Show resolved Hide resolved
internal/writeaheadlog/wal.go Show resolved Hide resolved
internal/writeaheadlog/wal.go Show resolved Hide resolved
internal/writeaheadlog/wal.go Show resolved Hide resolved
internal/writeaheadlog/wal.go Show resolved Hide resolved
internal/writeaheadlog/wal.go Outdated Show resolved Hide resolved
@Kubuxu Kubuxu marked this pull request as ready for review September 18, 2024 12:42
Kubuxu and others added 6 commits September 18, 2024 15:04
Signed-off-by: Jakub Sztandera <oss@kubuxu.com>
Signed-off-by: Jakub Sztandera <oss@kubuxu.com>
Signed-off-by: Jakub Sztandera <oss@kubuxu.com>
Signed-off-by: Jakub Sztandera <oss@kubuxu.com>
Co-authored-by: Masih H. Derkani <m@derkani.org>
Signed-off-by: Jakub Sztandera <oss@kubuxu.com>
Signed-off-by: Jakub Sztandera <oss@kubuxu.com>

err := wal.hydrate()
if err != nil {
return nil, fmt.Errorf("reading the WAL: %v", err)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might as well wrap error?

Suggested change
return nil, fmt.Errorf("reading the WAL: %v", err)
return nil, fmt.Errorf("reading the WAL: %w", err)

}

type logStat struct {
logname string
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Either name or logName?

Suggested change
logname string
logName string

return nil
}

const walExtension = ".wal.cbor"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Subjective: Would be easier to read if all constants are grouped at the top.

return nil
}

const roatateAt = 1 << 20 // 1MiB
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
const roatateAt = 1 << 20 // 1MiB
const rotateAt = 1 << 20 // 1MiB

}

// Purge removes files containing entries only older than keepEpoch
// It is not guarnateed to remove all entries older than keepEpoch as it will keep the current
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// It is not guarnateed to remove all entries older than keepEpoch as it will keep the current
// It is not guaranteed to remove all entries older than keepEpoch as it will keep the current


switch {
case err == nil:
// the EOF case is expected, this is slightly unexpected by still handle it
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// the EOF case is expected, this is slightly unexpected by still handle it
// the EOF case is expected, this is slightly unexpected but still handle it

func (wal *WriteAheadLog[T, PT]) readLogFile(logname string, keepVaues bool) (logStat, []T, error) {
var res logStat
if len(logname) == 0 {
return res, nil, fmt.Errorf("empty logname")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
return res, nil, fmt.Errorf("empty logname")
return res, nil, errors.New("empty logname")

@@ -0,0 +1,177 @@
package writeaheadlog
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would be sweet to have a concurrency stress test.

Signed-off-by: Jakub Sztandera <oss@kubuxu.com>
Signed-off-by: Jakub Sztandera <oss@kubuxu.com>
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.

Write Ahead Log & Rebroadcast
3 participants