-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: prevent retention service creating orphaned shard files (#24544)
Under certain circumstances, the retention service can fail to delete shards from the store in a timely manner. When the shard groups are pruned based on age, this leaves orphaned shard files on the disk. The retention service will then not attempt to remove the obsolete shard files because the meta store does not know about them. This can cause excessive disk space usage for some users. This corrects that by requiring shards files be deleted before they can be removed from the meta store. Backport via clean cherry-pick of #24530. fixes: #24543 (cherry picked from commit 7bd3f89)
- Loading branch information
Showing
10 changed files
with
583 additions
and
180 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
package helpers | ||
|
||
import ( | ||
"fmt" | ||
"time" | ||
|
||
"golang.org/x/exp/slices" | ||
|
||
"github.com/influxdata/influxdb" | ||
"github.com/influxdata/influxdb/services/meta" | ||
) | ||
|
||
// DataDeleteShardGroup deletes the shard group specified by database, policy, and id from targetData. | ||
// It does this by setting the shard group's DeletedAt time to now. We have to reimplement DeleteShardGroup | ||
// instead of using data's so that the DeletedAt time will be deterministic. We are also not testing | ||
// the functionality of DeleteShardGroup. We are testing if DeleteShardGroup gets called correctly. | ||
func DataDeleteShardGroup(targetData *meta.Data, now time.Time, database, policy string, id uint64) error { | ||
rpi, err := targetData.RetentionPolicy(database, policy) | ||
|
||
if err != nil { | ||
return err | ||
} else if rpi == nil { | ||
return influxdb.ErrRetentionPolicyNotFound(policy) | ||
} | ||
|
||
// Find shard group by ID and set its deletion timestamp. | ||
for i := range rpi.ShardGroups { | ||
if rpi.ShardGroups[i].ID == id { | ||
rpi.ShardGroups[i].DeletedAt = now | ||
return nil | ||
} | ||
} | ||
|
||
return meta.ErrShardGroupNotFound | ||
} | ||
|
||
// DataNukeShardGroup unconditionally removes the shard group identified by targetDB, targetRP, and targetID | ||
// from targetData. There's no meta.Data method to directly remove a shard group, only to mark it deleted and | ||
// then prune it. We can't use the functionality we're testing to generate the expected result. | ||
func DataNukeShardGroup(targetData *meta.Data, targetDB, targetRP string, targetID uint64) error { | ||
rpi, err := targetData.RetentionPolicy(targetDB, targetRP) | ||
if err != nil { | ||
return err | ||
} else if rpi == nil { | ||
return fmt.Errorf("no retention policy found for %q, %q, %d", targetDB, targetRP, targetID) | ||
} | ||
isTargetShardGroup := func(sgi meta.ShardGroupInfo) bool { | ||
return sgi.ID == targetID | ||
} | ||
if !slices.ContainsFunc(rpi.ShardGroups, isTargetShardGroup) { | ||
return fmt.Errorf("shard not found for %q, %q, %d", targetDB, targetRP, targetID) | ||
} | ||
rpi.ShardGroups = slices.DeleteFunc(rpi.ShardGroups, isTargetShardGroup) | ||
return nil | ||
} |
Oops, something went wrong.