-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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 Downsampling process; Fixed runutil.CloseAndCaptureErr
#1070
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -167,26 +167,20 @@ func (w *streamedBlockWriter) Close() error { | |
if w.finalized { | ||
return nil | ||
} | ||
|
||
var merr tsdb.MultiError | ||
w.finalized = true | ||
|
||
// Finalise data block only if there wasn't any internal errors. | ||
if !w.ignoreFinalize { | ||
merr.Add(w.finalize()) | ||
} | ||
merr := tsdb.MultiError{} | ||
|
||
for _, cl := range w.closers { | ||
merr.Add(cl.Close()) | ||
if w.ignoreFinalize { | ||
// Close open file descriptors anyway. | ||
for _, cl := range w.closers { | ||
merr.Add(cl.Close()) | ||
} | ||
return merr.Err() | ||
} | ||
|
||
return errors.Wrap(merr.Err(), "close closers") | ||
} | ||
// Finalize saves prepared index and metadata to corresponding files. | ||
|
||
// finalize saves prepared index and meta data to corresponding files. | ||
// It is called on Close. Even if an error happened outside of StreamWriter, it will finalize the block anyway, | ||
// so it's a caller's responsibility to remove the block's directory. | ||
func (w *streamedBlockWriter) finalize() error { | ||
if err := w.writeLabelSets(); err != nil { | ||
return errors.Wrap(err, "write label sets") | ||
} | ||
|
@@ -195,7 +189,15 @@ func (w *streamedBlockWriter) finalize() error { | |
return errors.Wrap(err, "write mem postings") | ||
} | ||
|
||
if err := w.writeIndexCache(); err != nil { | ||
for _, cl := range w.closers { | ||
merr.Add(cl.Close()) | ||
} | ||
|
||
if err := block.WriteIndexCache( | ||
w.logger, | ||
filepath.Join(w.blockDir, block.IndexFilename), | ||
filepath.Join(w.blockDir, block.IndexCacheFilename), | ||
); err != nil { | ||
return errors.Wrap(err, "write index cache") | ||
} | ||
|
||
|
@@ -207,8 +209,14 @@ func (w *streamedBlockWriter) finalize() error { | |
return errors.Wrap(err, "sync blockDir") | ||
} | ||
|
||
if err := merr.Err(); err != nil { | ||
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. it's better to put it before 196 line to avoid wasting time/resources on writing index cache 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. You are right. Do you have time for small PR on this? (: |
||
return errors.Wrap(err, "finalize") | ||
} | ||
|
||
// No error, claim success. | ||
|
||
level.Info(w.logger).Log( | ||
"msg", "write downsampled block", | ||
"msg", "finalized downsampled block", | ||
"mint", w.meta.MinTime, | ||
"maxt", w.meta.MaxTime, | ||
"ulid", w.meta.ULID, | ||
|
@@ -224,7 +232,7 @@ func (w *streamedBlockWriter) syncDir() (err error) { | |
return errors.Wrap(err, "open temporary block blockDir") | ||
} | ||
|
||
defer runutil.CloseWithErrCapture(w.logger, &err, df, "close temporary block blockDir") | ||
defer runutil.CloseWithErrCapture(&err, df, "close temporary block blockDir") | ||
|
||
if err := fileutil.Fsync(df); err != nil { | ||
return errors.Wrap(err, "sync temporary blockDir") | ||
|
@@ -257,16 +265,6 @@ func (w *streamedBlockWriter) writeMemPostings() error { | |
return nil | ||
} | ||
|
||
func (w *streamedBlockWriter) writeIndexCache() error { | ||
indexFile := filepath.Join(w.blockDir, block.IndexFilename) | ||
indexCacheFile := filepath.Join(w.blockDir, block.IndexCacheFilename) | ||
if err := block.WriteIndexCache(w.logger, indexFile, indexCacheFile); err != nil { | ||
return errors.Wrap(err, "write index cache") | ||
} | ||
|
||
return nil | ||
} | ||
|
||
// writeMetaFile writes meta file. | ||
func (w *streamedBlockWriter) writeMetaFile() error { | ||
w.meta.Version = metadata.MetaVersion1 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
package runutil | ||
|
||
import ( | ||
"github.com/pkg/errors" | ||
"io" | ||
"testing" | ||
) | ||
|
||
type testCloser struct { | ||
err error | ||
} | ||
|
||
func (c testCloser) Close() error { | ||
return c.err | ||
} | ||
|
||
func TestCloseWithErrCapture(t *testing.T) { | ||
for _, tcase := range []struct{ | ||
err error | ||
closer io.Closer | ||
|
||
expectedErrStr string | ||
}{ | ||
{ | ||
err: nil, | ||
closer: testCloser{err:nil}, | ||
expectedErrStr: "", | ||
}, | ||
{ | ||
err: errors.New("test"), | ||
closer: testCloser{err:nil}, | ||
expectedErrStr: "test", | ||
}, | ||
{ | ||
err: nil, | ||
closer: testCloser{err:errors.New("test")}, | ||
expectedErrStr: "close: test", | ||
}, | ||
{ | ||
err: errors.New("test"), | ||
closer: testCloser{err:errors.New("test")}, | ||
expectedErrStr: "2 errors: test; close: test", | ||
}, | ||
}{ | ||
if ok := t.Run("", func(t *testing.T) { | ||
ret := tcase.err | ||
CloseWithErrCapture(&ret, tcase.closer, "close") | ||
|
||
if tcase.expectedErrStr == "" { | ||
if ret != nil { | ||
t.Error("Expected error to be nil") | ||
t.Fail() | ||
} | ||
} else { | ||
if ret == nil { | ||
t.Error("Expected error to be not nil") | ||
t.Fail() | ||
} | ||
|
||
if tcase.expectedErrStr != ret.Error() { | ||
t.Errorf("%s != %s", tcase.expectedErrStr, ret.Error()) | ||
t.Fail() | ||
} | ||
} | ||
|
||
}); !ok { | ||
return | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
forgot to wrap an error