From 4b332b73482057fd8e832b4262c73344a46fb031 Mon Sep 17 00:00:00 2001 From: Philip O'Toole Date: Wed, 17 Jun 2015 11:02:07 -0700 Subject: [PATCH 1/3] Enforce minimum retention duration of 1 hour Fixes issue #2991. --- meta/errors.go | 8 ++++++-- meta/store.go | 6 +++++- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/meta/errors.go b/meta/errors.go index b7698a5117..82c5b6895f 100644 --- a/meta/errors.go +++ b/meta/errors.go @@ -1,6 +1,9 @@ package meta -import "errors" +import ( + "errors" + "fmt" +) var ( // ErrStoreOpen is returned when opening an already open store. @@ -52,7 +55,8 @@ var ( // ErrRetentionPolicyDurationTooLow is returned when updating a retention // policy that has a duration lower than the allowed minimum. - ErrRetentionPolicyDurationTooLow = errors.New("retention policy duration too low") + ErrRetentionPolicyDurationTooLow = errors.New(fmt.Sprintf("retention policy duration must be at least %s", + RetentionPolicyMinDuration)) // ErrReplicationFactorMismatch is returned when the replication factor // does not match the number of nodes in the cluster. This is a temporary diff --git a/meta/store.go b/meta/store.go index 52a585ac41..ccadd3b914 100644 --- a/meta/store.go +++ b/meta/store.go @@ -34,10 +34,11 @@ const ( // that it is coming from a remote exec client connection. const ExecMagic = "EXEC" -// Retention policy auto-create settings. +// Retention policy settings. const ( AutoCreateRetentionPolicyName = "default" AutoCreateRetentionPolicyPeriod = 0 + RetentionPolicyMinDuration = time.Hour ) // Raft configuration. @@ -717,6 +718,9 @@ func (s *Store) RetentionPolicies(database string) (a []RetentionPolicyInfo, err // CreateRetentionPolicy creates a new retention policy for a database. func (s *Store) CreateRetentionPolicy(database string, rpi *RetentionPolicyInfo) (*RetentionPolicyInfo, error) { + if rpi.Duration < RetentionPolicyMinDuration && rpi.Duration != 0 { + return nil, ErrRetentionPolicyDurationTooLow + } if err := s.exec(internal.Command_CreateRetentionPolicyCommand, internal.E_CreateRetentionPolicyCommand_Command, &internal.CreateRetentionPolicyCommand{ Database: proto.String(database), From 8bff4c1c5184084726982a07ff1d1e4f60aab04d Mon Sep 17 00:00:00 2001 From: Philip O'Toole Date: Wed, 17 Jun 2015 11:02:38 -0700 Subject: [PATCH 2/3] Unit test minimum retention policy duration --- cmd/influxd/run/server_test.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/cmd/influxd/run/server_test.go b/cmd/influxd/run/server_test.go index 3ca8cda06a..20b8eeeb97 100644 --- a/cmd/influxd/run/server_test.go +++ b/cmd/influxd/run/server_test.go @@ -133,10 +133,9 @@ func TestServer_RetentionPolicyCommands(t *testing.T) { exp: `{"results":[{"series":[{"columns":["name","duration","replicaN","default"]}]}]}`, }, &Query{ - skip: true, name: "Ensure retention policy with unacceptable retention cannot be created - FIXME issue #2991", command: `CREATE RETENTION POLICY rp3 ON db0 DURATION 1s REPLICATION 1`, - exp: `{"results":[{"error":"retention policy duration needs to be at least 1h0m0s"}]}`, + exp: `{"results":[{"error":"retention policy duration must be at least 1h0m0s"}]}`, }, &Query{ name: "Check error when deleting retention policy on non-existent database", From 64925023cd8754f0b97ca40998de2908fad3f7a1 Mon Sep 17 00:00:00 2001 From: Philip O'Toole Date: Wed, 17 Jun 2015 11:04:51 -0700 Subject: [PATCH 3/3] Update CHANGELOG --- CHANGELOG.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 75bdd6b279..f7824be723 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -18,7 +18,8 @@ - [#2993](https://github.com/influxdb/influxdb/pull/2993): Don't log each UDP batch. - [#2994](https://github.com/influxdb/influxdb/pull/2994): Don't panic during wilcard expansion if no default database specified. - [#3002](https://github.com/influxdb/influxdb/pull/3002): Remove measurement from shard's index on DROP MEASUREMENT. -- [#3021](https://github.com/influxdb/influxdb/pull/3021): Correct set HTTP write trace logging. Thanks @vladlopes. +- [#3021](https://github.com/influxdb/influxdb/pull/3021): Correct set HTTP write trace logging. Thanks @vladlopes. +- [#3027](https://github.com/influxdb/influxdb/pull/3027): Enforce minimum retention policy duration of 1 hour. ## v0.9.0 [2015-06-11]