mirror of https://github.com/citusdata/citus.git
Clarify resource-cleaner apis (#7518)
Rename InsertCleanupRecordInCurrentTransaction -> InsertCleanupOnSuccessRecordInCurrentTransaction and hardcode policy type as CLEANUP_DEFERRED_ON_SUCCESS. Rename InsertCleanupRecordInSubtransaction -> InsertCleanupRecordOutsideTransaction.grant_database_2pc_onur_1
parent
71ccbcf3e2
commit
56e014e64e
|
@ -426,10 +426,9 @@ ExecuteDropShardPlacementCommandRemotely(ShardPlacement *shardPlacement,
|
||||||
errdetail("Marking this shard placement for "
|
errdetail("Marking this shard placement for "
|
||||||
"deletion")));
|
"deletion")));
|
||||||
|
|
||||||
InsertCleanupRecordInCurrentTransaction(CLEANUP_OBJECT_SHARD_PLACEMENT,
|
InsertCleanupOnSuccessRecordInCurrentTransaction(CLEANUP_OBJECT_SHARD_PLACEMENT,
|
||||||
shardRelationName,
|
shardRelationName,
|
||||||
shardPlacement->groupId,
|
shardPlacement->groupId);
|
||||||
CLEANUP_DEFERRED_ON_SUCCESS);
|
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
@ -452,15 +452,15 @@ CompareCleanupRecordsByObjectType(const void *leftElement, const void *rightElem
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* InsertCleanupRecordInCurrentTransaction inserts a new pg_dist_cleanup entry
|
* InsertCleanupOnSuccessRecordInCurrentTransaction inserts a new pg_dist_cleanup entry
|
||||||
* as part of the current transaction. This is primarily useful for deferred drop scenarios,
|
* as part of the current transaction. This is primarily useful for deferred drop scenarios,
|
||||||
* since these records would roll back in case of operation failure.
|
* since these records would roll back in case of operation failure. And for the same reason,
|
||||||
|
* always sets the policy type to CLEANUP_DEFERRED_ON_SUCCESS.
|
||||||
*/
|
*/
|
||||||
void
|
void
|
||||||
InsertCleanupRecordInCurrentTransaction(CleanupObject objectType,
|
InsertCleanupOnSuccessRecordInCurrentTransaction(CleanupObject objectType,
|
||||||
char *objectName,
|
char *objectName,
|
||||||
int nodeGroupId,
|
int nodeGroupId)
|
||||||
CleanupPolicy policy)
|
|
||||||
{
|
{
|
||||||
/* We must have a valid OperationId. Any operation requring cleanup
|
/* We must have a valid OperationId. Any operation requring cleanup
|
||||||
* will call RegisterOperationNeedingCleanup.
|
* will call RegisterOperationNeedingCleanup.
|
||||||
|
@ -482,7 +482,8 @@ InsertCleanupRecordInCurrentTransaction(CleanupObject objectType,
|
||||||
values[Anum_pg_dist_cleanup_object_type - 1] = Int32GetDatum(objectType);
|
values[Anum_pg_dist_cleanup_object_type - 1] = Int32GetDatum(objectType);
|
||||||
values[Anum_pg_dist_cleanup_object_name - 1] = CStringGetTextDatum(objectName);
|
values[Anum_pg_dist_cleanup_object_name - 1] = CStringGetTextDatum(objectName);
|
||||||
values[Anum_pg_dist_cleanup_node_group_id - 1] = Int32GetDatum(nodeGroupId);
|
values[Anum_pg_dist_cleanup_node_group_id - 1] = Int32GetDatum(nodeGroupId);
|
||||||
values[Anum_pg_dist_cleanup_policy_type - 1] = Int32GetDatum(policy);
|
values[Anum_pg_dist_cleanup_policy_type - 1] =
|
||||||
|
Int32GetDatum(CLEANUP_DEFERRED_ON_SUCCESS);
|
||||||
|
|
||||||
/* open cleanup relation and insert new tuple */
|
/* open cleanup relation and insert new tuple */
|
||||||
Oid relationId = DistCleanupRelationId();
|
Oid relationId = DistCleanupRelationId();
|
||||||
|
@ -499,14 +500,15 @@ InsertCleanupRecordInCurrentTransaction(CleanupObject objectType,
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* InsertCleanupRecordInSubtransaction inserts a new pg_dist_cleanup entry in a
|
* InsertCleanupRecordOutsideTransaction inserts a new pg_dist_cleanup entry in a
|
||||||
* separate transaction to ensure the record persists after rollback. We should
|
* separate transaction to ensure the record persists after rollback. We should
|
||||||
* delete these records if the operation completes successfully.
|
* delete these records if the operation completes successfully.
|
||||||
*
|
*
|
||||||
* For failure scenarios, use a subtransaction (direct insert via localhost).
|
* This is used in scenarios where we need to cleanup resources on operation
|
||||||
|
* completion (CLEANUP_ALWAYS) or on failure (CLEANUP_ON_FAILURE).
|
||||||
*/
|
*/
|
||||||
void
|
void
|
||||||
InsertCleanupRecordInSubtransaction(CleanupObject objectType,
|
InsertCleanupRecordOutsideTransaction(CleanupObject objectType,
|
||||||
char *objectName,
|
char *objectName,
|
||||||
int nodeGroupId,
|
int nodeGroupId,
|
||||||
CleanupPolicy policy)
|
CleanupPolicy policy)
|
||||||
|
@ -516,6 +518,9 @@ InsertCleanupRecordInSubtransaction(CleanupObject objectType,
|
||||||
*/
|
*/
|
||||||
Assert(CurrentOperationId != INVALID_OPERATION_ID);
|
Assert(CurrentOperationId != INVALID_OPERATION_ID);
|
||||||
|
|
||||||
|
/* assert the circumstance noted in function comment */
|
||||||
|
Assert(policy == CLEANUP_ALWAYS || policy == CLEANUP_ON_FAILURE);
|
||||||
|
|
||||||
StringInfo sequenceName = makeStringInfo();
|
StringInfo sequenceName = makeStringInfo();
|
||||||
appendStringInfo(sequenceName, "%s.%s",
|
appendStringInfo(sequenceName, "%s.%s",
|
||||||
PG_CATALOG,
|
PG_CATALOG,
|
||||||
|
|
|
@ -733,7 +733,7 @@ CreateSplitShardsForShardGroup(List *shardGroupSplitIntervalListList,
|
||||||
workerPlacementNode->workerPort)));
|
workerPlacementNode->workerPort)));
|
||||||
}
|
}
|
||||||
|
|
||||||
InsertCleanupRecordInSubtransaction(CLEANUP_OBJECT_SHARD_PLACEMENT,
|
InsertCleanupRecordOutsideTransaction(CLEANUP_OBJECT_SHARD_PLACEMENT,
|
||||||
ConstructQualifiedShardName(
|
ConstructQualifiedShardName(
|
||||||
shardInterval),
|
shardInterval),
|
||||||
workerPlacementNode->groupId,
|
workerPlacementNode->groupId,
|
||||||
|
@ -1717,7 +1717,7 @@ CreateDummyShardsForShardGroup(HTAB *mapOfPlacementToDummyShardList,
|
||||||
/* Log shard in pg_dist_cleanup. Given dummy shards are transient resources,
|
/* Log shard in pg_dist_cleanup. Given dummy shards are transient resources,
|
||||||
* we want to cleanup irrespective of operation success or failure.
|
* we want to cleanup irrespective of operation success or failure.
|
||||||
*/
|
*/
|
||||||
InsertCleanupRecordInSubtransaction(CLEANUP_OBJECT_SHARD_PLACEMENT,
|
InsertCleanupRecordOutsideTransaction(CLEANUP_OBJECT_SHARD_PLACEMENT,
|
||||||
ConstructQualifiedShardName(
|
ConstructQualifiedShardName(
|
||||||
shardInterval),
|
shardInterval),
|
||||||
workerPlacementNode->groupId,
|
workerPlacementNode->groupId,
|
||||||
|
@ -1780,7 +1780,7 @@ CreateDummyShardsForShardGroup(HTAB *mapOfPlacementToDummyShardList,
|
||||||
/* Log shard in pg_dist_cleanup. Given dummy shards are transient resources,
|
/* Log shard in pg_dist_cleanup. Given dummy shards are transient resources,
|
||||||
* we want to cleanup irrespective of operation success or failure.
|
* we want to cleanup irrespective of operation success or failure.
|
||||||
*/
|
*/
|
||||||
InsertCleanupRecordInSubtransaction(CLEANUP_OBJECT_SHARD_PLACEMENT,
|
InsertCleanupRecordOutsideTransaction(CLEANUP_OBJECT_SHARD_PLACEMENT,
|
||||||
ConstructQualifiedShardName(
|
ConstructQualifiedShardName(
|
||||||
shardInterval),
|
shardInterval),
|
||||||
sourceWorkerNode->groupId,
|
sourceWorkerNode->groupId,
|
||||||
|
|
|
@ -604,10 +604,10 @@ InsertDeferredDropCleanupRecordsForShards(List *shardIntervalList)
|
||||||
* We also log cleanup record in the current transaction. If the current transaction rolls back,
|
* We also log cleanup record in the current transaction. If the current transaction rolls back,
|
||||||
* we do not generate a record at all.
|
* we do not generate a record at all.
|
||||||
*/
|
*/
|
||||||
InsertCleanupRecordInCurrentTransaction(CLEANUP_OBJECT_SHARD_PLACEMENT,
|
InsertCleanupOnSuccessRecordInCurrentTransaction(
|
||||||
|
CLEANUP_OBJECT_SHARD_PLACEMENT,
|
||||||
qualifiedShardName,
|
qualifiedShardName,
|
||||||
placement->groupId,
|
placement->groupId);
|
||||||
CLEANUP_DEFERRED_ON_SUCCESS);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -634,10 +634,9 @@ InsertCleanupRecordsForShardPlacementsOnNode(List *shardIntervalList,
|
||||||
* We also log cleanup record in the current transaction. If the current transaction rolls back,
|
* We also log cleanup record in the current transaction. If the current transaction rolls back,
|
||||||
* we do not generate a record at all.
|
* we do not generate a record at all.
|
||||||
*/
|
*/
|
||||||
InsertCleanupRecordInCurrentTransaction(CLEANUP_OBJECT_SHARD_PLACEMENT,
|
InsertCleanupOnSuccessRecordInCurrentTransaction(CLEANUP_OBJECT_SHARD_PLACEMENT,
|
||||||
qualifiedShardName,
|
qualifiedShardName,
|
||||||
groupId,
|
groupId);
|
||||||
CLEANUP_DEFERRED_ON_SUCCESS);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1393,9 +1392,10 @@ CopyShardTablesViaLogicalReplication(List *shardIntervalList, char *sourceNodeNa
|
||||||
char *tableOwner = TableOwner(shardInterval->relationId);
|
char *tableOwner = TableOwner(shardInterval->relationId);
|
||||||
|
|
||||||
/* drop the shard we created on the target, in case of failure */
|
/* drop the shard we created on the target, in case of failure */
|
||||||
InsertCleanupRecordInSubtransaction(CLEANUP_OBJECT_SHARD_PLACEMENT,
|
InsertCleanupRecordOutsideTransaction(CLEANUP_OBJECT_SHARD_PLACEMENT,
|
||||||
ConstructQualifiedShardName(shardInterval),
|
ConstructQualifiedShardName(shardInterval),
|
||||||
GroupForNode(targetNodeName, targetNodePort),
|
GroupForNode(targetNodeName,
|
||||||
|
targetNodePort),
|
||||||
CLEANUP_ON_FAILURE);
|
CLEANUP_ON_FAILURE);
|
||||||
|
|
||||||
SendCommandListToWorkerOutsideTransaction(targetNodeName, targetNodePort,
|
SendCommandListToWorkerOutsideTransaction(targetNodeName, targetNodePort,
|
||||||
|
@ -1466,9 +1466,10 @@ CopyShardTablesViaBlockWrites(List *shardIntervalList, char *sourceNodeName,
|
||||||
char *tableOwner = TableOwner(shardInterval->relationId);
|
char *tableOwner = TableOwner(shardInterval->relationId);
|
||||||
|
|
||||||
/* drop the shard we created on the target, in case of failure */
|
/* drop the shard we created on the target, in case of failure */
|
||||||
InsertCleanupRecordInSubtransaction(CLEANUP_OBJECT_SHARD_PLACEMENT,
|
InsertCleanupRecordOutsideTransaction(CLEANUP_OBJECT_SHARD_PLACEMENT,
|
||||||
ConstructQualifiedShardName(shardInterval),
|
ConstructQualifiedShardName(shardInterval),
|
||||||
GroupForNode(targetNodeName, targetNodePort),
|
GroupForNode(targetNodeName,
|
||||||
|
targetNodePort),
|
||||||
CLEANUP_ON_FAILURE);
|
CLEANUP_ON_FAILURE);
|
||||||
|
|
||||||
SendCommandListToWorkerOutsideTransaction(targetNodeName, targetNodePort,
|
SendCommandListToWorkerOutsideTransaction(targetNodeName, targetNodePort,
|
||||||
|
|
|
@ -1335,7 +1335,7 @@ CreatePublications(MultiConnection *connection,
|
||||||
|
|
||||||
WorkerNode *worker = FindWorkerNode(connection->hostname,
|
WorkerNode *worker = FindWorkerNode(connection->hostname,
|
||||||
connection->port);
|
connection->port);
|
||||||
InsertCleanupRecordInSubtransaction(CLEANUP_OBJECT_PUBLICATION,
|
InsertCleanupRecordOutsideTransaction(CLEANUP_OBJECT_PUBLICATION,
|
||||||
entry->name,
|
entry->name,
|
||||||
worker->groupId,
|
worker->groupId,
|
||||||
CLEANUP_ALWAYS);
|
CLEANUP_ALWAYS);
|
||||||
|
@ -1435,7 +1435,7 @@ CreateReplicationSlots(MultiConnection *sourceConnection,
|
||||||
|
|
||||||
WorkerNode *worker = FindWorkerNode(sourceConnection->hostname,
|
WorkerNode *worker = FindWorkerNode(sourceConnection->hostname,
|
||||||
sourceConnection->port);
|
sourceConnection->port);
|
||||||
InsertCleanupRecordInSubtransaction(CLEANUP_OBJECT_REPLICATION_SLOT,
|
InsertCleanupRecordOutsideTransaction(CLEANUP_OBJECT_REPLICATION_SLOT,
|
||||||
replicationSlot->name,
|
replicationSlot->name,
|
||||||
worker->groupId,
|
worker->groupId,
|
||||||
CLEANUP_ALWAYS);
|
CLEANUP_ALWAYS);
|
||||||
|
@ -1506,7 +1506,7 @@ CreateSubscriptions(MultiConnection *sourceConnection,
|
||||||
quote_identifier(GetUserNameFromId(ownerId, false))
|
quote_identifier(GetUserNameFromId(ownerId, false))
|
||||||
)));
|
)));
|
||||||
|
|
||||||
InsertCleanupRecordInSubtransaction(CLEANUP_OBJECT_USER,
|
InsertCleanupRecordOutsideTransaction(CLEANUP_OBJECT_USER,
|
||||||
target->subscriptionOwnerName,
|
target->subscriptionOwnerName,
|
||||||
worker->groupId,
|
worker->groupId,
|
||||||
CLEANUP_ALWAYS);
|
CLEANUP_ALWAYS);
|
||||||
|
@ -1567,7 +1567,7 @@ CreateSubscriptions(MultiConnection *sourceConnection,
|
||||||
pfree(createSubscriptionCommand->data);
|
pfree(createSubscriptionCommand->data);
|
||||||
pfree(createSubscriptionCommand);
|
pfree(createSubscriptionCommand);
|
||||||
|
|
||||||
InsertCleanupRecordInSubtransaction(CLEANUP_OBJECT_SUBSCRIPTION,
|
InsertCleanupRecordOutsideTransaction(CLEANUP_OBJECT_SUBSCRIPTION,
|
||||||
target->subscriptionName,
|
target->subscriptionName,
|
||||||
worker->groupId,
|
worker->groupId,
|
||||||
CLEANUP_ALWAYS);
|
CLEANUP_ALWAYS);
|
||||||
|
|
|
@ -81,16 +81,16 @@ typedef enum CleanupPolicy
|
||||||
extern OperationId RegisterOperationNeedingCleanup(void);
|
extern OperationId RegisterOperationNeedingCleanup(void);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* InsertCleanupRecordInCurrentTransaction inserts a new pg_dist_cleanup entry
|
* InsertCleanupOnSuccessRecordInCurrentTransaction inserts a new pg_dist_cleanup entry
|
||||||
* as part of the current transaction.
|
* as part of the current transaction.
|
||||||
*
|
*
|
||||||
* This is primarily useful for deferred cleanup (CLEANUP_DEFERRED_ON_SUCCESS)
|
* This is primarily useful for deferred cleanup (CLEANUP_DEFERRED_ON_SUCCESS)
|
||||||
* scenarios, since the records would roll back in case of failure.
|
* scenarios, since the records would roll back in case of failure. And for the
|
||||||
|
* same reason, always sets the policy type to CLEANUP_DEFERRED_ON_SUCCESS.
|
||||||
*/
|
*/
|
||||||
extern void InsertCleanupRecordInCurrentTransaction(CleanupObject objectType,
|
extern void InsertCleanupOnSuccessRecordInCurrentTransaction(CleanupObject objectType,
|
||||||
char *objectName,
|
char *objectName,
|
||||||
int nodeGroupId,
|
int nodeGroupId);
|
||||||
CleanupPolicy policy);
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* InsertCleanupRecordInSeparateTransaction inserts a new pg_dist_cleanup entry
|
* InsertCleanupRecordInSeparateTransaction inserts a new pg_dist_cleanup entry
|
||||||
|
@ -99,7 +99,7 @@ extern void InsertCleanupRecordInCurrentTransaction(CleanupObject objectType,
|
||||||
* This is used in scenarios where we need to cleanup resources on operation
|
* This is used in scenarios where we need to cleanup resources on operation
|
||||||
* completion (CLEANUP_ALWAYS) or on failure (CLEANUP_ON_FAILURE).
|
* completion (CLEANUP_ALWAYS) or on failure (CLEANUP_ON_FAILURE).
|
||||||
*/
|
*/
|
||||||
extern void InsertCleanupRecordInSubtransaction(CleanupObject objectType,
|
extern void InsertCleanupRecordOutsideTransaction(CleanupObject objectType,
|
||||||
char *objectName,
|
char *objectName,
|
||||||
int nodeGroupId,
|
int nodeGroupId,
|
||||||
CleanupPolicy policy);
|
CleanupPolicy policy);
|
||||||
|
|
Loading…
Reference in New Issue