Skip to content

Commit

Permalink
Fixed windows compatibility issue, when storage gateway syncs index f…
Browse files Browse the repository at this point in the history
…iles to local disk.

Signed-off-by: henrikschristensen <51989221+henrikschristensen@users.noreply.github.com>
  • Loading branch information
henrikschristensen committed Feb 21, 2024
1 parent 70c8eb6 commit b3487cf
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Expand Up @@ -11,9 +11,10 @@ We use *breaking :warning:* to mark changes that are not backward compatible (re
## Unreleased

### Fixed

- [#7083](https://github.com/thanos-io/thanos/pull/7083) Store Gateway: Fix lazy expanded postings with 0 length failed to be cached.
- [#7080](https://github.com/thanos-io/thanos/pull/7080) Receive: race condition in handler Close() when stopped early
- [#7148](https://github.com/thanos-io/thanos/pull/7148) Store Gateway: Fix windows compatibility in index-header sync.
- [#7132](https://github.com/thanos-io/thanos/pull/7132) Documentation: fix broken helm installation instruction

### Added
Expand Down
16 changes: 14 additions & 2 deletions pkg/block/indexheader/binary_reader.go
Expand Up @@ -13,6 +13,7 @@ import (
"io"
"math"
"os"
"path"
"path/filepath"
"sort"
"sync"
Expand Down Expand Up @@ -154,6 +155,8 @@ func WriteBinary(ctx context.Context, bkt objstore.BucketReader, id ulid.ULID, f
}

if tmpFilename != "" {
// On windows renaming an open file will result in access denied error
bw.writer.Close()
// Create index-header in atomic way, to avoid partial writes (e.g during restart or crash of store GW).
return nil, os.Rename(tmpFilename, filename)
}
Expand All @@ -170,7 +173,7 @@ type chunkedIndexReader struct {
}

func newChunkedIndexReader(ctx context.Context, bkt objstore.BucketReader, id ulid.ULID) (*chunkedIndexReader, int, error) {
indexFilepath := filepath.Join(id.String(), block.IndexFilename)
indexFilepath := path.Join(id.String(), block.IndexFilename)
attrs, err := bkt.Attributes(ctx, indexFilepath)
if err != nil {
return nil, 0, errors.Wrapf(err, "get object attributes of %s", indexFilepath)
Expand Down Expand Up @@ -443,13 +446,22 @@ func (fw *FileWriter) Flush() error {
}

func (fw *FileWriter) Close() error {
if fw.f == nil {
// Allready closed

Check failure on line 450 in pkg/block/indexheader/binary_reader.go

View workflow job for this annotation

GitHub Actions / Linters (Static Analysis) for Go

`Allready` is a misspelling of `Already` (misspell)
return nil
}

if err := fw.Flush(); err != nil {
return err
}
if err := fw.f.Sync(); err != nil {
return err
}
return fw.f.Close()

err := fw.Close()
// Mark file descriptor as closed
fw.f = nil
return err
}

func (fw *FileWriter) Sync() error {
Expand Down

0 comments on commit b3487cf

Please sign in to comment.