@@ -24,6 +24,7 @@ use graph::{
2424 } ,
2525 data:: {
2626 query:: QueryTarget ,
27+ store:: DEFAULT_NODE_ID ,
2728 subgraph:: { schema:: DeploymentCreate , status, DeploymentFeatures } ,
2829 } ,
2930 internal_error,
@@ -737,35 +738,6 @@ impl Inner {
737738 }
738739 }
739740
740- /// Determine the target node for a deployment using the configured
741- /// deployment rules, ignoring the shard selection. Returns an error
742- /// if no rule matches.
743- async fn node_for_deployment (
744- & self ,
745- name : & SubgraphName ,
746- network : & str ,
747- ) -> Result < NodeId , StoreError > {
748- let placement = self
749- . placer
750- . place ( name. as_str ( ) , network)
751- . map_err ( |msg| internal_error ! ( "illegal indexer name in deployment rule: {}" , msg) ) ?;
752-
753- match placement {
754- Some ( ( _, nodes) ) if !nodes. is_empty ( ) => {
755- if nodes. len ( ) == 1 {
756- Ok ( nodes. into_iter ( ) . next ( ) . unwrap ( ) )
757- } else {
758- let mut pconn = self . primary_conn ( ) . await ?;
759- // unwrap: nodes is not empty
760- Ok ( pconn. least_assigned_node ( & nodes) . await ?. unwrap ( ) )
761- }
762- }
763- _ => Err ( StoreError :: InternalError (
764- "no deployment rule matches this deployment" . into ( ) ,
765- ) ) ,
766- }
767- }
768-
769741 pub async fn copy_deployment (
770742 & self ,
771743 src : & DeploymentLocator ,
@@ -1481,7 +1453,7 @@ impl Inner {
14811453 pub async fn restore (
14821454 & self ,
14831455 dir : & std:: path:: Path ,
1484- shard : Shard ,
1456+ shard : Option < Shard > ,
14851457 name : Option < SubgraphName > ,
14861458 mode : RestoreMode ,
14871459 ) -> Result < ( ) , StoreError > {
@@ -1490,11 +1462,6 @@ impl Inner {
14901462 let metadata_path = dir. join ( "metadata.json" ) ;
14911463 let metadata = Metadata :: from_file ( & metadata_path) ?;
14921464
1493- // Validate that the target shard exists before making any DB changes
1494- self . stores
1495- . get ( & shard)
1496- . ok_or_else ( || StoreError :: UnknownShard ( shard. to_string ( ) ) ) ?;
1497-
14981465 // Resolve the subgraph name for deployment rule matching. If not
14991466 // supplied, look up an existing name from the DB; error if none.
15001467 let name = match name {
@@ -1517,9 +1484,16 @@ impl Inner {
15171484 } ;
15181485
15191486 // Use deployment rules to determine which node should index this
1520- // deployment. The rules also return candidate shards, but we ignore
1521- // those since the shard is user-specified for restore.
1522- let node = self . node_for_deployment ( & name, & metadata. network ) . await ?;
1487+ // deployment and how to place it.
1488+ let ( placed_shard, node) = self
1489+ . place ( & name, & metadata. network , DEFAULT_NODE_ID . clone ( ) )
1490+ . await ?;
1491+ let shard = shard. unwrap_or ( placed_shard) ;
1492+
1493+ // Validate that the target shard exists before making any DB changes
1494+ self . stores
1495+ . get ( & shard)
1496+ . ok_or_else ( || StoreError :: UnknownShard ( shard. to_string ( ) ) ) ?;
15231497
15241498 let mut pconn = self . primary_conn ( ) . await ?;
15251499 let action = pconn
0 commit comments