Returns a vector of `NodePropMetadata` instances based on the collection `schema` and `metadata_fields` as per the following cases: - If both `schema` and `metadata_fields` are not None, then it computes the metadata dimensions and returns `NodePropMetadata` instances based on those. - If `metadata_fields` is None but `schema` is not None (i.e. the collection supports metadata filtering but the
(
schema: Option<&MetadataSchema>,
metadata_fields: Option<&MetadataFields>,
prop_file: &RwLock<File>,
base_id: &InternalId,
)
| 519 | /// Note that this function performs IO by writing metadata to the |
| 520 | /// prop_file |
| 521 | fn prop_metadata_replicas( |
| 522 | schema: Option<&MetadataSchema>, |
| 523 | metadata_fields: Option<&MetadataFields>, |
| 524 | prop_file: &RwLock<File>, |
| 525 | base_id: &InternalId, |
| 526 | ) -> Result<Option<Vec<NodePropMetadata>>, WaCustomError> { |
| 527 | if schema.is_none() { |
| 528 | return Ok(None); |
| 529 | } |
| 530 | |
| 531 | let replica_set = if metadata_fields.is_some() { |
| 532 | let rs = metadata_replica_set(schema.unwrap(), metadata_fields)? |
| 533 | .into_iter() |
| 534 | .enumerate() |
| 535 | .map(|(i, r)| (InternalId::from(**base_id + i as u32), r)) |
| 536 | .collect::<Vec<(InternalId, Metadata)>>(); |
| 537 | Some(rs) |
| 538 | } else { |
| 539 | // If the collection supports metadata schema and |
| 540 | // even if no metadata fields are specified with |
| 541 | // the input vector, we create one replica with |
| 542 | // base dimensions. |
| 543 | match schema { |
| 544 | Some(s) => { |
| 545 | let mrset = metadata_replica_set(s, None)?; |
| 546 | debug_assert_eq!(1, mrset.len()); |
| 547 | let result = mrset |
| 548 | .into_iter() |
| 549 | .enumerate() |
| 550 | .map(|(i, r)| (InternalId::from(**base_id + i as u32), r)) |
| 551 | .collect::<Vec<(InternalId, Metadata)>>(); |
| 552 | Some(result) |
| 553 | } |
| 554 | // Following is unreachable as the case of schema being |
| 555 | // None has already been handled |
| 556 | None => None, |
| 557 | } |
| 558 | }; |
| 559 | |
| 560 | if let Some(replicas) = replica_set { |
| 561 | let mut result = Vec::with_capacity(replicas.len()); |
| 562 | for (id, m) in replicas { |
| 563 | let mvalue = Arc::new(m); |
| 564 | |
| 565 | // Write metadata to the same prop file |
| 566 | let mut prop_file_guard = prop_file.write().map_err(|_| { |
| 567 | WaCustomError::LockError( |
| 568 | "Failed to acquire lock to write prop metadata".to_string(), |
| 569 | ) |
| 570 | })?; |
| 571 | let location = write_prop_metadata_to_file(id, mvalue.clone(), &mut prop_file_guard)?; |
| 572 | drop(prop_file_guard); |
| 573 | |
| 574 | let prop_metadata = NodePropMetadata { |
| 575 | replica_id: id, |
| 576 | vec: mvalue, |
| 577 | location, |
| 578 | }; |
no test coverage detected