-
Notifications
You must be signed in to change notification settings - Fork 454
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
Improve commitlog bootstrapping reliability in the face of sudden failures #1065
Changes from 7 commits
1ea73e3
e14887e
d559f71
b2f1def
ce48133
33c8ef6
206c1c4
deb487f
7b7c0d7
71f4ab4
33056c6
890c272
5934dd4
0921c37
aee9342
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -80,6 +80,13 @@ type commitLogWriter interface { | |
Close() error | ||
} | ||
|
||
type chunkWriterIface interface { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. naming nit: not a fan of the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yeah sure, I didn't like this either |
||
reset(f fs.FD) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: use uniform casing in method names There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Some have to be public to implement other interfaces, other methods should probably just be private...but I guess its a private interface so I guess it doesnt matter There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. embed the interface's rather than copying methods if you can help it. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. that worked actually, cheers |
||
Write(p []byte) (int, error) | ||
close() error | ||
isOpen() bool | ||
} | ||
|
||
type flushFn func(err error) | ||
|
||
type writer struct { | ||
|
@@ -89,7 +96,7 @@ type writer struct { | |
nowFn clock.NowFn | ||
start time.Time | ||
duration time.Duration | ||
chunkWriter *chunkWriter | ||
chunkWriter chunkWriterIface | ||
chunkReserveHeader []byte | ||
buffer *bufio.Writer | ||
sizeBuffer []byte | ||
|
@@ -151,7 +158,7 @@ func (w *writer) Open(start time.Time, duration time.Duration) error { | |
return err | ||
} | ||
|
||
w.chunkWriter.fd = fd | ||
w.chunkWriter.reset(fd) | ||
w.buffer.Reset(w.chunkWriter) | ||
if err := w.write(w.logEncoder.Bytes()); err != nil { | ||
w.Close() | ||
|
@@ -164,7 +171,7 @@ func (w *writer) Open(start time.Time, duration time.Duration) error { | |
} | ||
|
||
func (w *writer) isOpen() bool { | ||
return w.chunkWriter.fd != nil | ||
return w.chunkWriter.isOpen() | ||
} | ||
|
||
func (w *writer) Write( | ||
|
@@ -245,11 +252,11 @@ func (w *writer) Close() error { | |
if err := w.Flush(); err != nil { | ||
return err | ||
} | ||
if err := w.chunkWriter.fd.Close(); err != nil { | ||
if err := w.chunkWriter.close(); err != nil { | ||
return err | ||
} | ||
|
||
w.chunkWriter.fd = nil | ||
w.chunkWriter.reset(nil) | ||
w.start = timeZero | ||
w.duration = 0 | ||
w.seen.ClearAll() | ||
|
@@ -278,7 +285,7 @@ func (w *writer) write(data []byte) error { | |
} | ||
|
||
type chunkWriter struct { | ||
fd *os.File | ||
fd fs.FD | ||
flushFn flushFn | ||
buff []byte | ||
fsync bool | ||
|
@@ -292,6 +299,18 @@ func newChunkWriter(flushFn flushFn, fsync bool) *chunkWriter { | |
} | ||
} | ||
|
||
func (w *chunkWriter) reset(f fs.FD) { | ||
w.fd = f | ||
} | ||
|
||
func (w *chunkWriter) close() error { | ||
return w.fd.Close() | ||
} | ||
|
||
func (w *chunkWriter) isOpen() bool { | ||
return w.fd != nil | ||
} | ||
|
||
func (w *chunkWriter) Write(p []byte) (int, error) { | ||
size := len(p) | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -460,3 +460,13 @@ type BlockRetrieverOptions interface { | |
// IdentifierPool returns the identifierPool | ||
IdentifierPool() ident.Pool | ||
} | ||
|
||
// FD is the interface implemented by *os.File. | ||
type FD interface { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: move this to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. good call |
||
// Write bytes to the file descriptor. | ||
Write(p []byte) (int, error) | ||
// Sync fsyncs the file descriptor ensuring all writes have made it to disk. | ||
Sync() error | ||
// Close the file descriptor. | ||
Close() error | ||
} |
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.
s/change/chance/