Create a command to truncated shard groups
parent
049a9a859d
commit
e6aa5023eb
|
@ -38,6 +38,7 @@
|
||||||
- [#8897](https://github.com/influxdata/influxdb/pull/8897): Add message pack format for query responses.
|
- [#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
|
- [#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.
|
- [#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
|
### Bugfixes
|
||||||
|
|
||||||
|
|
|
@ -27,6 +27,7 @@ type MetaClient interface {
|
||||||
SetAdminPrivilege(username string, admin bool) error
|
SetAdminPrivilege(username string, admin bool) error
|
||||||
SetPrivilege(username, database string, p influxql.Privilege) error
|
SetPrivilege(username, database string, p influxql.Privilege) error
|
||||||
ShardGroupsByTimeRange(database, policy string, min, max time.Time) (a []meta.ShardGroupInfo, err 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
|
UpdateRetentionPolicy(database, name string, rpu *meta.RetentionPolicyUpdate, makeDefault bool) error
|
||||||
UpdateUser(name, password string) error
|
UpdateUser(name, password string) error
|
||||||
UserPrivilege(username, database string) (*influxql.Privilege, error)
|
UserPrivilege(username, database string) (*influxql.Privilege, error)
|
||||||
|
|
|
@ -32,6 +32,7 @@ type MetaClient struct {
|
||||||
SetAdminPrivilegeFn func(username string, admin bool) error
|
SetAdminPrivilegeFn func(username string, admin bool) error
|
||||||
SetPrivilegeFn func(username, database string, p influxql.Privilege) error
|
SetPrivilegeFn func(username, database string, p influxql.Privilege) error
|
||||||
ShardGroupsByTimeRangeFn func(database, policy string, min, max time.Time) (a []meta.ShardGroupInfo, err 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
|
UpdateRetentionPolicyFn func(database, name string, rpu *meta.RetentionPolicyUpdate, makeDefault bool) error
|
||||||
UpdateUserFn func(name, password string) error
|
UpdateUserFn func(name, password string) error
|
||||||
UserPrivilegeFn func(username, database string) (*influxql.Privilege, 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)
|
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 {
|
func (c *MetaClient) UpdateRetentionPolicy(database, name string, rpu *meta.RetentionPolicyUpdate, makeDefault bool) error {
|
||||||
return c.UpdateRetentionPolicyFn(database, name, rpu, makeDefault)
|
return c.UpdateRetentionPolicyFn(database, name, rpu, makeDefault)
|
||||||
}
|
}
|
||||||
|
|
|
@ -41,6 +41,7 @@ type MetaClientMock struct {
|
||||||
SetPrivilegeFn func(username, database string, p influxql.Privilege) error
|
SetPrivilegeFn func(username, database string, p influxql.Privilege) error
|
||||||
ShardGroupsByTimeRangeFn func(database, policy string, min, max time.Time) (a []meta.ShardGroupInfo, err 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)
|
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
|
UpdateRetentionPolicyFn func(database, name string, rpu *meta.RetentionPolicyUpdate, makeDefault bool) error
|
||||||
UpdateUserFn func(name, password string) error
|
UpdateUserFn func(name, password string) error
|
||||||
UserPrivilegeFn func(username, database string) (*influxql.Privilege, 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)
|
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 {
|
func (c *MetaClientMock) UpdateRetentionPolicy(database, name string, rpu *meta.RetentionPolicyUpdate, makeDefault bool) error {
|
||||||
return c.UpdateRetentionPolicyFn(database, name, rpu, makeDefault)
|
return c.UpdateRetentionPolicyFn(database, name, rpu, makeDefault)
|
||||||
}
|
}
|
||||||
|
|
|
@ -672,6 +672,16 @@ func (c *Client) DropShard(id uint64) error {
|
||||||
return c.commit(data)
|
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.
|
// PruneShardGroups remove deleted shard groups from the data store.
|
||||||
func (c *Client) PruneShardGroups() error {
|
func (c *Client) PruneShardGroups() error {
|
||||||
var changed bool
|
var changed bool
|
||||||
|
|
|
@ -746,6 +746,32 @@ func (data *Data) UnmarshalBinary(buf []byte) error {
|
||||||
return nil
|
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
|
// hasAdminUser exhaustively checks for the presence of at least one admin
|
||||||
// user.
|
// user.
|
||||||
func (data *Data) hasAdminUser() bool {
|
func (data *Data) hasAdminUser() bool {
|
||||||
|
|
Loading…
Reference in New Issue