Skip to content

Commit

Permalink
fix influxdata#7068: use DefaultRetentionPolicyName from cfg
Browse files Browse the repository at this point in the history
Use DefaultRetentionPolicyName from the config instead of passing
through meta data.
  • Loading branch information
dgnorton committed Jul 26, 2016
1 parent a101f52 commit 8fbfdc5
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 27 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ With this release the systemd configuration files for InfluxDB will use the syst
- [#7043](https://github.com/influxdata/influxdb/pull/7043): Remove limiter from walkShards
- [#5501](https://github.com/influxdata/influxdb/issues/5501): Queries against files that have just been compacted need to point to new files
- [#6595](https://github.com/influxdata/influxdb/issues/6595): Fix full compactions conflicting with level compactions
- [#7068](https://github.com/influxdata/influxdb/issues/7068): Use DefaultRetentionPolicyName from config

## v0.13.0 [2016-05-12]

Expand Down
1 change: 1 addition & 0 deletions coordinator/meta_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ type MetaClient interface {
DropRetentionPolicy(database, name string) error
DropSubscription(database, rp, name string) error
DropUser(name string) error
RetentionAutoCreateName() string
RetentionPolicy(database, name string) (rpi *meta.RetentionPolicyInfo, err error)
SetAdminPrivilege(username string, admin bool) error
SetDefaultRetentionPolicy(database, name string) error
Expand Down
5 changes: 5 additions & 0 deletions coordinator/meta_client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ type MetaClient struct {
DropShardFn func(id uint64) error
DropUserFn func(name string) error
MetaNodesFn func() ([]meta.NodeInfo, error)
RetentionAutoCreateNameFn func() string
RetentionPolicyFn func(database, name string) (rpi *meta.RetentionPolicyInfo, err error)
SetAdminPrivilegeFn func(username string, admin bool) error
SetDefaultRetentionPolicyFn func(database, name string) error
Expand Down Expand Up @@ -115,6 +116,10 @@ func (c *MetaClient) MetaNodes() ([]meta.NodeInfo, error) {
return c.MetaNodesFn()
}

func (c *MetaClient) RetentionAutoCreateName() string {
return c.RetentionAutoCreateNameFn()
}

func (c *MetaClient) RetentionPolicy(database, name string) (rpi *meta.RetentionPolicyInfo, err error) {
return c.RetentionPolicyFn(database, name)
}
Expand Down
6 changes: 5 additions & 1 deletion coordinator/statement_executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,11 @@ func (e *StatementExecutor) executeCreateDatabaseStatement(stmt *influxql.Create
return err
}

rpi := meta.NewRetentionPolicyInfo(stmt.RetentionPolicyName)
rpname := stmt.RetentionPolicyName
if rpname == "" {
rpname = e.MetaClient.RetentionAutoCreateName()
}
rpi := meta.NewRetentionPolicyInfo(rpname)
rpi.Duration = stmt.RetentionPolicyDuration
rpi.ReplicaN = stmt.RetentionPolicyReplication
rpi.ShardGroupDuration = stmt.RetentionPolicyShardGroupDuration
Expand Down
25 changes: 16 additions & 9 deletions services/meta/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ type Client struct {

path string

retentionAutoCreate bool
retentionAutoCreate bool
defaultRetentionPolicyName string
}

type authUser struct {
Expand All @@ -68,14 +69,14 @@ func NewClient(config *Config) *Client {
cacheData: &Data{
ClusterID: uint64(rand.Int63()),
Index: 1,
DefaultRetentionPolicyName: config.DefaultRetentionPolicyName,
},
closing: make(chan struct{}),
changed: make(chan struct{}),
logger: log.New(ioutil.Discard, "[metaclient] ", log.LstdFlags),
authCache: make(map[string]authUser, 0),
path: config.Dir,
retentionAutoCreate: config.RetentionAutoCreate,
closing: make(chan struct{}),
changed: make(chan struct{}),
logger: log.New(ioutil.Discard, "[metaclient] ", log.LstdFlags),
authCache: make(map[string]authUser, 0),
path: config.Dir,
retentionAutoCreate: config.RetentionAutoCreate,
defaultRetentionPolicyName: config.DefaultRetentionPolicyName,
}
}

Expand Down Expand Up @@ -189,11 +190,12 @@ func (c *Client) CreateDatabase(name string) (*DatabaseInfo, error) {
// create default retention policy
if c.retentionAutoCreate {
if err := data.CreateRetentionPolicy(name, &RetentionPolicyInfo{
Name: c.defaultRetentionPolicyName,
ReplicaN: 1,
}); err != nil {
return nil, err
}
if err := data.SetDefaultRetentionPolicy(name, ""); err != nil {
if err := data.SetDefaultRetentionPolicy(name, c.defaultRetentionPolicyName); err != nil {
return nil, err
}
}
Expand Down Expand Up @@ -297,6 +299,11 @@ func (c *Client) CreateRetentionPolicy(database string, rpi *RetentionPolicyInfo
return rp, nil
}

// RetentionAutoCreateName returns the name used for auto generated retention policies.
func (c *Client) RetentionAutoCreateName() string {
return c.defaultRetentionPolicyName
}

// RetentionPolicy returns the requested retention policy info.
func (c *Client) RetentionPolicy(database, name string) (rpi *RetentionPolicyInfo, err error) {
c.mu.RLock()
Expand Down
22 changes: 5 additions & 17 deletions services/meta/data.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,6 @@ type Data struct {

MaxShardGroupID uint64
MaxShardID uint64

DefaultRetentionPolicyName string `json:"-"`
}

// NewShardOwner sets the owner of the provided shard to the data node
Expand Down Expand Up @@ -136,7 +134,9 @@ func (data *Data) RetentionPolicy(database, name string) (*RetentionPolicyInfo,
// Returns an error if name is blank or if a database does not exist.
func (data *Data) CreateRetentionPolicy(database string, rpi *RetentionPolicyInfo) error {
// Validate retention policy.
if rpi.ReplicaN < 1 {
if rpi.Name == "" {
return ErrRetentionPolicyNameRequired
} else if rpi.ReplicaN < 1 {
return ErrReplicationFactorTooLow
}

Expand All @@ -156,18 +156,9 @@ func (data *Data) CreateRetentionPolicy(database string, rpi *RetentionPolicyInf
return nil
}

// Determine the retention policy name if it is blank.
rpName := rpi.Name
if rpName == "" {
if data.DefaultRetentionPolicyName == "" {
return ErrRetentionPolicyNameRequired
}
rpName = data.DefaultRetentionPolicyName
}

// Append copy of new policy.
rp := RetentionPolicyInfo{
Name: rpName,
Name: rpi.Name,
Duration: rpi.Duration,
ReplicaN: rpi.ReplicaN,
ShardGroupDuration: rpi.ShardGroupDuration,
Expand Down Expand Up @@ -263,10 +254,7 @@ func (data *Data) UpdateRetentionPolicy(database, name string, rpu *RetentionPol
// SetDefaultRetentionPolicy sets the default retention policy for a database.
func (data *Data) SetDefaultRetentionPolicy(database, name string) error {
if name == "" {
if data.DefaultRetentionPolicyName == "" {
return ErrRetentionPolicyNameRequired
}
name = data.DefaultRetentionPolicyName
return ErrRetentionPolicyNameRequired
}

// Find database and verify policy exists.
Expand Down

0 comments on commit 8fbfdc5

Please sign in to comment.