Merge pull request #1406 from influxdb/fix-default-rp
fix CREATE RETENTION POLICY ... DEFAULTpull/1407/head
commit
843afd2dd8
|
@ -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)
|
||||||
|
|
14
server.go
14
server.go
|
@ -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 {
|
||||||
|
|
Loading…
Reference in New Issue