mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2026-12-04 10:07:28 +01:00
chunkstore: attempt-bound retention, fork holds, rolling windows
- Retain deletes the exact attempt it planned: the attempt's entry is marked deleting conditionally and the name record is removed only while it names that attempt; a replacement is reported as replaced. - Fork records a hold (forkholds/<name>/<attempt>/<target>) before it reads the parent. Retain marks first, then reads the holds: a live hold reverts the mark (fork_held); a fork holding after that read finds the attempt deleting and refuses before installing anything. A hold counts while its target has no HEAD and its VOLUME records the fork, or while it is younger than the operation deadline. - A pass stopped after a mark finishes (or reverts) it on the next run. - Log-spaced keeps use rolling windows anchored at now. - Exclusive bytes resolve "@owner/key" refs and count every volume's HEAD and live snapshots as holders; documented as eligible for GC subject to its grace period and intents. - Retain reports confirmed deletions, the failing snapshot (uncertain or not) and what it never reached; the CLI prints them with the error and exits nonzero. - chunkControl.Snapshot validates the class before any cut; invalid_class and invalid_policy map to 400. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
23d125daa7
commit
56300cc6c1
5 files changed
+3
-26
No files matched your search
@@ -106,9 +106,6 @@ type retainOutput struct {
|
||||
}
|
||||
|
||||
func retainPartial(res chunkstore.RetentionResult, err error, stdout, stderr io.Writer) int {
|
||||
if red := true; red { // RED: the partial result is discarded
|
||||
return chunkResult("retain", nil, err, stdout, stderr)
|
||||
}
|
||||
body := chunkErrBody{Code: chunkstore.CodeOf(err), Message: err.Error(), Retryable: true}
|
||||
var ce *chunkstore.CatalogError
|
||||
if errors.As(err, &ce) {
|
||||
|
||||
@@ -1298,9 +1298,6 @@ func (c *Catalog) holdForkParent(ctx context.Context, srcRoot string, req ForkRe
|
||||
if err != nil || !ok {
|
||||
return "", err
|
||||
}
|
||||
if red := true; red { // RED: no hold recorded
|
||||
return ref.rec.Attempt, nil
|
||||
}
|
||||
now := c.now().Unix()
|
||||
e := &filerpb.Entry{Name: req.Target, Attributes: &filerpb.FuseAttributes{Mtime: now, Crtime: now, FileMode: 0o644}}
|
||||
if err := c.f.CreateEntry(ctx, forkHoldDir(srcRoot, req.Snapshot, ref.rec.Attempt), e, true); err != nil && !errors.Is(err, ErrExists) {
|
||||
|
||||
@@ -254,13 +254,6 @@ func planRetention(p RetentionPolicy, snaps []SnapshotInfo, needed map[string]bo
|
||||
continue
|
||||
}
|
||||
k := int64(age / lk.period) // the rolling window holding this age
|
||||
// RED: calendar periods, as before the review
|
||||
if red := true; red {
|
||||
if age >= time.Duration(lk.count)*lk.period {
|
||||
continue
|
||||
}
|
||||
k = -1 - s.CreatedNs/int64(lk.period)
|
||||
}
|
||||
if k >= int64(lk.count) {
|
||||
continue
|
||||
}
|
||||
@@ -403,13 +396,6 @@ const (
|
||||
// that attempt. uncertain reports, with an error, that the failing call
|
||||
// was a mutation whose outcome is unknown.
|
||||
func (c *Catalog) deleteRetainedAttempt(ctx context.Context, vol, name, attempt string) (retainOutcome, bool, error) {
|
||||
if red := true; red { // RED: delete by name, as before the review
|
||||
c.hook(hookUnheld, name)
|
||||
if _, err := c.DeleteSnapshot(ctx, vol, name); err != nil && CodeOf(err) != CodeSnapshotNotFound {
|
||||
return 0, false, err
|
||||
}
|
||||
return retainDeleted, false, nil
|
||||
}
|
||||
root, err := c.volRoot(vol)
|
||||
if err != nil {
|
||||
return 0, false, err
|
||||
|
||||
@@ -211,9 +211,6 @@ func (c *Catalog) Usage(ctx context.Context, vol string) (VolumeUsage, error) {
|
||||
// owner-qualified "@owner/key" (a fork's reference) is owner's key,
|
||||
// anything else is vol's.
|
||||
func chunkIdentity(vol, key string) string {
|
||||
if red := true; red { // RED: owner-qualified refs not resolved
|
||||
return vol + "\x00" + key
|
||||
}
|
||||
if strings.HasPrefix(key, "@") {
|
||||
if owner, rest, ok := strings.Cut(key[1:], "/"); ok {
|
||||
return owner + "\x00" + rest
|
||||
|
||||
@@ -214,7 +214,7 @@ func chunkErrorCode(err error) (int, string, bool) {
|
||||
|
||||
func catalogStatus(code string) int {
|
||||
switch code {
|
||||
case chunkstore.CodeInvalidName, chunkstore.CodeInvalidLabel: // RED: class and policy errors fall to 409
|
||||
case chunkstore.CodeInvalidName, chunkstore.CodeInvalidLabel, chunkstore.CodeInvalidClass, chunkstore.CodeInvalidPolicy:
|
||||
return http.StatusBadRequest
|
||||
case chunkstore.CodeSnapshotNotFound:
|
||||
return http.StatusNotFound
|
||||
@@ -465,8 +465,8 @@ func (c *chunkControl) Cut(ctx context.Context, volumeID string, minLSN uint64)
|
||||
func (c *chunkControl) Snapshot(ctx context.Context, volumeID string, req ChunkSnapshotRequest) (chunkstore.SnapshotInfo, error) {
|
||||
// Admit the request before anything can cut: an invalid class must
|
||||
// not advance HEAD (review of #142).
|
||||
if red := true; !red { // RED: the class is checked only after the cut
|
||||
return chunkstore.SnapshotInfo{}, chunkstore.ValidateSnapshotClass(req.Class)
|
||||
if err := chunkstore.ValidateSnapshotClass(req.Class); err != nil {
|
||||
return chunkstore.SnapshotInfo{}, err
|
||||
}
|
||||
sreq := chunkstore.SnapshotRequest{Name: req.Name, RequestID: req.RequestID, Labels: req.Labels,
|
||||
Consistency: req.Consistency, ExpiresAtNs: req.ExpiresAtNs, CreatedBy: "blockvolume", Class: req.Class}
|
||||
|
||||
Reference in new issue
Block a user