diff --git a/mdio/CMakeLists.txt b/mdio/CMakeLists.txt index 08ea17f..bfc058a 100644 --- a/mdio/CMakeLists.txt +++ b/mdio/CMakeLists.txt @@ -49,6 +49,9 @@ target_include_directories(mdio INTERFACE ) # Link dependencies +# NOTE: Abseil libraries (e.g. absl::log used by dataset.h) are provided +# transitively through EXT_TENSORSTORE::tensorstore, matching the existing +# convention for absl/strings usage in dataset_factory.h. target_link_libraries(mdio INTERFACE EXT_TENSORSTORE::tensorstore nlohmann_json_schema_validator::nlohmann_json_schema_validator @@ -291,7 +294,7 @@ mdio_cc_test( SRCS dataset_test.cc COPTS - ${mdio_DEFAULT_COPTS} + ${mdio_DEFAULT_COPTS} LINKOPTS ${mdio_DEFAULT_LINKOPTS} DEPS @@ -307,6 +310,10 @@ mdio_cc_test( tensorstore::index_space_index_transform tensorstore::util_status_testutil nlohmann_json_schema_validator + absl::log + absl::log_initialize + absl::log_sink + absl::log_internal_log_sink_set ) mdio_cc_test( diff --git a/mdio/dataset.h b/mdio/dataset.h index f9b5710..3fa01a5 100644 --- a/mdio/dataset.h +++ b/mdio/dataset.h @@ -17,6 +17,7 @@ #define MDIO_API_VERSION "1.0.0" #include +#include #include #include #include @@ -26,12 +27,15 @@ #include #include #include +#include #include #include #include #include #include +#include "absl/log/log.h" +#include "absl/strings/str_join.h" #include "mdio/dataset_factory.h" #include "mdio/header_variable.h" #include "mdio/variable.h" @@ -136,10 +140,13 @@ from_zmetadata(const std::string& dataset_path, [promise = std::move(promise), dataset_path, kvs = ready_kvs.value()]( tensorstore::ReadyFuture version_ready) { - zarr::ZarrVersion version = zarr::ZarrVersion::kV2; - if (version_ready.result().ok()) { - version = version_ready.value(); + // A version detection failure means the path has no store + // markers; propagate it instead of falling back to V2. + if (!version_ready.result().ok()) { + promise.SetResult(version_ready.result().status()); + return; } + zarr::ZarrVersion version = version_ready.value(); auto result_future = zarr::ReadDatasetMetadata( version, dataset_path, tensorstore::MakeReadyFuture(kvs)); @@ -154,6 +161,51 @@ from_zmetadata(const std::string& dataset_path, return pair.future; } + +/** + * @brief Dataset metadata fields that are purely informational. + * + * They do not affect how data is read, so the read path tolerates their + * absence (with a warning) instead of rejecting the store. The create + * path (`from_json` -> `Construct` -> `validate_dataset`) keeps requiring + * them, and stores written by mdio-cpp always carry them. + */ +inline constexpr std::array kInformationalDatasetFields = { + "name", "apiVersion", "createdOn"}; + +/** + * @brief Warns when an opened store is missing informational dataset metadata. + * + * The fields above do not affect how data is read, so an open store missing + * them is still usable; this only reports the gap. Stores carrying the v0 + * marker (`api_version`) are skipped -- they are rejected downstream with a + * dedicated v0 error and would only produce a misleading warning here. + * + * @param metadata The dataset metadata read from the store. + * @param dataset_path The path the store was opened from. + */ +inline void WarnOnMissingDatasetMetadata(const ::nlohmann::json& metadata, + const std::string& dataset_path) { + if (metadata.contains("api_version")) { + // v0 store; rejected downstream with its own error message. + return; + } + std::vector missing; + for (const auto field : kInformationalDatasetFields) { + if (!metadata.contains(field)) { + missing.push_back(field); + } + } + if (missing.empty()) { + return; + } + ABSL_LOG(WARNING) + << "Dataset '" << dataset_path + << "' is missing dataset metadata field(s): " + << absl::StrJoin(missing, ", ") + << ". Continuing without them; these fields are informational and do " + "not affect how the dataset is read."; +} } // namespace internal using coordinate_map = @@ -937,6 +989,11 @@ class Dataset { mdio::internal::from_zmetadata(dataset_path, context).result()); auto [dataset_metadata, json_vars] = params_from_zmetadata; + // The read path tolerates stores without the informational dataset + // metadata fields; warn about the gap. Creation specs keep going + // through `Construct`'s strict validation. + internal::WarnOnMissingDatasetMetadata(dataset_metadata, dataset_path); + return mdio::Dataset::Open(dataset_metadata, json_vars, std::forward