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

Fix SHOW MEASUREMENTS across the cluster #4833

Merged
merged 1 commit into from
Nov 25, 2015
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 31 additions & 14 deletions tsdb/show_measurements.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,15 +53,20 @@ func (e *ShowMeasurementsExecutor) Execute() <-chan *models.Row {
continue
}

// Convert the mapper chunk to a string array of measurement names.
mms, ok := c.([]string)
// Convert the mapper chunk to MapperOutput type.
mop, ok := c.(*MapperOutput)
if !ok {
out <- &models.Row{Err: fmt.Errorf("show measurements mapper returned invalid type: %T", c)}
return
}

// Add the measurement names to the set.
for _, mm := range mms {
for _, mv := range mop.Values {
mm, ok := mv.Value.(string)
if !ok {
out <- &models.Row{Err: fmt.Errorf("show measurements mapper returned invalid type: %T", mop)}
return
}
set[mm] = struct{}{}
}
}
Expand Down Expand Up @@ -204,21 +209,25 @@ func (m *ShowMeasurementsMapper) NextChunk() (interface{}, error) {
return nil, nil
}

names := []string{}
if err := json.Unmarshal(b.([]byte), &names); err != nil {
mop := &MapperOutput{
Name: "measurements",
Fields: []string{"name"},
Values: make([]*MapperValue, 0),
}

if err := json.Unmarshal(b.([]byte), &mop); err != nil {
return nil, err
} else if len(names) == 0 {
// Mapper on other node sent 0 values so it's done.
return nil, nil
}
return names, nil

return mop, nil
}
return m.nextChunk()
}

// nextChunk implements next chunk logic for a local shard.
func (m *ShowMeasurementsMapper) nextChunk() (interface{}, error) {
// Allocate array to hold measurement names.
var output *MapperOutput

names := make([]string, 0, m.ChunkSize)

// Get the channel of measurement names from the state.
Expand All @@ -231,12 +240,20 @@ func (m *ShowMeasurementsMapper) nextChunk() (interface{}, error) {
break
}
}
// See if we've read all the names.
if len(names) == 0 {
return nil, nil

output = &MapperOutput{
Name: "measurements",
Fields: []string{"name"},
Values: make([]*MapperValue, 0, len(names)),
}

for _, v := range names {
output.Values = append(output.Values, &MapperValue{
Value: v,
})
}

return names, nil
return output, nil
}

// Close closes the mapper.
Expand Down