thanos-io/thanos · error

write new meta

Error message

write new meta

What it means

InjectThanos wraps the failure of newMeta.WriteToDir, which serializes the merged meta (with the Thanos section) back to meta.json on disk. It means the updated metadata could not be persisted, leaving the block without the Thanos metadata despite the in-memory value being correct.

Solutions

  1. Check filesystem permissions on bdir (needs write access, typically 0750/0755).
  2. Verify free disk space and that the volume is not mounted read-only.
  3. Retry the operation after resolving transient I/O errors; ensure no process holds meta.json locked.
  4. If the block cannot be updated, re-create the block with the correct Thanos meta.

Example fix

// before
$ chmod 555 /data/store/01BK.../ && ./thanos inject-meta
// after
$ chmod 750 /data/store/01BK.../ && ./thanos inject-meta
Defensive patterns

Strategy: try-catch

Validate before calling

if err := unix.Access(bdir, unix.W_OK); err != nil {
    return fmt.Errorf("block dir %s not writable: %w", bdir, err)
}

Try / catch

meta, err := InjectThanos(logger, bdir, thanosMeta, nil)
if err != nil {
    if strings.Contains(err.Error(), "write new meta") {
        // check disk space / permissions, then retry once
        return fmt.Errorf("persisting thanos meta failed: %w", err)
    }
    return err
}

Prevention

When it happens

Trigger: WriteToDir failing due to unwritable directory, permission denied, disk full, bdir being read-only, or filesystem I/O errors during the write/sync/rename.

Common situations: Running as a user without write permission on the block dir; disk full on the storage volume; block dir mounted read-only; antivirus/backup tooling locking meta.json during the write.

Understand the failure class

Background: "failed to write file", "Could not save figure", "Error saving remote file" — file write failed: causes and fixes across languages and libraries — this error's family across 38 libraries.

Related errors


AI-assisted analysis of thanos-io/thanos@35b8b99117 (2026-09-07). Data as JSON: /api/errors/ee5b3c9dd56a4ee6. Report an issue: GitHub.

Appendix: source

Thrown at pkg/block/metadata/meta.go:191

	Resolution int64 `json:"resolution"`
}

// InjectThanos sets Thanos meta to the block meta JSON and saves it to the disk.
// NOTE: It should be used after writing any block by any Thanos component, otherwise we will miss crucial metadata.
func InjectThanos(logger log.Logger, bdir string, meta Thanos, downsampledMeta *tsdb.BlockMeta) (*Meta, error) {
	newMeta, err := ReadFromDir(bdir)
	if err != nil {
		return nil, errors.Wrap(err, "read new meta")
	}
	newMeta.Thanos = meta

	// While downsampling we need to copy original compaction.
	if downsampledMeta != nil {
		newMeta.Compaction = downsampledMeta.Compaction
	}

	if err := newMeta.WriteToDir(logger, bdir); err != nil {
		return nil, errors.Wrap(err, "write new meta")
	}

	return newMeta, nil
}

// GroupKey returns a unique identifier for the compaction group the block belongs to.
// It considers the downsampling resolution and the block's labels.
func (m *Thanos) GroupKey() string {
	return fmt.Sprintf("%d@%v", m.Downsample.Resolution, labels.FromMap(m.Labels).Hash())
}

// ResolutionString returns a the block's resolution as a string.
func (m *Thanos) ResolutionString() string {
	return fmt.Sprintf("%d", m.Downsample.Resolution)
}

// WriteToDir writes the encoded meta into <dir>/meta.json.
func (m Meta) WriteToDir(logger log.Logger, dir string) error {

View on GitHub (pinned to 35b8b99117)