@@ -761,16 +761,6 @@ node_in_cluster(int id)
761
761
return res ;
762
762
}
763
763
764
- static void
765
- rm_partition (int node_id , char const * part_name )
766
- {
767
- char * sql ;
768
- sql = psprintf ("delete from shardman.partitions where owner=%d and part_name='%s'" ,
769
- node_id , part_name );
770
- void_spi (sql );
771
- pfree (sql );
772
- }
773
-
774
764
/*
775
765
* Remove node, losing all data on it. We
776
766
* - ensure that there is active node with given id in the cluster
@@ -787,7 +777,7 @@ rm_node(Cmd *cmd)
787
777
char * sql ;
788
778
char * * opts ;
789
779
bool force = false;
790
- int i , e ;
780
+ int e ;
791
781
792
782
for (opts = cmd -> opts ; * opts ; opts ++ )
793
783
{
@@ -799,28 +789,26 @@ rm_node(Cmd *cmd)
799
789
}
800
790
801
791
SPI_PROLOG ;
802
- sql = psprintf ("select part_name from shardman.partitions where owner=%d" , node_id );
803
- e = SPI_execute (sql , true, 0 );
804
- if (e < 0 )
805
- shmn_elog (FATAL , "Stmt failed: %s" , sql );
806
- pfree (sql );
807
- if (SPI_processed > 0 )
792
+ if (force )
808
793
{
809
- TupleDesc rowdesc = SPI_tuptable -> tupdesc ;
810
- if (!force )
794
+ sql = psprintf ("delete from shardman.partitions where owner=%d" , node_id );
795
+ void_spi (sql );
796
+ }
797
+ else
798
+ {
799
+ bool isnull ;
800
+ sql = psprintf ("select count(*) from shardman.partitions where owner=%d" , node_id );
801
+ e = SPI_execute (sql , true, 0 );
802
+ if (e < 0 )
803
+ shmn_elog (FATAL , "Stmt failed: %s" , sql );
804
+ Assert (SPI_processed == 1 );
805
+ if (DatumGetInt64 (SPI_getbinval (SPI_tuptable -> vals [0 ], SPI_tuptable -> tupdesc , 1 , & isnull )) != 0 )
811
806
{
812
-
813
807
ereport (ERROR , (errmsg ("Can not remove node with existed partitions" ),
814
808
errhint ("Add \"force\" option to remove node with existed partitions." )));
815
809
}
816
- /* Remove partitions belonging to this node */
817
- for (i = 0 ; i < SPI_processed ; i ++ )
818
- {
819
- HeapTuple tuple = SPI_tuptable -> vals [i ];
820
- char const * partition = SPI_getvalue (tuple , rowdesc , 1 );
821
- rm_partition (node_id , partition );
822
- }
823
810
}
811
+ pfree (sql );
824
812
SPI_EPILOG ;
825
813
826
814
elog (INFO , "Removing node %d " , node_id );
0 commit comments