From 21343e4e0f6fa6c1666b47cc91770c8b6965cbe6 Mon Sep 17 00:00:00 2001 From: Philip O'Toole Date: Tue, 9 Jun 2015 11:37:49 -0700 Subject: [PATCH] Don't panic when altering retention policy Fixes issue #2846 --- CHANGELOG.md | 1 + meta/statement_executor_test.go | 14 ++++++++++++-- meta/store.go | 2 +- 3 files changed, 14 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a7fb3fb98c..60511ee2f1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ - [2838](https://github.com/influxdb/influxdb/pull/2838) -- Set auto-created retention policy period to infinite. - [2829](https://github.com/influxdb/influxdb/pull/2829) -- Re-enable Graphite support as a new Service-style component. - [2814](https://github.com/influxdb/influxdb/issues/2814) -- Convert collectd to a service. +- [2852](https://github.com/influxdb/influxdb/pull/2852) -- Don't panic when altering retention policies. Thanks for the report @huhongbo ## v0.9.0-rc32 [2015-06-07] diff --git a/meta/statement_executor_test.go b/meta/statement_executor_test.go index 46a7068d55..6de0b754a7 100644 --- a/meta/statement_executor_test.go +++ b/meta/statement_executor_test.go @@ -367,9 +367,9 @@ func TestStatementExecutor_ExecuteStatement_AlterRetentionPolicy(t *testing.T) { t.Fatalf("unexpected database: %s", database) } else if name != "rp0" { t.Fatalf("unexpected name: %s", name) - } else if *rpu.Duration != 7*24*time.Hour { + } else if rpu.Duration != nil && *rpu.Duration != 7*24*time.Hour { t.Fatalf("unexpected duration: %v", *rpu.Duration) - } else if *rpu.ReplicaN != 2 { + } else if rpu.ReplicaN != nil && *rpu.ReplicaN != 2 { t.Fatalf("unexpected replication factor: %v", *rpu.ReplicaN) } return nil @@ -387,6 +387,16 @@ func TestStatementExecutor_ExecuteStatement_AlterRetentionPolicy(t *testing.T) { if res := e.ExecuteStatement(stmt); res.Err != nil { t.Fatalf("unexpected error: %s", res.Err) } + + stmt = influxql.MustParseStatement(`ALTER RETENTION POLICY rp0 ON foo DURATION 7d`) + if res := e.ExecuteStatement(stmt); res.Err != nil { + t.Fatalf("unexpected error: %s", res.Err) + } + + stmt = influxql.MustParseStatement(`ALTER RETENTION POLICY rp0 ON foo REPLICATION 2`) + if res := e.ExecuteStatement(stmt); res.Err != nil { + t.Fatalf("unexpected error: %s", res.Err) + } } // Ensure a ALTER RETENTION POLICY statement returns errors from the store. diff --git a/meta/store.go b/meta/store.go index 70094471bf..2115734cc2 100644 --- a/meta/store.go +++ b/meta/store.go @@ -719,7 +719,7 @@ func (s *Store) UpdateRetentionPolicy(database, name string, rpu *RetentionPolic } var replicaN *uint32 - if rpu.Duration != nil { + if rpu.ReplicaN != nil { value := uint32(*rpu.ReplicaN) replicaN = &value }