Skip to content

Commit

Permalink
Merge branch 'main' into renovate/rust-libraries-toolchains
Browse files Browse the repository at this point in the history
  • Loading branch information
TimDiekmann authored May 8, 2023
2 parents 9c989a2 + 228a100 commit 925a461
Show file tree
Hide file tree
Showing 14 changed files with 109 additions and 59 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ jobs:
- name: Launch external services
run: |
yarn turbo codegen --filter '@apps/hash-external-services'
yarn workspace @apps/hash-external-services deploy up --detach
yarn workspace @apps/hash-external-services deploy:test up --detach
- run: yarn test:backend-integration
env:
Expand Down
12 changes: 11 additions & 1 deletion apps/hash-external-services/docker-compose.test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ services:
environment:
HASH_KRATOS_PG_DATABASE: "${HASH_KRATOS_PG_TEST_DATABASE}"
HASH_TEMPORAL_PG_DATABASE: "${HASH_TEMPORAL_PG_TEST_DATABASE}"
HASH_TEMPORAL_VISIBILITY_PG_DATABASE: "${HASH_TEMPORAL_VISIBILITY_PG_DATABASE}"
HASH_TEMPORAL_VISIBILITY_PG_DATABASE: "${HASH_TEMPORAL_VISIBILITY_PG_TEST_DATABASE}"
HASH_GRAPH_PG_DATABASE: "${HASH_GRAPH_PG_TEST_DATABASE}"

graph-migrate:
Expand All @@ -28,6 +28,16 @@ services:
environment:
- DSN=postgres://${HASH_KRATOS_PG_USER}:${HASH_KRATOS_PG_PASSWORD}@postgres:${POSTGRES_PORT}/${HASH_KRATOS_PG_TEST_DATABASE}

temporal-setup:
environment:
DBNAME: "${HASH_TEMPORAL_PG_TEST_DATABASE}"
VISIBILITY_DBNAME: "${HASH_TEMPORAL_VISIBILITY_PG_TEST_DATABASE}"

temporal-migrate:
environment:
DBNAME: "${HASH_TEMPORAL_PG_TEST_DATABASE}"
VISIBILITY_DBNAME: "${HASH_TEMPORAL_VISIBILITY_PG_TEST_DATABASE}"

