Create a command to truncated shard groups

pull/8971/head
Andrew Hare 2017-10-16 20:34:26 -06:00
parent 049a9a859d
commit e6aa5023eb
6 changed files with 48 additions and 0 deletions

View File

@ -38,6 +38,7 @@
- [#8897](https://github.com/influxdata/influxdb/pull/8897): Add message pack format for query responses.
- [#8886](https://github.com/influxdata/influxdb/pull/8886): Improved compaction scheduling
- [#8690](https://github.com/influxdata/influxdb/issues/8690): Implicitly decide on a lower limit for fill queries when none is present.
- [#7355](https://github.com/influxdata/influxdb/issues/7355): Create a command to truncated shard groups
### Bugfixes

View File

@ -27,6 +27,7 @@ type MetaClient interface {
SetAdminPrivilege(username string, admin bool) error
SetPrivilege(username, database string, p influxql.Privilege) error
ShardGroupsByTimeRange(database, policy string, min, max time.Time) (a []meta.ShardGroupInfo, err error)
TruncateShardGroups(t time.Time) error
UpdateRetentionPolicy(database, name string, rpu *meta.RetentionPolicyUpdate, makeDefault bool) error
UpdateUser(name, password string) error
UserPrivilege(username, database string) (*influxql.Privilege, error)

View File

@ -32,6 +32,7 @@ type MetaClient struct {
SetAdminPrivilegeFn func(username string, admin bool) error
SetPrivilegeFn func(username, database string, p influxql.Privilege) error
ShardGroupsByTimeRangeFn func(database, policy string, min, max time.Time) (a []meta.ShardGroupInfo, err error)
TruncateShardGroupsFn func(t time.Time) error
UpdateRetentionPolicyFn func(database, name string, rpu *meta.RetentionPolicyUpdate, makeDefault bool) error
UpdateUserFn func(name, password string) error
UserPrivilegeFn func(username, database string) (*influxql.Privilege, error)
@ -131,6 +132,10 @@ func (c *MetaClient) ShardGroupsByTimeRange(database, policy string, min, max ti
return c.ShardGroupsByTimeRangeFn(database, policy, min, max)
}
func (c *MetaClient) TruncateShardGroups(t time.Time) error {
return c.TruncateShardGroupsFn(t)
}
func (c *MetaClient) UpdateRetentionPolicy(database, name string, rpu *meta.RetentionPolicyUpdate, makeDefault bool) error {
return c.UpdateRetentionPolicyFn(database, name, rpu, makeDefault)
}

View File

@ -41,6 +41,7 @@ type MetaClientMock struct {
SetPrivilegeFn func(username, database string, p influxql.Privilege) error
ShardGroupsByTimeRangeFn func(database, policy string, min, max time.Time) (a []meta.ShardGroupInfo, err error)
ShardOwnerFn func(shardID uint64) (database, policy string, sgi *meta.ShardGroupInfo)
TruncateShardGroupsFn func(t time.Time) error
UpdateRetentionPolicyFn func(database, name string, rpu *meta.RetentionPolicyUpdate, makeDefault bool) error
UpdateUserFn func(name, password string) error
UserPrivilegeFn func(username, database string) (*influxql.Privilege, error)
@ -137,6 +138,10 @@ func (c *MetaClientMock) ShardOwner(shardID uint64) (database, policy string, sg
return c.ShardOwnerFn(shardID)
}
func (c *MetaClientMock) TruncateShardGroups(t time.Time) error {
return c.TruncateShardGroupsFn(t)
}
func (c *MetaClientMock) UpdateRetentionPolicy(database, name string, rpu *meta.RetentionPolicyUpdate, makeDefault bool) error {
return c.UpdateRetentionPolicyFn(database, name, rpu, makeDefault)
}

View File

@ -672,6 +672,16 @@ func (c *Client) DropShard(id uint64) error {
return c.commit(data)
}
// TruncateShardGroups truncates any shard group that could contain timestamps beyond t.
func (c *Client) TruncateShardGroups(t time.Time) error {
c.mu.Lock()
defer c.mu.Unlock()
data := c.cacheData.Clone()
data.TruncateShardGroups(t)
return c.commit(data)
}
// PruneShardGroups remove deleted shard groups from the data store.
func (c *Client) PruneShardGroups() error {
var changed bool

View File

@ -746,6 +746,32 @@ func (data *Data) UnmarshalBinary(buf []byte) error {
return nil
}
// TruncateShardGroups truncates any shard group that could contain timestamps beyond t.
func (data *Data) TruncateShardGroups(t time.Time) {
for i := range data.Databases {
dbi := &data.Databases[i]
for j := range dbi.RetentionPolicies {
rpi := &dbi.RetentionPolicies[j]
for k := range rpi.ShardGroups {
sgi := &rpi.ShardGroups[k]
if !t.Before(sgi.EndTime) || sgi.Deleted() || (sgi.Truncated() && sgi.TruncatedAt.Before(t)) {
continue
}
if !t.After(sgi.StartTime) {
// future shardgroup
sgi.TruncatedAt = sgi.StartTime
} else {
sgi.TruncatedAt = t
}
}
}
}
}
// hasAdminUser exhaustively checks for the presence of at least one admin
// user.
func (data *Data) hasAdminUser() bool {