Skip to content

Commit cc8cdd3

Browse files
committed
Make it possible to drop replciation slots
1 parent 828874b commit cc8cdd3

File tree

3 files changed

+18
-8
lines changed

3 files changed

+18
-8
lines changed

contrib/multimaster/multimaster--1.0.sql

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ CREATE FUNCTION mm_stop_replication() RETURNS void
99
AS 'MODULE_PATHNAME','mm_stop_replication'
1010
LANGUAGE C;
1111

12-
CREATE FUNCTION mm_disable_node(node integer) RETURNS void
13-
AS 'MODULE_PATHNAME','mm_disable_node'
12+
CREATE FUNCTION mm_drop_node(node integer, drop_slot bool default false) RETURNS void
13+
AS 'MODULE_PATHNAME','mm_drop_node'
1414
LANGUAGE C;
1515

contrib/multimaster/multimaster.c

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
#include "storage/proc.h"
4545
#include "utils/syscache.h"
4646
#include "replication/walsender.h"
47+
#include "replication/slot.h"
4748
#include "port/atomics.h"
4849
#include "tcop/utility.h"
4950
#include "sockhub/sockhub.h"
@@ -84,7 +85,7 @@ PG_MODULE_MAGIC;
8485

8586
PG_FUNCTION_INFO_V1(mm_start_replication);
8687
PG_FUNCTION_INFO_V1(mm_stop_replication);
87-
PG_FUNCTION_INFO_V1(mm_disable_node);
88+
PG_FUNCTION_INFO_V1(mm_drop_node);
8889

8990
static Snapshot DtmGetSnapshot(Snapshot snapshot);
9091
static void DtmMergeWithGlobalSnapshot(Snapshot snapshot);
@@ -1216,17 +1217,26 @@ mm_stop_replication(PG_FUNCTION_ARGS)
12161217
}
12171218

12181219
Datum
1219-
mm_disable_node(PG_FUNCTION_ARGS)
1220+
mm_drop_node(PG_FUNCTION_ARGS)
12201221
{
12211222
int nodeId = PG_GETARG_INT32(0);
1222-
if (!BIT_SET(dtm->disabledNodeMask, nodeId))
1223+
bool dropSlot = PG_GETARG_BOOL(1);
1224+
if (!BIT_SET(dtm->disabledNodeMask, nodeId-1))
12231225
{
1224-
dtm->disabledNodeMask |= ((int64)1 << nodeId);
1226+
if (nodeId <= 0 || nodeId > dtm->nNodes)
1227+
{
1228+
elog(ERROR, "NodeID %d is out of range [1,%d]", nodeId, dtm->nNodes);
1229+
}
1230+
dtm->disabledNodeMask |= ((int64)1 << (nodeId-1));
12251231
dtm->nNodes -= 1;
12261232
if (!IsTransactionBlock())
12271233
{
1228-
MMBroadcastUtilityStmt(psprintf("select mm_disable_node(%d)", nodeId), true);
1234+
MMBroadcastUtilityStmt(psprintf("select mm_drop_node(%d,%s)", nodeId, dropSlot ? "true" : "false"), true);
12291235
}
1236+
if (dropSlot)
1237+
{
1238+
ReplicationSlotDrop(psprintf("mm_slot_%d", nodeId));
1239+
}
12301240
}
12311241
PG_RETURN_VOID();
12321242
}

contrib/pg_dtm/pg_dtm.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ static TransactionManager DtmTM = {
118118
DtmGetGlobalTransactionId,
119119
PgXidInMVCCSnapshot,
120120
DtmDetectGlobalDeadLock,
121-
GtmGetName
121+
DtmGetName
122122
};
123123

124124
static char *DtmServers;

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy