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

wal, ioutil: set page offset for encoder #6544

Merged
merged 2 commits into from
Sep 28, 2016
Merged

Conversation

gyuho
Copy link
Contributor

@gyuho gyuho commented Sep 28, 2016

Fix #6515.

Previously page writer was not aware of page offset of the given writer. Then mis-computed actual offset of unaligned pages. This passes the starting page offset to page writer to position the right offset for next flushing.

/cc @heyitsanthony Please review.

Do you think tests in wal is needed? The offset calculation is not exported though.

@@ -38,9 +36,10 @@ type PageWriter struct {
bufWatermarkBytes int
}

func NewPageWriter(w io.Writer, pageBytes int) *PageWriter {
func NewPageWriter(w io.Writer, pageOffset, pageBytes int) *PageWriter {
Copy link
Contributor

Choose a reason for hiding this comment

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

NewPageWriter(w io.Writer, pageBytes, pageOffset int) *PageWriter -- order the arguments by importance; the page size is more important to the operation of the writer than the offset since the offset can be dropped in the default cases (i.e., a new file) and the writer will work, but the page size must always be provided.

@@ -377,7 +384,7 @@ func (w *WAL) cut() error {
// update writer and save the previous crc
w.locks = append(w.locks, newTail)
prevCrc := w.encoder.crc.Sum32()
w.encoder = newEncoder(w.tail(), prevCrc)
w.encoder = newEncoder(w.tail(), int(off), prevCrc)
Copy link
Contributor

Choose a reason for hiding this comment

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

this is writing to a new file, the offset should be 0

@@ -39,9 +39,9 @@ type encoder struct {
uint64buf []byte
}

func newEncoder(w io.Writer, prevCrc uint32) *encoder {
func newEncoder(w io.Writer, offset int, prevCrc uint32) *encoder {
Copy link
Contributor

@heyitsanthony heyitsanthony Sep 28, 2016

Choose a reason for hiding this comment

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

Passing the offset into this is evidently error-prone. Have a second function newFileEncoder(f *os.File, prevCrc uint32) *encoder instead of adding the offset to this function?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Right will fix. Thanks.

@gyuho
Copy link
Contributor Author

gyuho commented Sep 28, 2016

@heyitsanthony PTAL. Thanks.

@heyitsanthony
Copy link
Contributor

lgtm

@gyuho gyuho merged commit 2353cbc into etcd-io:master Sep 28, 2016
@gyuho gyuho deleted the page-offset branch September 28, 2016 18:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants