@@ -486,35 +486,42 @@ bgw_main_concurrent_part(Datum main_arg)
486
486
/* Exec ret = _partition_data_concurrent() */
487
487
PG_TRY ();
488
488
{
489
- int ret ;
490
- bool isnull ;
491
-
492
489
/* Make sure that relation exists and has partitions */
493
- if (! SearchSysCacheExists1 (RELOID , ObjectIdGetDatum (part_slot -> relid )) ||
494
- get_pathman_relation_info (part_slot -> relid ) = = NULL )
490
+ if (SearchSysCacheExists1 (RELOID , ObjectIdGetDatum (part_slot -> relid )) &&
491
+ get_pathman_relation_info (part_slot -> relid ) ! = NULL )
495
492
{
496
- /* Fail fast */
497
- failures_count = PART_WORKER_MAX_ATTEMPTS ;
493
+ int ret ;
494
+ bool isnull ;
498
495
499
- elog (ERROR , "relation %u is not partitioned (or does not exist)" ,
500
- part_slot -> relid );
501
- }
496
+ ret = SPI_execute_with_args (sql , 2 , types , vals , nulls , false, 0 );
497
+ if (ret == SPI_OK_SELECT )
498
+ {
499
+ TupleDesc tupdesc = SPI_tuptable -> tupdesc ;
500
+ HeapTuple tuple = SPI_tuptable -> vals [0 ];
502
501
503
- ret = SPI_execute_with_args (sql , 2 , types , vals , nulls , false, 0 );
504
- if (ret == SPI_OK_SELECT )
505
- {
506
- TupleDesc tupdesc = SPI_tuptable -> tupdesc ;
507
- HeapTuple tuple = SPI_tuptable -> vals [0 ];
502
+ Assert (SPI_processed == 1 ); /* there should be 1 result at most */
508
503
509
- Assert ( SPI_processed == 1 ); /* there should be 1 result at most */
504
+ rows = DatumGetInt32 ( SPI_getbinval ( tuple , tupdesc , 1 , & isnull ));
510
505
511
- rows = DatumGetInt32 (SPI_getbinval (tuple , tupdesc , 1 , & isnull ));
506
+ Assert (!isnull ); /* ... and ofc it must not be NULL */
507
+ }
508
+ }
509
+ /* Otherwise it's time to exit */
510
+ else
511
+ {
512
+ failures_count = PART_WORKER_MAX_ATTEMPTS ;
512
513
513
- Assert (!isnull ); /* ... and ofc it must not be NULL */
514
+ elog (LOG , "relation %u is not partitioned (or does not exist)" ,
515
+ part_slot -> relid );
514
516
}
515
517
}
516
518
PG_CATCH ();
517
519
{
520
+ /*
521
+ * The most common exception we can catch here is a deadlock with
522
+ * concurrent user queries. Check that attempts count doesn't exceed
523
+ * some reasonable value
524
+ */
518
525
ErrorData * error ;
519
526
char * sleep_time_str ;
520
527
@@ -545,11 +552,7 @@ bgw_main_concurrent_part(Datum main_arg)
545
552
SPI_finish ();
546
553
PopActiveSnapshot ();
547
554
548
- /*
549
- * The most common exception we can catch here is a deadlock with
550
- * concurrent user queries. Check that attempts count doesn't exceed
551
- * some reasonable value
552
- */
555
+ /* We've run out of attempts, exit */
553
556
if (failures_count >= PART_WORKER_MAX_ATTEMPTS )
554
557
{
555
558
AbortCurrentTransaction ();
@@ -563,14 +566,19 @@ bgw_main_concurrent_part(Datum main_arg)
563
566
"see the error message below" ,
564
567
PART_WORKER_MAX_ATTEMPTS );
565
568
566
- return ;
569
+ return ; /* time to exit */
567
570
}
571
+
572
+ /* Failed this time, wait */
568
573
else if (failed )
569
574
{
570
575
/* Abort transaction and sleep for a second */
571
576
AbortCurrentTransaction ();
577
+
572
578
DirectFunctionCall1 (pg_sleep , Float8GetDatum (part_slot -> sleep_time ));
573
579
}
580
+
581
+ /* Everything is fine */
574
582
else
575
583
{
576
584
/* Commit transaction and reset 'failures_count' */
@@ -592,7 +600,7 @@ bgw_main_concurrent_part(Datum main_arg)
592
600
if (cps_check_status (part_slot ) == CPS_STOPPING )
593
601
break ;
594
602
}
595
- while (rows > 0 || failed ); /* do while there's still rows to be relocated */
603
+ while (rows > 0 || failed ); /* do while there's still rows to be relocated */
596
604
597
605
/* Reclaim the resources */
598
606
pfree (sql );
0 commit comments