Skip to content

Commit

Permalink
Simplifications
Browse files Browse the repository at this point in the history
  • Loading branch information
jwilder committed Jul 29, 2016
1 parent c1840be commit 5576e7f
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 22 deletions.
25 changes: 8 additions & 17 deletions tsdb/engine/tsm1/file_store.go
Original file line number Diff line number Diff line change
Expand Up @@ -635,35 +635,26 @@ func (f *FileStore) walkFiles(fn func(f TSMFile) error) error {
defer f.mu.RUnlock()

// struct to hold the result of opening each reader in a goroutine
type res struct {
err error
}

resC := make(chan res)
var n int

errC := make(chan error, len(f.files))
for _, f := range f.files {
n++

go func(tsm TSMFile) {
if err := fn(tsm); err != nil {
resC <- res{err: fmt.Errorf("file %s: %s", tsm.Path(), err)}
errC <- fmt.Errorf("file %s: %s", tsm.Path(), err)
return
}

resC <- res{}
errC <- nil
}(f)
}

var err error
for i := 0; i < n; i++ {
res := <-resC
if res.err != nil {
err = res.err
for i := 0; i < cap(errC); i++ {
res := <-errC
if res != nil {
return res
}
}
close(resC)
return err
return nil
}

// locations returns the files and index blocks for a key and time. ascending indicates
Expand Down
2 changes: 1 addition & 1 deletion tsdb/engine/tsm1/reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ func (t *TSMReader) applyTombstones() error {
}
batch = append(batch, ts.Key)

if len(batch) > 4096 {
if len(batch) >= 4096 {
t.index.DeleteRange(batch, prev.Min, prev.Max)
batch = batch[:0]
}
Expand Down
10 changes: 6 additions & 4 deletions tsdb/engine/tsm1/tombstone.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@ import (
"sync"
)

const v2header = 0x1502
const (
v2header = 0x1502
v2headerSize = 4
)

type Tombstoner struct {
mu sync.Mutex
Expand Down Expand Up @@ -116,8 +119,7 @@ func (t *Tombstoner) Walk(fn func(t Tombstone) error) error {
defer f.Close()

var b [4]byte
_, err = f.Read(b[:])
if err != nil {
if _, err := f.Read(b[:]); err != nil {
// Might be a zero length file which should not exist, but
// an old bug allowed them to occur. Treat it as an empty
// v1 tombstone file so we don't abort loading the TSM file.
Expand Down Expand Up @@ -221,7 +223,7 @@ func (t *Tombstoner) readTombstoneV1(f *os.File, fn func(t Tombstone) error) err
// format is binary.
func (t *Tombstoner) readTombstoneV2(f *os.File, fn func(t Tombstone) error) error {
// Skip header, already checked earlier
if _, err := f.Seek(4, os.SEEK_SET); err != nil {
if _, err := f.Seek(v2headerSize, os.SEEK_SET); err != nil {
return err
}
n := int64(4)
Expand Down

0 comments on commit 5576e7f

Please sign in to comment.