|
31 | 31 | _build_parents,
|
32 | 32 | _parse_deprecated_compressor,
|
33 | 33 | create_array,
|
| 34 | + is_concurrency_safe, |
34 | 35 | )
|
35 | 36 | from zarr.core.attributes import Attributes
|
36 | 37 | from zarr.core.buffer import default_buffer_prototype
|
@@ -535,17 +536,23 @@ async def open(
|
535 | 536 | if zarr_json_bytes is None:
|
536 | 537 | raise FileNotFoundError(store_path)
|
537 | 538 | elif zarr_format is None:
|
| 539 | + paths = [ |
| 540 | + (store_path / ZARR_JSON).get(), |
| 541 | + (store_path / ZGROUP_JSON).get(), |
| 542 | + (store_path / ZATTRS_JSON).get(), |
| 543 | + (store_path / consolidated_key).get(), |
| 544 | + ] |
538 | 545 | (
|
539 | 546 | zarr_json_bytes,
|
540 | 547 | zgroup_bytes,
|
541 | 548 | zattrs_bytes,
|
542 | 549 | maybe_consolidated_metadata_bytes,
|
543 |
| - ) = await asyncio.gather( |
544 |
| - (store_path / ZARR_JSON).get(), |
545 |
| - (store_path / ZGROUP_JSON).get(), |
546 |
| - (store_path / ZATTRS_JSON).get(), |
547 |
| - (store_path / str(consolidated_key)).get(), |
| 550 | + ) = ( |
| 551 | + await asyncio.gather(*paths) |
| 552 | + if is_concurrency_safe(store_path.store) |
| 553 | + else [await path for path in paths] |
548 | 554 | )
|
| 555 | + |
549 | 556 | if zarr_json_bytes is not None and zgroup_bytes is not None:
|
550 | 557 | # warn and favor v3
|
551 | 558 | msg = f"Both zarr.json (Zarr format 3) and .zgroup (Zarr format 2) metadata objects exist at {store_path}. Zarr format 3 will be used."
|
@@ -3476,11 +3483,23 @@ async def _read_metadata_v2(store: Store, path: str) -> ArrayV2Metadata | GroupM
|
3476 | 3483 | """
|
3477 | 3484 | # TODO: consider first fetching array metadata, and only fetching group metadata when we don't
|
3478 | 3485 | # find an array
|
3479 |
| - zarray_bytes, zgroup_bytes, zattrs_bytes = await asyncio.gather( |
3480 |
| - store.get(_join_paths([path, ZARRAY_JSON]), prototype=default_buffer_prototype()), |
3481 |
| - store.get(_join_paths([path, ZGROUP_JSON]), prototype=default_buffer_prototype()), |
3482 |
| - store.get(_join_paths([path, ZATTRS_JSON]), prototype=default_buffer_prototype()), |
3483 |
| - ) |
| 3486 | + print(f"Reading metadata from {path} in store {store}", file=sys.stderr) |
| 3487 | + if is_concurrency_safe(store): |
| 3488 | + zarray_bytes, zgroup_bytes, zattrs_bytes = await asyncio.gather( |
| 3489 | + store.get(_join_paths([path, ZARRAY_JSON]), prototype=default_buffer_prototype()), |
| 3490 | + store.get(_join_paths([path, ZGROUP_JSON]), prototype=default_buffer_prototype()), |
| 3491 | + store.get(_join_paths([path, ZATTRS_JSON]), prototype=default_buffer_prototype()), |
| 3492 | + ) |
| 3493 | + else: |
| 3494 | + zarray_bytes = await store.get( |
| 3495 | + _join_paths([path, ZARRAY_JSON]), prototype=default_buffer_prototype() |
| 3496 | + ) |
| 3497 | + zgroup_bytes = await store.get( |
| 3498 | + _join_paths([path, ZGROUP_JSON]), prototype=default_buffer_prototype() |
| 3499 | + ) |
| 3500 | + zattrs_bytes = await store.get( |
| 3501 | + _join_paths([path, ZATTRS_JSON]), prototype=default_buffer_prototype() |
| 3502 | + ) |
3484 | 3503 |
|
3485 | 3504 | if zattrs_bytes is None:
|
3486 | 3505 | zattrs = {}
|
|
0 commit comments