temporal:
environment:
DBNAME: "${HASH_TEMPORAL_PG_TEST_DATABASE}"
Expand Down
1 change: 1 addition & 0 deletions apps/hash-graph/lib/graph/src/api/rest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -422,6 +422,7 @@ impl Modify for OperationGraphTagAddon {
struct FilterSchemaAddon;

impl Modify for FilterSchemaAddon {
#[expect(clippy::too_many_lines)]
fn modify(&self, openapi: &mut openapi::OpenApi) {
// This magically generates `any`, which is the closest representation we found working
// with the OpenAPI generator.
Expand Down
19 changes: 17 additions & 2 deletions apps/hash-graph/lib/graph/src/snapshot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ mod ontology;
mod restore;

use async_trait::async_trait;
use error_stack::{Context, IntoReport, Report, Result, ResultExt};
use error_stack::{ensure, Context, IntoReport, Report, Result, ResultExt};
use futures::{stream, SinkExt, Stream, StreamExt, TryFutureExt, TryStreamExt};
use hash_status::StatusCode;
use serde::{Deserialize, Serialize};
Expand Down Expand Up @@ -211,7 +211,7 @@ impl<C: AsClient> SnapshotStore<C> {
) -> Result<(), SnapshotRestoreError> {
tracing::info!("snapshot restore started");

let (snapshot_record_tx, snapshot_record_rx) = restore::channel(chunk_size);
let (snapshot_record_tx, snapshot_record_rx, metadata_rx) = restore::channel(chunk_size);

let read_thread = tokio::spawn(
snapshot
Expand Down Expand Up @@ -278,6 +278,21 @@ impl<C: AsClient> SnapshotStore<C> {
.into_report()
.change_context(SnapshotRestoreError::Read)??;

let mut found_metadata = false;
for metadata in metadata_rx.collect::<Vec<SnapshotMetadata>>().await {
if found_metadata {
tracing::warn!("found more than one metadata record in the snapshot");
}
found_metadata = true;

ensure!(
metadata.block_protocol_module_versions.graph == semver::Version::new(0, 3, 0),
SnapshotRestoreError::Unsupported
);
}

ensure!(found_metadata, SnapshotRestoreError::MissingMetadata);

tracing::info!("snapshot restore finished");

Ok(())
Expand Down
2 changes: 2 additions & 0 deletions apps/hash-graph/lib/graph/src/snapshot/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ impl Error for SnapshotDumpError {}
#[derive(Debug)]
pub enum SnapshotRestoreError {
Unsupported,
MissingMetadata,
Read,
Buffer,
Write,
Expand All @@ -31,6 +32,7 @@ impl fmt::Display for SnapshotRestoreError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::Unsupported => write!(f, "The snapshot contains unsupported entries"),
Self::MissingMetadata => write!(f, "The snapshot does not contain metadata"),
Self::Read => write!(f, "could not read a snapshot entry"),
Self::Buffer => write!(f, "could not buffer a snapshot entry"),
Self::Write => write!(f, "could not write a snapshot entry into the store"),
Expand Down
42 changes: 32 additions & 10 deletions apps/hash-graph/lib/graph/src/snapshot/restore/channel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@ use std::{
task::{ready, Context, Poll},
};

use error_stack::{ensure, Report, ResultExt};
use error_stack::{IntoReport, Report, ResultExt};
use futures::{
channel::mpsc::{self, UnboundedReceiver, UnboundedSender},
stream::{select_all, BoxStream, SelectAll},
Sink, SinkExt, Stream, StreamExt,
};
Expand All @@ -15,11 +16,12 @@ use crate::snapshot::{
entity::{self, EntitySender},
ontology::{self, DataTypeSender, EntityTypeSender, PropertyTypeSender},
restore::batch::SnapshotRecordBatch,
SnapshotEntry, SnapshotRestoreError,
SnapshotEntry, SnapshotMetadata, SnapshotRestoreError,
};

#[derive(Debug, Clone)]
pub struct SnapshotRecordSender {
metadata: UnboundedSender<SnapshotMetadata>,
data_type: DataTypeSender,
property_type: PropertyTypeSender,
entity_type: EntityTypeSender,
Expand All @@ -33,6 +35,10 @@ impl Sink<SnapshotEntry> for SnapshotRecordSender {
mut self: Pin<&mut Self>,
cx: &mut Context<'_>,
) -> Poll<StdResult<(), Self::Error>> {
ready!(self.metadata.poll_ready_unpin(cx))
.into_report()
.change_context(SnapshotRestoreError::Read)
.attach_printable("could not poll metadata sender")?;
ready!(self.data_type.poll_ready_unpin(cx))
.attach_printable("could not poll data type sender")?;
ready!(self.property_type.poll_ready_unpin(cx))
Expand All @@ -47,13 +53,12 @@ impl Sink<SnapshotEntry> for SnapshotRecordSender {

fn start_send(mut self: Pin<&mut Self>, entity: SnapshotEntry) -> StdResult<(), Self::Error> {
match entity {
SnapshotEntry::Snapshot(snapshot) => {
ensure!(
snapshot.block_protocol_module_versions.graph == semver::Version::new(0, 3, 0),
SnapshotRestoreError::Unsupported
);
Ok(())
}
SnapshotEntry::Snapshot(snapshot) => self
.metadata
.start_send_unpin(snapshot)
.into_report()
.change_context(SnapshotRestoreError::Read)
.attach_printable("could not send snapshot metadata"),
SnapshotEntry::DataType(data_type) => self
.data_type
.start_send_unpin(data_type)
Expand All @@ -77,6 +82,10 @@ impl Sink<SnapshotEntry> for SnapshotRecordSender {
mut self: Pin<&mut Self>,
cx: &mut Context<'_>,
) -> Poll<StdResult<(), Self::Error>> {
ready!(self.metadata.poll_flush_unpin(cx))
.into_report()
.change_context(SnapshotRestoreError::Read)
.attach_printable("could not flush metadata sender")?;
ready!(self.data_type.poll_flush_unpin(cx))
.attach_printable("could not flush data type sender")?;
ready!(self.property_type.poll_flush_unpin(cx))
Expand All @@ -93,6 +102,10 @@ impl Sink<SnapshotEntry> for SnapshotRecordSender {
mut self: Pin<&mut Self>,
cx: &mut Context<'_>,
) -> Poll<StdResult<(), Self::Error>> {
ready!(self.metadata.poll_close_unpin(cx))
.into_report()
.change_context(SnapshotRestoreError::Read)
.attach_printable("could not close metadata sender")?;
ready!(self.data_type.poll_close_unpin(cx))
.attach_printable("could not close data type sender")?;
ready!(self.property_type.poll_close_unpin(cx))
Expand All @@ -118,7 +131,14 @@ impl Stream for SnapshotRecordReceiver {
}
}

pub fn channel(chunk_size: usize) -> (SnapshotRecordSender, SnapshotRecordReceiver) {
pub fn channel(
chunk_size: usize,
) -> (
SnapshotRecordSender,
SnapshotRecordReceiver,
UnboundedReceiver<SnapshotMetadata>,
) {
let (metadata_tx, metadata_rx) = mpsc::unbounded();
let (account_tx, account_rx) = account::channel(chunk_size);
let (ontology_metadata_tx, ontology_metadata_rx) =
ontology::ontology_metadata_channel(chunk_size, account_tx.clone());
Expand All @@ -132,6 +152,7 @@ pub fn channel(chunk_size: usize) -> (SnapshotRecordSender, SnapshotRecordReceiv

(
SnapshotRecordSender {
metadata: metadata_tx,
data_type: data_type_tx,
property_type: property_type_tx,
entity_type: entity_type_tx,
Expand All @@ -151,5 +172,6 @@ pub fn channel(chunk_size: usize) -> (SnapshotRecordSender, SnapshotRecordReceiv
entity_rx.map(SnapshotRecordBatch::Entities).boxed(),
]),
},
metadata_rx,
)
}
8 changes: 4 additions & 4 deletions libs/error-stack/src/fmt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@
//! ## Example
//!
//! ```rust
//! # // we only test with Rust 1.65, which means that `render()` is unused on earlier version
//! # #![cfg_attr(not(rust_1_65), allow(dead_code, unused_variables, unused_imports))]
//! # // we only test with nightly, which means that `render()` is unused on earlier version
//! # #![cfg_attr(not(nightly), allow(dead_code, unused_variables, unused_imports))]
//! use std::fmt::{Display, Formatter};
//! use std::io::{Error, ErrorKind};
//! use error_stack::Report;
Expand Down Expand Up @@ -110,12 +110,12 @@
//! # ansi_to_html::convert_escaped(value.as_ref()).unwrap()
//! # }
//! #
//! # #[cfg(rust_1_65)]
//! # #[cfg(nightly)]
//! # expect_test::expect_file![concat!(env!("CARGO_MANIFEST_DIR"), "/tests/snapshots/doc/fmt__doc.snap")].assert_eq(&render(format!("{report:?}")));
//! #
//! println!("{report:?}");
//!
//! # #[cfg(rust_1_65)]
//! # #[cfg(nightly)]
//! # expect_test::expect_file![concat!(env!("CARGO_MANIFEST_DIR"), "/tests/snapshots/doc/fmt_doc_alt.snap")].assert_eq(&render(format!("{report:#?}")));
//! #
//! println!("{report:#?}");
Expand Down
8 changes: 4 additions & 4 deletions libs/error-stack/src/fmt/charset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ impl Report<()> {
/// # Example
///
/// ```
/// # // we only test the snapshot on rust 1.65, therefore report is unused (so is render)
/// # #![cfg_attr(not(rust_1_65), allow(dead_code, unused_variables, unused_imports))]
/// # // we only test the snapshot on nightly, therefore report is unused (so is render)
/// # #![cfg_attr(not(nightly), allow(dead_code, unused_variables, unused_imports))]
/// use std::io::{Error, ErrorKind};
///
/// use error_stack::{report, Report};
Expand Down Expand Up @@ -90,12 +90,12 @@ impl Report<()> {
/// #
/// Report::set_charset(Charset::Utf8);
/// println!("{report:?}");
/// # #[cfg(rust_1_65)]
/// # #[cfg(nightly)]
/// # expect_test::expect_file![concat!(env!("CARGO_MANIFEST_DIR"), "/tests/snapshots/doc/fmt__charset_utf8.snap")].assert_eq(&render(format!("{report:?}")));
///
/// Report::set_charset(Charset::Ascii);
/// println!("{report:?}");
/// # #[cfg(rust_1_65)]
/// # #[cfg(nightly)]
/// # expect_test::expect_file![concat!(env!("CARGO_MANIFEST_DIR"), "/tests/snapshots/doc/fmt__charset_ascii.snap")].assert_eq(&render(format!("{report:?}")));
/// ```
///
Expand Down
10 changes: 5 additions & 5 deletions libs/error-stack/src/fmt/color.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@ impl Report<()> {
/// # Example
///
/// ```
/// # // we only test the snapshot on rust 1.65, therefore report is unused (so is render)
/// # #![cfg_attr(not(rust_1_65), allow(dead_code, unused_variables, unused_imports))]
/// # // we only test the snapshot on nightly, therefore report is unused (so is render)
/// # #![cfg_attr(not(nightly), allow(dead_code, unused_variables, unused_imports))]
/// use std::io::{Error, ErrorKind};
/// use owo_colors::OwoColorize;
///
Expand Down Expand Up @@ -102,17 +102,17 @@ impl Report<()> {
/// #
/// Report::set_color_mode(ColorMode::None);
/// println!("{report:?}");
/// # #[cfg(rust_1_65)]
/// # #[cfg(nightly)]
/// # expect_test::expect_file![concat!(env!("CARGO_MANIFEST_DIR"), "/tests/snapshots/doc/fmt__preference_none.snap")].assert_eq(&render(format!("{report:?}")));
///
/// Report::set_color_mode(ColorMode::Emphasis);
/// println!("{report:?}");
/// # #[cfg(rust_1_65)]
/// # #[cfg(nightly)]
/// # expect_test::expect_file![concat!(env!("CARGO_MANIFEST_DIR"), "/tests/snapshots/doc/fmt__preference_emphasis.snap")].assert_eq(&render(format!("{report:?}")));
///
/// Report::set_color_mode(ColorMode::Color);
/// println!("{report:?}");
/// # #[cfg(rust_1_65)]
/// # #[cfg(nightly)]
/// # expect_test::expect_file![concat!(env!("CARGO_MANIFEST_DIR"), "/tests/snapshots/doc/fmt__preference_color.snap")].assert_eq(&render(format!("{report:?}")));
/// ```
///
Expand Down
26 changes: 13 additions & 13 deletions libs/error-stack/src/fmt/hook.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@ crate::hook::context::impl_hook_context! {
/// ### Example
///
/// ```rust
/// # // we only test with Rust 1.65, which means that `render()` is unused on earlier version
/// # #![cfg_attr(not(rust_1_65), allow(dead_code, unused_variables, unused_imports))]
/// # // we only test with nightly, which means that `render()` is unused on earlier version
/// # #![cfg_attr(not(nightly), allow(dead_code, unused_variables, unused_imports))]
/// use std::io::{Error, ErrorKind};
///
/// use error_stack::Report;
Expand Down Expand Up @@ -130,12 +130,12 @@ crate::hook::context::impl_hook_context! {
/// # ansi_to_html::convert_escaped(value.as_ref()).unwrap()
/// # }
/// #
/// # #[cfg(rust_1_65)]
/// # #[cfg(nightly)]
/// # expect_test::expect_file![concat!(env!("CARGO_MANIFEST_DIR"), "/tests/snapshots/doc/fmt__emit.snap")].assert_eq(&render(format!("{report:?}")));
/// #
/// println!("{report:?}");
///
/// # #[cfg(rust_1_65)]
/// # #[cfg(nightly)]
/// # expect_test::expect_file![concat!(env!("CARGO_MANIFEST_DIR"), "/tests/snapshots/doc/fmt__emit_alt.snap")].assert_eq(&render(format!("{report:#?}")));
/// #
/// println!("{report:#?}");
Expand Down Expand Up @@ -168,8 +168,8 @@ crate::hook::context::impl_hook_context! {
/// ### Example
///
/// ```rust
/// # // we only test with Rust 1.65, which means that `render()` is unused on earlier version
/// # #![cfg_attr(not(rust_1_65), allow(dead_code, unused_variables, unused_imports))]
/// # // we only test with nightly, which means that `render()` is unused on earlier version
/// # #![cfg_attr(not(nightly), allow(dead_code, unused_variables, unused_imports))]
/// use std::io::ErrorKind;
///
/// use error_stack::Report;
Expand Down Expand Up @@ -210,7 +210,7 @@ crate::hook::context::impl_hook_context! {
/// # ansi_to_html::convert_escaped(value.as_ref()).unwrap()
/// # }
/// #
/// # #[cfg(rust_1_65)]
/// # #[cfg(nightly)]
/// # expect_test::expect_file![concat!(env!("CARGO_MANIFEST_DIR"), "/tests/snapshots/doc/fmt__hookcontext_storage.snap")].assert_eq(&render(format!("{report:?}")));
/// #
/// println!("{report:?}");
Expand Down Expand Up @@ -255,8 +255,8 @@ impl<T> HookContext<T> {
/// # Example
///
/// ```rust
/// # // we only test with Rust 1.65, which means that `render()` is unused on earlier version
/// # #![cfg_attr(not(rust_1_65), allow(dead_code, unused_variables, unused_imports))]
/// # // we only test with nightly, which means that `render()` is unused on earlier version
/// # #![cfg_attr(not(nightly), allow(dead_code, unused_variables, unused_imports))]
/// use std::io::ErrorKind;
///
/// use error_stack::Report;
Expand Down Expand Up @@ -296,7 +296,7 @@ impl<T> HookContext<T> {
/// # ansi_to_html::convert_escaped(value.as_ref()).unwrap()
/// # }
/// #
/// # #[cfg(rust_1_65)]
/// # #[cfg(nightly)]
/// # expect_test::expect_file![concat!(env!("CARGO_MANIFEST_DIR"), "/tests/snapshots/doc/fmt__hookcontext_emit.snap")].assert_eq(&render(format!("{report:#?}")));
/// #
/// println!("{report:#?}");
Expand All @@ -314,8 +314,8 @@ impl<T> HookContext<T> {
/// # Example
///
/// ```rust
/// # // we only test with Rust 1.65, which means that `render()` is unused on earlier version
/// # #![cfg_attr(not(rust_1_65), allow(dead_code, unused_variables, unused_imports))]
/// # // we only test with nightly, which means that `render()` is unused on earlier version
/// # #![cfg_attr(not(nightly), allow(dead_code, unused_variables, unused_imports))]
/// use std::io;
///
/// use error_stack::Report;
Expand Down Expand Up @@ -343,7 +343,7 @@ impl<T> HookContext<T> {
/// # ansi_to_html::convert_escaped(value.as_ref()).unwrap()
/// # }
/// #
/// # #[cfg(rust_1_65)]
/// # #[cfg(nightly)]
/// # expect_test::expect_file![concat!(env!("CARGO_MANIFEST_DIR"), "/tests/snapshots/doc/fmt__diagnostics_add.snap")].assert_eq(&render(format!("{report:?}")));
/// #
/// println!("{report:?}");
Expand Down
6 changes: 3 additions & 3 deletions libs/error-stack/src/hook.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ impl Report<()> {
/// # Examples
///
/// ```
/// # // we only test the snapshot on rust 1.65, therefore report is unused (so is render)
/// # #![cfg_attr(not(rust_1_65), allow(dead_code, unused_variables, unused_imports))]
/// # // we only test the snapshot on nightly, therefore report is unused (so is render)
/// # #![cfg_attr(not(nightly), allow(dead_code, unused_variables, unused_imports))]
/// use std::io::{Error, ErrorKind};
///
/// use error_stack::{
Expand All @@ -56,7 +56,7 @@ impl Report<()> {
/// # ansi_to_html::convert_escaped(value.as_ref()).unwrap()
/// # }
/// #
/// # #[cfg(rust_1_65)]
/// # #[cfg(nightly)]
/// # expect_test::expect_file![concat!(env!("CARGO_MANIFEST_DIR"), "/tests/snapshots/doc/hook__debug_hook.snap")].assert_eq(&render(format!("{report:?}")));
/// #
/// println!("{report:?}");
Expand Down
Loading

0 comments on commit 925a461

Please sign in to comment.