Skip to content

Write and use consolidated metadata - #492

Open
Bisaloo wants to merge 16 commits into
scverse:develfrom
Bisaloo:consolidated-metadata
Open

Bisaloo wants to merge 16 commits into
scverse:develfrom
Bisaloo:consolidated-metadata

Conversation

@Bisaloo

@Bisaloo Bisaloo commented Jul 28, 2026 •

Copy link
Copy Markdown
Contributor

Related to: fix #461

Description

In line with what anndata python is doing, this PR:

  • always writes consolidated metadata when writing anndata to Zarr.
  • uses the metadata when reading (it's created on the fly if it doesn't exist on disk) to avoid multiple reading of multiple JSON files.

Eventually, in a follow up PR, this can also be used to add reading from S3.

Checklist

Before review

  • Update and regenerate man pages
  • Add/update tests
  • Add/update examples in vignettes
  • Pass CI checks

Before merge

  • Update NEWS
  • Bump devel version

@Bisaloo
Bisaloo marked this pull request as ready for review July 28, 2026 21:25
@Bisaloo
Bisaloo marked this pull request as draft July 29, 2026 09:01
@Bisaloo
Bisaloo marked this pull request as ready for review July 29, 2026 09:59
@Bisaloo

Bisaloo commented Jul 29, 2026

Copy link
Copy Markdown
Contributor Author

I'll stop here for a first review & merge if this seems good.

The 2nd stage, which will bring reading from S3 and further performance improvement, will require changing the signature of some helper function, so I prefer to do it in a dedicated PR.

For example, read_zarr_categorical() would now have ordered in its signature so it can be passed directly from the consolidated metadata, and all read_zarr_attributes() calls can be avoided (or even eliminated) from individual low-level helpers.

Comment thread R/ZarrAnnData.R Resolved
@github-actions

github-actions Bot commented Aug 3, 2026 •

Copy link
Copy Markdown

🐰 Bencher Report

ProjectanndataR
Branchconsolidated-metadata
Testbedubuntu-latest

⚠️ WARNING: Truncated view!

The full continuous benchmarking report exceeds the maximum length allowed on this platform.

🚨 8 Alerts

🐰 View full continuous benchmarking report in Bencher

@lazappi lazappi left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this looks good. Does there need to be any checks for the Zarr version?

Comment thread DESCRIPTION Outdated
Package: anndataR
Title: AnnData interoperability in R
Version: 1.3.1
Version: 1.3.2

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure if we want to bump this yet (I've lost track of how we were managing versions, @rcannood might have a plan)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we are at 1.3.3 now so devel should be merged here first

@Bisaloo

Bisaloo commented Aug 9, 2026

Copy link
Copy Markdown
Contributor Author

Does there need to be any checks for the Zarr version?

From Rarr's side, no. Consolidated metadata is generated, and would be beneficial, for both v2 and v3. I don't know if the anndata spec is strict about this but my view is that even if anndata python doesn't generate it / use it for v2, they are not likely to be hindered by it either.

@Bisaloo
Bisaloo requested a review from lazappi October 22, 2026 16:30

@lazappi lazappi left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we just need to merge devel, otherwise looks good

Comment thread DESCRIPTION Outdated
Package: anndataR
Title: AnnData interoperability in R
Version: 1.3.1
Version: 1.3.2

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we are at 1.3.3 now so devel should be merged here first

@rcannood rcannood left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Bisaloo Thanks for implementing this functionality; the consolidated metadata is very useful for streaming stores.

Before we merge the PR, I'd just like to verify, after the consolidated metadata is written (during initialisation), does the metadata (both the store and the private$.consolidated_metadata) not go stale every time we write one of the values?


The zarr-python docs say consolidated metadata is for "read-heavy use cases on slowly changing hierarchies". Python anndata took the strict route in scverse/anndata#2015: write_elem raises "Cannot overwrite/edit a store with consolidated metadata" if the target group is consolidated, and the zarr v3 tutorial tells users to open with use_consolidated=False, edit, then call zarr.consolidate_metadata again. Issue scverse/anndata#2016 in anndata is still open on how to let users opt out.


For this PR, if this is indeed an issue, I think we can do one of the following:

  1. Reconsolidate after every write
  2. Invalidate on write, reconsolidate when the info is needed
  3. Refuse writes on consolidated stores

I lean towards 1 or 2, depending on how much overhead 1 introduces.


@rcannood rcannood added the new feature New feature or request label Oct 28, 2026
@rcannood rcannood mentioned this pull request Nov 20, 2026
4 of 6 tasks

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

new feature New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Consolidated Zarr metadata at the root of the anndata zarr store

3 participants