Use default retention policy if not specified during writes

pull/2725/head
Jason Wilder 2015-06-01 17:16:44 -06:00
parent 497cd506f9
commit e400e8f2d6
3 changed files with 15 additions and 1 deletions

View File

@ -48,6 +48,7 @@ type PointsWriter struct {
MetaStore interface {
NodeID() uint64
Database(name string) (di *meta.DatabaseInfo, err error)
RetentionPolicy(database, policy string) (*meta.RetentionPolicyInfo, error)
CreateShardGroupIfNotExists(database, policy string, timestamp time.Time) (*meta.ShardGroupInfo, error)
}
@ -150,6 +151,14 @@ func (w *PointsWriter) MapShards(wp *WritePointsRequest) (*ShardMapping, error)
// WritePoints writes across multiple local and remote data nodes according the consistency level.
func (w *PointsWriter) WritePoints(p *WritePointsRequest) error {
if p.RetentionPolicy == "" {
db, err := w.MetaStore.Database(p.Database)
if err != nil {
return err
}
p.RetentionPolicy = db.DefaultRetentionPolicy
}
shardMappings, err := w.MapShards(p)
if err != nil {
return err

View File

@ -304,6 +304,7 @@ type MetaStore struct {
NodeIDFn func() uint64
RetentionPolicyFn func(database, name string) (*meta.RetentionPolicyInfo, error)
CreateShardGroupIfNotExistsFn func(database, policy string, timestamp time.Time) (*meta.ShardGroupInfo, error)
DatabaseFn func(database string) (*meta.DatabaseInfo, error)
}
func (m MetaStore) NodeID() uint64 { return m.NodeIDFn() }
@ -316,6 +317,10 @@ func (m MetaStore) CreateShardGroupIfNotExists(database, policy string, timestam
return m.CreateShardGroupIfNotExistsFn(database, policy, timestamp)
}
func (m MetaStore) Database(database string) (*meta.DatabaseInfo, error) {
return m.DatabaseFn(database)
}
func NewRetentionPolicy(name string, duration time.Duration, nodeCount int) *meta.RetentionPolicyInfo {
shards := []meta.ShardInfo{}
ownerIDs := []uint64{}

View File

@ -129,7 +129,7 @@ func (data *Data) RetentionPolicy(database, name string) (*RetentionPolicyInfo,
return &di.RetentionPolicies[i], nil
}
}
return nil, nil
return nil, ErrRetentionPolicyNotFound
}
// CreateRetentionPolicy creates a new retention policy on a database.