@@ -26,34 +26,35 @@ static void bg_worker_main(Datum main_arg);
2626
2727typedef struct PartitionArgs
2828{
29- Oid dbid ;
30- Oid relid ;
29+ Oid dbid ;
30+ Oid relid ;
3131#ifdef HAVE_INT64_TIMESTAMP
3232int64 value ;
3333#else
3434double value ;
3535#endif
36- Oid value_type ;
36+ Oid value_type ;
3737bool by_val ;
38- Oid result ;
38+ Oid result ;
39+ bool crashed ;
3940}PartitionArgs ;
4041
4142/*
4243 * Starts background worker that will create new partitions,
4344 * waits till it finishes the job and returns the result (new partition oid)
4445 */
4546Oid
46- create_partitions_bg_worker (Oid relid ,Datum value ,Oid value_type )
47+ create_partitions_bg_worker (Oid relid ,Datum value ,Oid value_type , bool * crashed )
4748{
4849BackgroundWorker worker ;
4950BackgroundWorkerHandle * worker_handle ;
5051BgwHandleStatus status ;
5152dsm_segment * segment ;
5253dsm_handle segment_handle ;
5354pid_t pid ;
54- PartitionArgs * args ;
55+ PartitionArgs * args ;
5556Oid child_oid ;
56- TypeCacheEntry * tce ;
57+ TypeCacheEntry * tce ;
5758
5859/* Create a dsm segment for the worker to pass arguments */
5960segment = dsm_create (sizeof (PartitionArgs ),0 );
@@ -98,6 +99,7 @@ create_partitions_bg_worker(Oid relid, Datum value, Oid value_type)
9899
99100/* Wait till the worker finishes its job */
100101status = WaitForBackgroundWorkerShutdown (worker_handle );
102+ * crashed = args -> crashed ;
101103child_oid = args -> result ;
102104
103105/* Free dsm segment */
@@ -112,7 +114,7 @@ create_partitions_bg_worker(Oid relid, Datum value, Oid value_type)
112114static void
113115bg_worker_main (Datum main_arg )
114116{
115- PartitionArgs * args ;
117+ PartitionArgs * args ;
116118dsm_handle handle = DatumGetInt32 (main_arg );
117119
118120/* Create resource owner */
@@ -134,7 +136,7 @@ bg_worker_main(Datum main_arg)
134136PushActiveSnapshot (GetTransactionSnapshot ());
135137
136138/* Create partitions */
137- args -> result = create_partitions (args -> relid ,PATHMAN_GET_DATUM (args -> value ,args -> by_val ),args -> value_type );
139+ args -> result = create_partitions (args -> relid ,PATHMAN_GET_DATUM (args -> value ,args -> by_val ),args -> value_type , & args -> crashed );
138140
139141/* Cleanup */
140142SPI_finish ();
@@ -148,7 +150,7 @@ bg_worker_main(Datum main_arg)
148150 * Create partitions and return an OID of the partition that contain value
149151 */
150152Oid
151- create_partitions (Oid relid ,Datum value ,Oid value_type )
153+ create_partitions (Oid relid ,Datum value ,Oid value_type , bool * crashed )
152154{
153155int ret ;
154156RangeEntry * ranges ;
@@ -163,6 +165,7 @@ create_partitions(Oid relid, Datum value, Oid value_type)
163165FmgrInfo cmp_func ;
164166char * schema ;
165167
168+ * crashed = false;
166169schema = get_extension_schema ();
167170
168171prel = get_pathman_relation_info (relid ,NULL );
@@ -178,16 +181,25 @@ create_partitions(Oid relid, Datum value, Oid value_type)
178181/* Perform PL procedure */
179182sql = psprintf ("SELECT %s.append_partitions_on_demand_internal($1, $2)" ,
180183schema );
181- ret = SPI_execute_with_args (sql ,2 ,oids ,vals ,nulls , false,0 );
182- if (ret > 0 )
184+ PG_TRY ();
183185{
184- /* Update relation info */
185- free_dsm_array (& rangerel -> ranges );
186- free_dsm_array (& prel -> children );
187- load_check_constraints (relid ,GetCatalogSnapshot (relid ));
186+ ret = SPI_execute_with_args (sql ,2 ,oids ,vals ,nulls , false,0 );
187+ if (ret > 0 )
188+ {
189+ /* Update relation info */
190+ free_dsm_array (& rangerel -> ranges );
191+ free_dsm_array (& prel -> children );
192+ load_check_constraints (relid ,GetCatalogSnapshot (relid ));
193+ }
188194}
189- else
195+ PG_CATCH ();
196+ {
190197elog (WARNING ,"Attempt to create new partitions failed" );
198+ if (crashed != NULL )
199+ * crashed = true;
200+ return 0 ;
201+ }
202+ PG_END_TRY ();
191203
192204/* Repeat binary search */
193205ranges = dsm_array_get_pointer (& rangerel -> ranges );