MCPcopy Create free account
hub / github.com/hashintel/hash / snapshot

Function snapshot

apps/hash-graph/src/subcommand/snapshot.rs:84–146  ·  view source on GitHub ↗
(args: SnapshotArgs)

Source from the content-addressed store, hash-verified

82}
83
84pub async fn snapshot(args: SnapshotArgs) -> Result<(), Report<GraphError>> {
85 SnapshotEntry::install_error_stack_hook();
86
87 let mut settings = PostgresStoreSettings::default();
88 if let SnapshotCommand::Restore(args) = &args.command {
89 settings.validate_links = !args.skip_validation;
90 }
91
92 let pool = PostgresStorePool::new(&args.db_info, &args.pool_config, NoTls, settings)
93 .await
94 .change_context(GraphError)
95 .map_err(|report| {
96 tracing::error!(error = ?report, "Failed to connect to database");
97 report
98 })?;
99
100 match args.command {
101 SnapshotCommand::Dump(args) => {
102 let write = FramedWrite::new(
103 io::BufWriter::new(io::stdout()),
104 JsonLinesEncoder::default(),
105 );
106 let settings = SnapshotDumpSettings {
107 chunk_size: 10_000,
108 dump_principals: !args.no_principals,
109 dump_actions: !args.no_actions,
110 dump_policies: !args.no_policies,
111 dump_entities: !args.no_entities,
112 dump_entity_types: !args.no_entity_types,
113 dump_property_types: !args.no_property_types,
114 dump_data_types: !args.no_data_types,
115 dump_embeddings: !args.no_embeddings,
116 };
117
118 pool.dump_snapshot(write, settings)
119 .change_context(GraphError)
120 .attach("Failed to produce snapshot dump")?;
121
122 tracing::info!("Snapshot dumped successfully");
123 }
124 SnapshotCommand::Restore(args) => {
125 let read =
126 FramedRead::new(io::BufReader::new(io::stdin()), JsonLinesDecoder::default());
127 SnapshotStore::new(
128 pool.acquire(None)
129 .await
130 .change_context(GraphError)
131 .map_err(|report| {
132 tracing::error!(error = ?report, "Failed to acquire database connection");
133 report
134 })?,
135 )
136 .restore_snapshot(read, 10_000, args.ignore_validation_errors)
137 .await
138 .change_context(GraphError)
139 .attach("Failed to restore snapshot")?;
140
141 tracing::info!("Snapshot restored successfully");

Callers 1

executeMethod · 0.85

Calls 8

OkInterface · 0.85
map_errMethod · 0.80
dump_snapshotMethod · 0.80
restore_snapshotMethod · 0.80
acquireMethod · 0.65
defaultFunction · 0.50
change_contextMethod · 0.45
attachMethod · 0.45

Tested by

no test coverage detected