Skip to content

Commit 41e1e7a

Browse files
committed
rewrite some code (make clang analyzer happy again)
1 parent 756b7f3 commit 41e1e7a

File tree

1 file changed

+33
-25
lines changed

1 file changed

+33
-25
lines changed

src/pathman_workers.c

Lines changed: 33 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -486,35 +486,42 @@ bgw_main_concurrent_part(Datum main_arg)
486486
/* Exec ret = _partition_data_concurrent() */
487487
PG_TRY();
488488
{
489-
int ret;
490-
bool isnull;
491-
492489
/* 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)
495492
{
496-
/* Fail fast */
497-
failures_count = PART_WORKER_MAX_ATTEMPTS;
493+
int ret;
494+
bool isnull;
498495

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];
502501

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 */
508503

509-
Assert(SPI_processed == 1); /* there should be 1 result at most */
504+
rows = DatumGetInt32(SPI_getbinval(tuple, tupdesc, 1, &isnull));
510505

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;
512513

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);
514516
}
515517
}
516518
PG_CATCH();
517519
{
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+
*/
518525
ErrorData *error;
519526
char *sleep_time_str;
520527

@@ -545,11 +552,7 @@ bgw_main_concurrent_part(Datum main_arg)
545552
SPI_finish();
546553
PopActiveSnapshot();
547554

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 */
553556
if (failures_count >= PART_WORKER_MAX_ATTEMPTS)
554557
{
555558
AbortCurrentTransaction();
@@ -563,14 +566,19 @@ bgw_main_concurrent_part(Datum main_arg)
563566
"see the error message below",
564567
PART_WORKER_MAX_ATTEMPTS);
565568

566-
return;
569+
return; /* time to exit */
567570
}
571+
572+
/* Failed this time, wait */
568573
else if (failed)
569574
{
570575
/* Abort transaction and sleep for a second */
571576
AbortCurrentTransaction();
577+
572578
DirectFunctionCall1(pg_sleep, Float8GetDatum(part_slot->sleep_time));
573579
}
580+
581+
/* Everything is fine */
574582
else
575583
{
576584
/* Commit transaction and reset 'failures_count' */
@@ -592,7 +600,7 @@ bgw_main_concurrent_part(Datum main_arg)
592600
if (cps_check_status(part_slot) == CPS_STOPPING)
593601
break;
594602
}
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 */
596604

597605
/* Reclaim the resources */
598606
pfree(sql);

0 commit comments

Comments
 (0)