/* * Permanently drop replication slot identified by the passed in name. */ void ReplicationSlotDropIfExists(const char *name) { bool exists = false; int i; /* * There exists a race condition if multiple callers check the existence of * replication slot at the same time. Then we may incorrectly try to drop * the same slot twice. Currently this is not an issue as this function is * only called once at startup from StartupXLOG. */ LWLockAcquire(ReplicationSlotControlLock, LW_SHARED); for (i = 0; i < max_replication_slots; i++) { ReplicationSlot *s = &ReplicationSlotCtl->replication_slots[i]; if (s->in_use && strcmp(name, NameStr(s->data.name)) == 0) { exists = true; break; } } LWLockRelease(ReplicationSlotControlLock); if (exists) ReplicationSlotDrop(name); }
/* * SQL function for dropping a replication slot. */ Datum pg_drop_replication_slot(PG_FUNCTION_ARGS) { Name name = PG_GETARG_NAME(0); check_permissions(); CheckSlotRequirements(); ReplicationSlotDrop(NameStr(*name)); PG_RETURN_VOID(); }
Datum mm_drop_node(PG_FUNCTION_ARGS) { int nodeId = PG_GETARG_INT32(0); bool dropSlot = PG_GETARG_BOOL(1); if (!BIT_SET(dtm->disabledNodeMask, nodeId-1)) { if (nodeId <= 0 || nodeId > dtm->nNodes) { elog(ERROR, "NodeID %d is out of range [1,%d]", nodeId, dtm->nNodes); } dtm->disabledNodeMask |= ((int64)1 << (nodeId-1)); dtm->nNodes -= 1; if (!IsTransactionBlock()) { MMBroadcastUtilityStmt(psprintf("select mm_drop_node(%d,%s)", nodeId, dropSlot ? "true" : "false"), true); } if (dropSlot) { ReplicationSlotDrop(psprintf("mm_slot_%d", nodeId)); } } PG_RETURN_VOID(); }