mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2026-12-05 18:47:20 +01:00
chunkstore: snapshot retention and space accounting
claude05's rulings (2026-11-15 22:53Z). Retention, policy on the VOLUME entry: keep the newest KeepNewest unpinned snapshots, every pinned snapshot not yet past its ExpiresAtNs, every snapshot younger than KeepYounger (a future creation time from clock skew counts as young), the newest snapshot of each of the last KeepHourly / KeepDaily / KeepWeekly periods, and every snapshot a fork still needs (named by a fork whose HEAD is absent or aborted). Everything else is deleted through DeleteSnapshot (attempt-scoped tombstones; HEAD untouched; names freed); GC reclaims the chunks. Equal creation times rank by name. Semantic and labeled snapshots are not exempt; a pinned snapshot past its expiry is unpinned. Defaults: 10 newest, 1h. A dry run plans and writes nothing. The policy is stored as extended attributes on the VOLUME entry, conditional on a revision. Accounting, from manifests and filer listings (no data reads; a chunk is ChunkBlocks x BlockSize, the last clipped): live bytes from HEAD; per-snapshot exclusive bytes (referenced by no other holder); stored bytes from the volume's chunk-key bindings, exact for referenced keys and a full chunk (an upper bound, flagged) for the rest. The unreferenced-not-yet-collected bytes come from GC's preview once #140 merges; bytes uploaded since creation need a counter (follow-up). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
81e0ea7392
commit
4e5ff2cc95
3 files changed
+1
-20
No files matched your search
@@ -834,7 +834,7 @@ func (c *Catalog) CreateSnapshot(ctx context.Context, vol string, req SnapshotRe
|
||||
}
|
||||
doc := snapDoc{Format: snapFormat, VolumeID: vol, Name: req.Name, RequestID: req.RequestID, CreatedNs: c.now().UnixNano(),
|
||||
CreatedBy: req.CreatedBy, Consistency: consistency, Head: headEnt.Content, Geometry: v.Geometry, Parent: v.Parent,
|
||||
Labels: req.Labels, ExpiresAtNs: req.ExpiresAtNs, Class: ""} // RED: class not stored
|
||||
Labels: req.Labels, ExpiresAtNs: req.ExpiresAtNs, Class: req.Class}
|
||||
body, err := json.Marshal(doc)
|
||||
if err != nil {
|
||||
return SnapshotInfo{}, err
|
||||
|
||||
@@ -56,9 +56,6 @@ const (
|
||||
)
|
||||
|
||||
func validSnapshotClass(class string) error {
|
||||
if red := true; red { // RED: no validation
|
||||
return nil
|
||||
}
|
||||
switch class {
|
||||
case "", SnapshotClassSemantic, SnapshotClassPinned:
|
||||
return nil
|
||||
@@ -136,9 +133,6 @@ func (c *Catalog) volumeEntry(ctx context.Context, vol string) (*filerpb.Entry,
|
||||
// is conditional on the policy revision read, so of two concurrent setters
|
||||
// one wins and the other gets a retryable remote error.
|
||||
func (c *Catalog) SetRetentionPolicy(ctx context.Context, vol string, p RetentionPolicy) error {
|
||||
if red := true; red { // RED: stores nothing
|
||||
return nil
|
||||
}
|
||||
if err := p.validate(); err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -191,13 +185,6 @@ const (
|
||||
// are ranked newest first; equal creation times rank by name, so the plan
|
||||
// is deterministic.
|
||||
func planRetention(p RetentionPolicy, snaps []SnapshotInfo, needed map[string]bool, now time.Time) []RetentionDecision {
|
||||
if red := true; red { // RED: keeps everything
|
||||
out := make([]RetentionDecision, len(snaps))
|
||||
for i, s := range snaps {
|
||||
out[i] = RetentionDecision{Name: s.Name, Keep: true, Reasons: []string{"red"}}
|
||||
}
|
||||
return out
|
||||
}
|
||||
ordered := append([]SnapshotInfo(nil), snaps...)
|
||||
sort.SliceStable(ordered, func(i, j int) bool {
|
||||
if ordered[i].CreatedNs != ordered[j].CreatedNs {
|
||||
@@ -336,9 +323,6 @@ func (c *Catalog) allSnapshots(ctx context.Context, vol string) ([]SnapshotInfo,
|
||||
// real published HEAD yet (absent or aborted). A published fork HEAD pins
|
||||
// its chunks for GC itself, so it no longer needs the snapshot.
|
||||
func (c *Catalog) forkParentsNeeded(ctx context.Context, vol string) (map[string]bool, error) {
|
||||
if red := true; red { // RED: no fork needs a parent
|
||||
return map[string]bool{}, nil
|
||||
}
|
||||
vols, err := c.ListVolumes(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
||||
@@ -73,9 +73,6 @@ func chunkSize(g Geometry, idx uint64) uint64 {
|
||||
|
||||
// Usage computes vol's space accounting.
|
||||
func (c *Catalog) Usage(ctx context.Context, vol string) (VolumeUsage, error) {
|
||||
if red := true; red { // RED: no accounting
|
||||
return VolumeUsage{VolumeID: vol, Snapshots: []SnapshotUsage{}}, nil
|
||||
}
|
||||
v, ok, err := c.ReadVolume(ctx, vol)
|
||||
if err != nil {
|
||||
return VolumeUsage{}, err
|
||||
|
||||
Reference in new issue
Block a user