thanos-io/thanos · warning
requested to mark for no compaction, but file already…
Error message
requested to mark for no compaction, but file already exists; this should not happen; investigate
What it means
MarkForNoCompact found that the no-compact-mark.json file already exists in the bucket when it was asked to create it. This is not a wrapped error but a deliberate warning log; MarkForNoCompact returns nil (no error) after logging. It signals an unexpected duplicate mark — someone/something already marked the block, so the operation is idempotently skipped.
Solutions
- Confirm only one compactor instance is running (leader election enabled, no duplicates).
- Treat as benign if a duplicate mark is expected — the function returns nil and compaction is still skipped.
- Inspect the existing no-compact-mark.json contents to see who marked it and with which reason/details.
- If the mark is wrong (block should be compacted), delete the mark file from the bucket and rerun.
Example fix
// before
if noCompactMarkExists {
level.Warn(logger).Log("msg", "requested to mark for no compaction, but file already exists; this should not happen; investigate", "err", errors.Errorf("file %s already exists in bucket", m))
return nil
}
// after
if noCompactMarkExists {
level.Warn(logger).Log("msg", "no-compact mark already exists; skipping", "file", m)
return nil // idempotent: block already marked
} Defensive patterns
Strategy: try-catch
Validate before calling
markPath := path.Join(id.String(), "no-compact-mark.json")
exists, err := bkt.Exists(ctx, markPath)
if err == nil && exists {
// decide early: skip or fetch existing mark to compare reason
rc, _ := bkt.Get(ctx, markPath)
b, _ := io.ReadAll(rc)
log.Printf("block %s already no-compact marked: %s", id, b)
} Try / catch
if err := block.MarkForNoCompact(...); err != nil {
return err
}
// on the warning log (returns nil), treat as idempotent success:
// check logs for "file already exists in bucket" and proceed
Prevention
- Ensure single compactor leadership (enable leader election; don't run duplicates).
- Make mark operations idempotent — the function already returns nil on existing marks.
- Before marking, read the existing mark to compare reasons instead of re-marking.
- Use partitioned/sharded compaction so two instances never process the same block.
When it happens
Trigger: bkt.Exists returns true for <id>/no-compact-mark.json: MarkForNoCompact (or a similar path) was invoked twice for the same block, e.g., duplicate compaction runs, retried operations, or two compactors working concurrently without leader election.
Common situations: Two compactor instances running concurrently (misconfigured HA); operation retried after a partial failure; block already marked by an earlier run with a different reason; manual mark created by an operator.
Understand the failure class
Background: "already exists" / EEXIST / FileAlreadyExistsException: what the 'file already exists' error means and how to fix it — this error's family across 37 libraries.
Related errors
- compaction
- sync before first pass of downsampling
- sync before second pass of downsampling
- sync before retention
- retention failed
AI-assisted analysis of thanos-io/thanos@35b8b99117 (2026-09-07).
Data as JSON: /api/errors/45da5834beb378d9.
Report an issue: GitHub.
Appendix: source
Thrown at pkg/block/block.go:389
return nil, errors.Wrapf(err, "stat %v", filepath.Join(blockDir, MetaFilename))
}
res = append(res, metadata.File{RelPath: metaFile.Name()})
sort.Slice(res, func(i, j int) bool {
return strings.Compare(res[i].RelPath, res[j].RelPath) < 0
})
return res, err
}
// MarkForNoCompact creates a file which marks block to be not compacted.
func MarkForNoCompact(ctx context.Context, logger log.Logger, bkt objstore.Bucket, id ulid.ULID, reason metadata.NoCompactReason, details string, markedForNoCompact prometheus.Counter) error {
m := path.Join(id.String(), metadata.NoCompactMarkFilename)
noCompactMarkExists, err := bkt.Exists(ctx, m)
if err != nil {
return errors.Wrapf(err, "check exists %s in bucket", m)
}
if noCompactMarkExists {
level.Warn(logger).Log("msg", "requested to mark for no compaction, but file already exists; this should not happen; investigate", "err", errors.Errorf("file %s already exists in bucket", m))
return nil
}
noCompactMark, err := json.Marshal(metadata.NoCompactMark{
ID: id,
Version: metadata.NoCompactMarkVersion1,
NoCompactTime: time.Now().Unix(),
Reason: reason,
Details: details,
})
if err != nil {
return errors.Wrap(err, "json encode no compact mark")
}
if err := bkt.Upload(ctx, m, bytes.NewBuffer(noCompactMark)); err != nil {
return errors.Wrapf(err, "upload file %s to bucket", m)
}View on GitHub (pinned to 35b8b99117)