Lock relations before calling citus_table_size().

This is to make sure they don't get dropped.
pull/1751/head
Hadi Moshayedi 2017-10-31 21:20:18 -04:00 committed by Hadi Moshayedi
parent 97d544b75c
commit c18c6625d9
1 changed files with 12 additions and 0 deletions

View File

@ -154,6 +154,17 @@ DistributedTablesSize(List *distTableOids)
Oid relationId = lfirst_oid(distTableOidCell); Oid relationId = lfirst_oid(distTableOidCell);
Datum tableSizeDatum = 0; Datum tableSizeDatum = 0;
/*
* Relations can get dropped after getting the Oid list and before we
* reach here. Acquire a lock to make sure the relation is available
* while we are getting its size.
*/
Relation relation = try_relation_open(relationId, AccessShareLock);
if (relation == NULL)
{
continue;
}
/* /*
* Ignore hash partitioned tables with size greater than 1, since * Ignore hash partitioned tables with size greater than 1, since
* citus_table_size() doesn't work on them. * citus_table_size() doesn't work on them.
@ -167,6 +178,7 @@ DistributedTablesSize(List *distTableOids)
tableSizeDatum = DirectFunctionCall1(citus_table_size, tableSizeDatum = DirectFunctionCall1(citus_table_size,
ObjectIdGetDatum(relationId)); ObjectIdGetDatum(relationId));
totalSize += DatumGetInt64(tableSizeDatum); totalSize += DatumGetInt64(tableSizeDatum);
heap_close(relation, AccessShareLock);
} }
return totalSize; return totalSize;