mirror of https://github.com/citusdata/citus.git
Perform relcache invalidation in CitusInvalidateRelcacheByRelid
parent
52f11223e5
commit
2af6797c04
|
@ -246,7 +246,7 @@ master_create_distributed_table(PG_FUNCTION_ARGS)
|
|||
/* finally insert tuple, build index entries & register cache invalidation */
|
||||
simple_heap_insert(pgDistPartition, newTuple);
|
||||
CatalogUpdateIndexes(pgDistPartition, newTuple);
|
||||
CacheInvalidateRelcacheByRelid(distributedRelationId);
|
||||
CitusInvalidateRelcacheByRelid(distributedRelationId);
|
||||
|
||||
RecordDistributedRelationDependencies(distributedRelationId, distributionKey);
|
||||
|
||||
|
|
|
@ -394,7 +394,7 @@ InsertShardRow(Oid relationId, uint64 shardId, char storageType,
|
|||
|
||||
/* close relation and invalidate previous cache entry */
|
||||
heap_close(pgDistShard, RowExclusiveLock);
|
||||
CacheInvalidateRelcacheByRelid(relationId);
|
||||
CitusInvalidateRelcacheByRelid(relationId);
|
||||
}
|
||||
|
||||
|
||||
|
@ -452,10 +452,6 @@ DeleteShardRow(uint64 shardId)
|
|||
HeapTuple heapTuple = NULL;
|
||||
Form_pg_dist_shard pgDistShardForm = NULL;
|
||||
Oid distributedRelationId = InvalidOid;
|
||||
HeapTuple relationOidTuple = NULL;
|
||||
TupleDesc tupleDescriptor = NULL;
|
||||
Datum tupleValues[1] = { (Datum) NULL };
|
||||
bool tupleNulls[1] = { false };
|
||||
|
||||
pgDistShard = heap_open(DistShardRelationId(), RowExclusiveLock);
|
||||
|
||||
|
@ -482,17 +478,8 @@ DeleteShardRow(uint64 shardId)
|
|||
systable_endscan(scanDescriptor);
|
||||
heap_close(pgDistShard, RowExclusiveLock);
|
||||
|
||||
/*
|
||||
* Invalidate using a heap tuple containing the relation OID. We avoid calling
|
||||
* CacheInvalidateRelcacheByRelid here, since that throw an error if the table
|
||||
* is no longer in the catalog, which is the case when calling this function
|
||||
* from a DROP TABLE trigger.
|
||||
*/
|
||||
tupleDescriptor = CreateTemplateTupleDesc(1, true);
|
||||
TupleDescInitEntry(tupleDescriptor, (AttrNumber) 1, "relation", OIDOID, -1, 0);
|
||||
tupleValues[0] = ObjectIdGetDatum(distributedRelationId);
|
||||
relationOidTuple = heap_form_tuple(tupleDescriptor, tupleValues, tupleNulls);
|
||||
CacheInvalidateRelcacheByTuple(relationOidTuple);
|
||||
/* invalidate previous cache entry */
|
||||
CitusInvalidateRelcacheByRelid(distributedRelationId);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -484,26 +484,12 @@ master_dist_partition_cache_invalidate(PG_FUNCTION_ARGS)
|
|||
if (oldLogicalRelationId != InvalidOid &&
|
||||
oldLogicalRelationId != newLogicalRelationId)
|
||||
{
|
||||
HeapTuple oldClassTuple =
|
||||
SearchSysCache1(RELOID, ObjectIdGetDatum(oldLogicalRelationId));
|
||||
|
||||
if (HeapTupleIsValid(oldClassTuple))
|
||||
{
|
||||
CacheInvalidateRelcacheByTuple(oldClassTuple);
|
||||
ReleaseSysCache(oldClassTuple);
|
||||
}
|
||||
CitusInvalidateRelcacheByRelid(oldLogicalRelationId);
|
||||
}
|
||||
|
||||
if (newLogicalRelationId != InvalidOid)
|
||||
{
|
||||
HeapTuple newClassTuple =
|
||||
SearchSysCache1(RELOID, ObjectIdGetDatum(newLogicalRelationId));
|
||||
|
||||
if (HeapTupleIsValid(newClassTuple))
|
||||
{
|
||||
CacheInvalidateRelcacheByTuple(newClassTuple);
|
||||
ReleaseSysCache(newClassTuple);
|
||||
}
|
||||
CitusInvalidateRelcacheByRelid(newLogicalRelationId);
|
||||
}
|
||||
|
||||
PG_RETURN_DATUM(PointerGetDatum(NULL));
|
||||
|
@ -558,26 +544,12 @@ master_dist_shard_cache_invalidate(PG_FUNCTION_ARGS)
|
|||
if (oldLogicalRelationId != InvalidOid &&
|
||||
oldLogicalRelationId != newLogicalRelationId)
|
||||
{
|
||||
HeapTuple oldClassTuple =
|
||||
SearchSysCache1(RELOID, ObjectIdGetDatum(oldLogicalRelationId));
|
||||
|
||||
if (HeapTupleIsValid(oldClassTuple))
|
||||
{
|
||||
CacheInvalidateRelcacheByTuple(oldClassTuple);
|
||||
ReleaseSysCache(oldClassTuple);
|
||||
}
|
||||
CitusInvalidateRelcacheByRelid(oldLogicalRelationId);
|
||||
}
|
||||
|
||||
if (newLogicalRelationId != InvalidOid)
|
||||
{
|
||||
HeapTuple newClassTuple =
|
||||
SearchSysCache1(RELOID, ObjectIdGetDatum(newLogicalRelationId));
|
||||
|
||||
if (HeapTupleIsValid(newClassTuple))
|
||||
{
|
||||
CacheInvalidateRelcacheByTuple(newClassTuple);
|
||||
ReleaseSysCache(newClassTuple);
|
||||
}
|
||||
CitusInvalidateRelcacheByRelid(newLogicalRelationId);
|
||||
}
|
||||
|
||||
PG_RETURN_DATUM(PointerGetDatum(NULL));
|
||||
|
@ -927,3 +899,25 @@ CachedRelationLookup(const char *relationName, Oid *cachedOid)
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Register a relcache invalidation for a non-shared relation.
|
||||
*
|
||||
* We ignore the case that there's no corresponding pg_class entry - that
|
||||
* happens if we register a relcache invalidation (e.g. for a
|
||||
* pg_dist_partition deletion) after the relation has been dropped. That's ok,
|
||||
* because in those cases we're guaranteed to already have registered an
|
||||
* invalidation for the target relation.
|
||||
*/
|
||||
void
|
||||
CitusInvalidateRelcacheByRelid(Oid relationId)
|
||||
{
|
||||
HeapTuple classTuple = SearchSysCache1(RELOID, ObjectIdGetDatum(relationId));
|
||||
|
||||
if (HeapTupleIsValid(classTuple))
|
||||
{
|
||||
CacheInvalidateRelcacheByTuple(classTuple);
|
||||
ReleaseSysCache(classTuple);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -45,6 +45,7 @@ typedef struct
|
|||
extern bool IsDistributedTable(Oid relationId);
|
||||
extern ShardInterval * LoadShardInterval(uint64 shardId);
|
||||
extern DistTableCacheEntry * DistributedTableCacheEntry(Oid distributedRelationId);
|
||||
extern void CitusInvalidateRelcacheByRelid(Oid relationId);
|
||||
|
||||
extern bool CitusDBHasBeenLoaded(void);
|
||||
|
||||
|
|
Loading…
Reference in New Issue