Merge pull request #1406 from influxdb/fix-default-rp

fix CREATE RETENTION POLICY ... DEFAULT
pull/1407/head
dgnorton 2015-01-28 14:31:32 -05:00
commit 843afd2dd8
2 changed files with 36 additions and 1 deletions

View File

@ -184,6 +184,29 @@ func TestHandler_CreateRetentionPolicy(t *testing.T) {
} }
} }
func TestHandler_CreateRetentionPolicyAsDefault(t *testing.T) {
srvr := OpenServer(NewMessagingClient())
srvr.CreateDatabase("foo")
s := NewHTTPServer(srvr)
defer s.Close()
query := map[string]string{"q": "CREATE RETENTION POLICY bar ON foo DURATION 1h REPLICATION 1 DEFAULT"}
status, body := MustHTTP("GET", s.URL+`/query`, query, nil, "")
if status != http.StatusOK {
t.Fatalf("unexpected status: %d", status)
} else if body != `{"results":[{}]}` {
t.Fatalf("unexpected body: %s", body)
}
rp, err := srvr.DefaultRetentionPolicy("foo")
if err != nil {
t.Fatal(err)
} else if rp.Name != "bar" {
t.Fatalf("default retention policy mismatch:\n exp=%s\n got=%s\n", "bar", rp.Name)
}
}
func TestHandler_CreateRetentionPolicy_DatabaseNotFound(t *testing.T) { func TestHandler_CreateRetentionPolicy_DatabaseNotFound(t *testing.T) {
srvr := OpenServer(NewMessagingClient()) srvr := OpenServer(NewMessagingClient())
s := NewHTTPServer(srvr) s := NewHTTPServer(srvr)

View File

@ -1917,7 +1917,19 @@ func (s *Server) executeCreateRetentionPolicyStatement(q *influxql.CreateRetenti
rp := NewRetentionPolicy(q.Name) rp := NewRetentionPolicy(q.Name)
rp.Duration = q.Duration rp.Duration = q.Duration
rp.ReplicaN = uint32(q.Replication) rp.ReplicaN = uint32(q.Replication)
return &Result{Err: s.CreateRetentionPolicy(q.Database, rp)}
// Create new retention policy.
err := s.CreateRetentionPolicy(q.Database, rp)
if err != nil {
return &Result{Err: s.CreateRetentionPolicy(q.Database, rp)}
}
// If requested, set new policy as the default.
if q.Default {
err = s.SetDefaultRetentionPolicy(q.Database, q.Name)
}
return &Result{Err: err}
} }
func (s *Server) executeAlterRetentionPolicyStatement(q *influxql.AlterRetentionPolicyStatement, user *User) *Result { func (s *Server) executeAlterRetentionPolicyStatement(q *influxql.AlterRetentionPolicyStatement, user *User) *Result {