Skip to content

Commit 2251179

Browse files
committed
Migrate replication slot I/O locks into a separate tranche.
This is following in a long train of similar changes and for the same reasons - see b319356 and fe702a7 inter alia. Author: Amit Kapila Reviewed-by: Alexander Korotkov, Robert Haas
1 parent b319356 commit 2251179

File tree

4 files changed

+13
-7
lines changed

4 files changed

+13
-7
lines changed

src/backend/replication/slot.c

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ ReplicationSlot *MyReplicationSlot = NULL;
9797
int max_replication_slots = 0; /* the maximum number of replication
9898
* slots */
9999

100+
static LWLockTranche ReplSlotIOLWLockTranche;
100101
static void ReplicationSlotDropAcquired(void);
101102

102103
/* internal persistency functions */
@@ -137,6 +138,13 @@ ReplicationSlotsShmemInit(void)
137138
ShmemInitStruct("ReplicationSlot Ctl", ReplicationSlotsShmemSize(),
138139
&found);
139140

141+
ReplSlotIOLWLockTranche.name = "Replication Slot IO Locks";
142+
ReplSlotIOLWLockTranche.array_base =
143+
((char *) ReplicationSlotCtl) + offsetof(ReplicationSlotCtlData, replication_slots) +offsetof(ReplicationSlot, io_in_progress_lock);
144+
ReplSlotIOLWLockTranche.array_stride = sizeof(ReplicationSlot);
145+
LWLockRegisterTranche(LWTRANCHE_REPLICATION_SLOT_IO_IN_PROGRESS,
146+
&ReplSlotIOLWLockTranche);
147+
140148
if (!found)
141149
{
142150
int i;
@@ -150,7 +158,7 @@ ReplicationSlotsShmemInit(void)
150158

151159
/* everything else is zeroed by the memset above */
152160
SpinLockInit(&slot->mutex);
153-
slot->io_in_progress_lock = LWLockAssign();
161+
LWLockInitialize(&slot->io_in_progress_lock, LWTRANCHE_REPLICATION_SLOT_IO_IN_PROGRESS);
154162
}
155163
}
156164
}
@@ -1008,7 +1016,7 @@ SaveSlotToPath(ReplicationSlot *slot, const char *dir, int elevel)
10081016
if (!was_dirty)
10091017
return;
10101018

1011-
LWLockAcquire(slot->io_in_progress_lock, LW_EXCLUSIVE);
1019+
LWLockAcquire(&slot->io_in_progress_lock, LW_EXCLUSIVE);
10121020

10131021
/* silence valgrind :( */
10141022
memset(&cp, 0, sizeof(ReplicationSlotOnDisk));
@@ -1101,7 +1109,7 @@ SaveSlotToPath(ReplicationSlot *slot, const char *dir, int elevel)
11011109
slot->dirty = false;
11021110
SpinLockRelease(&slot->mutex);
11031111

1104-
LWLockRelease(slot->io_in_progress_lock);
1112+
LWLockRelease(&slot->io_in_progress_lock);
11051113
}
11061114

11071115
/*

src/backend/storage/lmgr/lwlock.c

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -353,9 +353,6 @@ NumLWLocks(void)
353353
/* Predefined LWLocks */
354354
numLocks = NUM_FIXED_LWLOCKS;
355355

356-
/* slot.c needs one for each slot */
357-
numLocks += max_replication_slots;
358-
359356
/*
360357
* Add any requested by loadable modules; for backwards-compatibility
361358
* reasons, allocate at least NUM_USER_DEFINED_LWLOCKS of them even if

src/include/replication/slot.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ typedef struct ReplicationSlot
109109
ReplicationSlotPersistentData data;
110110

111111
/* is somebody performing io on this slot? */
112-
LWLock *io_in_progress_lock;
112+
LWLock io_in_progress_lock;
113113

114114
/* all the remaining data is only used for logical slots */
115115

src/include/storage/lwlock.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,7 @@ typedef enum BuiltinTrancheIds
213213
LWTRANCHE_WAL_INSERT,
214214
LWTRANCHE_BUFFER_CONTENT,
215215
LWTRANCHE_BUFFER_IO_IN_PROGRESS,
216+
LWTRANCHE_REPLICATION_SLOT_IO_IN_PROGRESS,
216217
LWTRANCHE_PROC,
217218
LWTRANCHE_FIRST_USER_DEFINED
218219
} BuiltinTrancheIds;

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