Skip to content

Commit

Permalink
Support sorting of retention policies
Browse files Browse the repository at this point in the history
Sort them by name.
  • Loading branch information
otoolep committed Mar 24, 2015
1 parent 6452564 commit 51e98b8
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

### Features
- [#2058](https://github.com/influxdb/influxdb/pull/2058): Track number of queries executed in stats.
- [#2059](https://github.com/influxdb/influxdb/pull/2059): Retention policies sorted by name on return to client.

### Bugfixes
- [#2037](https://github.com/influxdb/influxdb/pull/2037): Don't check 'configExists' at Run() level
Expand Down
6 changes: 6 additions & 0 deletions database.go
Original file line number Diff line number Diff line change
Expand Up @@ -1073,6 +1073,12 @@ type RetentionPolicy struct {
shardGroups []*ShardGroup
}

type RetentionPolicies []*RetentionPolicy

func (a RetentionPolicies) Len() int { return len(a) }
func (a RetentionPolicies) Less(i, j int) bool { return a[i].Name < a[j].Name }
func (a RetentionPolicies) Swap(i, j int) { a[i], a[j] = a[j], a[i] }

// NewRetentionPolicy returns a new instance of RetentionPolicy with defaults set.
func NewRetentionPolicy(name string) *RetentionPolicy {
return &RetentionPolicy{
Expand Down
2 changes: 1 addition & 1 deletion httpd/handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ func TestHandler_RetentionPolicies(t *testing.T) {

if status != http.StatusOK {
t.Fatalf("unexpected status: %d", status)
} else if !strings.Contains(body, `{"results":[{"series":[{"columns":["name","duration","replicaN","default"],"values":[["default","0",1,true],["bar","168h0m0s",1,false]]}]}]}`) {
} else if !strings.Contains(body, `{"results":[{"series":[{"columns":["name","duration","replicaN","default"],"values":[["bar","168h0m0s",1,false],["default","0",1,true]]}]}]}`) {
t.Fatalf("Missing retention policy: %s", body)
}
}
Expand Down
3 changes: 2 additions & 1 deletion server.go
Original file line number Diff line number Diff line change
Expand Up @@ -1331,10 +1331,11 @@ func (s *Server) RetentionPolicies(database string) ([]*RetentionPolicy, error)
}

// Retrieve the policies.
a := make([]*RetentionPolicy, 0, len(db.policies))
a := make(RetentionPolicies, 0, len(db.policies))
for _, p := range db.policies {
a = append(a, p)
}
sort.Sort(a)
return a, nil
}

Expand Down

0 comments on commit 51e98b8

Please sign in to comment.