|
30 | 30 | _build_parents,
|
31 | 31 | _parse_deprecated_compressor,
|
32 | 32 | create_array,
|
| 33 | + is_concurrency_safe, |
33 | 34 | )
|
34 | 35 | from zarr.core.attributes import Attributes
|
35 | 36 | from zarr.core.buffer import default_buffer_prototype
|
@@ -533,17 +534,23 @@ async def open(
|
533 | 534 | if zarr_json_bytes is None:
|
534 | 535 | raise FileNotFoundError(store_path)
|
535 | 536 | elif zarr_format is None:
|
| 537 | + paths = [ |
| 538 | + (store_path / ZARR_JSON).get(), |
| 539 | + (store_path / ZGROUP_JSON).get(), |
| 540 | + (store_path / ZATTRS_JSON).get(), |
| 541 | + (store_path / consolidated_key).get(), |
| 542 | + ] |
536 | 543 | (
|
537 | 544 | zarr_json_bytes,
|
538 | 545 | zgroup_bytes,
|
539 | 546 | zattrs_bytes,
|
540 | 547 | maybe_consolidated_metadata_bytes,
|
541 |
| - ) = await asyncio.gather( |
542 |
| - (store_path / ZARR_JSON).get(), |
543 |
| - (store_path / ZGROUP_JSON).get(), |
544 |
| - (store_path / ZATTRS_JSON).get(), |
545 |
| - (store_path / str(consolidated_key)).get(), |
| 548 | + ) = ( |
| 549 | + await asyncio.gather(*paths) |
| 550 | + if is_concurrency_safe(store_path.store) |
| 551 | + else [await path for path in paths] |
546 | 552 | )
|
| 553 | + |
547 | 554 | if zarr_json_bytes is not None and zgroup_bytes is not None:
|
548 | 555 | # warn and favor v3
|
549 | 556 | 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."
|
@@ -3453,11 +3460,23 @@ async def _read_metadata_v2(store: Store, path: str) -> ArrayV2Metadata | GroupM
|
3453 | 3460 | """
|
3454 | 3461 | # TODO: consider first fetching array metadata, and only fetching group metadata when we don't
|
3455 | 3462 | # find an array
|
3456 |
| - zarray_bytes, zgroup_bytes, zattrs_bytes = await asyncio.gather( |
3457 |
| - store.get(_join_paths([path, ZARRAY_JSON]), prototype=default_buffer_prototype()), |
3458 |
| - store.get(_join_paths([path, ZGROUP_JSON]), prototype=default_buffer_prototype()), |
3459 |
| - store.get(_join_paths([path, ZATTRS_JSON]), prototype=default_buffer_prototype()), |
3460 |
| - ) |
| 3463 | + print(f"Reading metadata from {path} in store {store}", file=sys.stderr) |
| 3464 | + if is_concurrency_safe(store): |
| 3465 | + zarray_bytes, zgroup_bytes, zattrs_bytes = await asyncio.gather( |
| 3466 | + store.get(_join_paths([path, ZARRAY_JSON]), prototype=default_buffer_prototype()), |
| 3467 | + store.get(_join_paths([path, ZGROUP_JSON]), prototype=default_buffer_prototype()), |
| 3468 | + store.get(_join_paths([path, ZATTRS_JSON]), prototype=default_buffer_prototype()), |
| 3469 | + ) |
| 3470 | + else: |
| 3471 | + zarray_bytes = await store.get( |
| 3472 | + _join_paths([path, ZARRAY_JSON]), prototype=default_buffer_prototype() |
| 3473 | + ) |
| 3474 | + zgroup_bytes = await store.get( |
| 3475 | + _join_paths([path, ZGROUP_JSON]), prototype=default_buffer_prototype() |
| 3476 | + ) |
| 3477 | + zattrs_bytes = await store.get( |
| 3478 | + _join_paths([path, ZATTRS_JSON]), prototype=default_buffer_prototype() |
| 3479 | + ) |
3461 | 3480 |
|
3462 | 3481 | if zattrs_bytes is None:
|
3463 | 3482 | zattrs = {}
|
|
0 commit comments