File tree Expand file tree Collapse file tree 4 files changed +21
-17
lines changed
graph/src/components/store Expand file tree Collapse file tree 4 files changed +21
-17
lines changed Original file line number Diff line number Diff line change @@ -411,21 +411,10 @@ where
411
411
hash : & DeploymentHash ,
412
412
node_id : & NodeId ,
413
413
) -> Result < ( ) , SubgraphRegistrarError > {
414
- let locations = self . store . locators ( hash) ?;
415
- let deployment = match locations. len ( ) {
416
- 0 => return Err ( SubgraphRegistrarError :: DeploymentNotFound ( hash. to_string ( ) ) ) ,
417
- 1 => locations[ 0 ] . clone ( ) ,
418
- _ => {
419
- return Err ( SubgraphRegistrarError :: StoreError (
420
- anyhow ! (
421
- "there are {} different deployments with id {}" ,
422
- locations. len( ) ,
423
- hash. as_str( )
424
- )
425
- . into ( ) ,
426
- ) )
427
- }
428
- } ;
414
+ let locator = self . store . active_locator ( hash) ?;
415
+ let deployment =
416
+ locator. ok_or_else ( || SubgraphRegistrarError :: DeploymentNotFound ( hash. to_string ( ) ) ) ?;
417
+
429
418
self . store . reassign_subgraph ( & deployment, node_id) ?;
430
419
431
420
Ok ( ( ) )
Original file line number Diff line number Diff line change @@ -156,9 +156,13 @@ pub trait SubgraphStore: Send + Sync + 'static {
156
156
157
157
async fn is_healthy ( & self , id : & DeploymentHash ) -> Result < bool , StoreError > ;
158
158
159
- /// Find the deployment locators for the subgraph with the given hash
159
+ /// Find all deployment locators for the subgraph with the given hash.
160
160
fn locators ( & self , hash : & str ) -> Result < Vec < DeploymentLocator > , StoreError > ;
161
161
162
+ /// Find the deployment locator for the active deployment with the given
163
+ /// hash. Returns `None` if there is no deployment with that hash
164
+ fn active_locator ( & self , hash : & str ) -> Result < Option < DeploymentLocator > , StoreError > ;
165
+
162
166
/// This migrates subgraphs that existed before the raw_yaml column was added.
163
167
async fn set_manifest_raw_yaml (
164
168
& self ,
Original file line number Diff line number Diff line change @@ -138,7 +138,7 @@ async fn setup(
138
138
139
139
global_init ( ) ;
140
140
let id = DeploymentHash :: new ( id) . unwrap ( ) ;
141
- let loc = store. subgraph_store ( ) . locators ( & id) . unwrap ( ) . pop ( ) ;
141
+ let loc = store. subgraph_store ( ) . active_locator ( & id) . unwrap ( ) ;
142
142
143
143
match loc {
144
144
Some ( loc) if id_type. deployment_id ( ) == loc. hash . as_str ( ) => loc,
Original file line number Diff line number Diff line change @@ -1397,6 +1397,17 @@ impl SubgraphStoreTrait for SubgraphStore {
1397
1397
. collect ( ) )
1398
1398
}
1399
1399
1400
+ fn active_locator ( & self , hash : & str ) -> Result < Option < DeploymentLocator > , StoreError > {
1401
+ let sites = self . mirror . find_sites ( & [ hash. to_string ( ) ] , true ) ?;
1402
+ if sites. len ( ) > 1 {
1403
+ return Err ( constraint_violation ! (
1404
+ "There are {} active deployments for {hash}, there should only be one" ,
1405
+ sites. len( )
1406
+ ) ) ;
1407
+ }
1408
+ Ok ( sites. first ( ) . map ( DeploymentLocator :: from) )
1409
+ }
1410
+
1400
1411
async fn set_manifest_raw_yaml (
1401
1412
& self ,
1402
1413
hash : & DeploymentHash ,
You can’t perform that action at this time.
0 commit comments