mirror of
				https://github.com/postgres/postgres.git
				synced 2025-10-29 22:49:41 +03:00 
			
		
		
		
	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 - seeb319356f0eandfe702a7b3finter alia. Author: Amit Kapila Reviewed-by: Alexander Korotkov, Robert Haas
This commit is contained in:
		| @@ -97,6 +97,7 @@ ReplicationSlot *MyReplicationSlot = NULL; | |||||||
| int			max_replication_slots = 0;	/* the maximum number of replication | int			max_replication_slots = 0;	/* the maximum number of replication | ||||||
| 										 * slots */ | 										 * slots */ | ||||||
|  |  | ||||||
|  | static LWLockTranche ReplSlotIOLWLockTranche; | ||||||
| static void ReplicationSlotDropAcquired(void); | static void ReplicationSlotDropAcquired(void); | ||||||
|  |  | ||||||
| /* internal persistency functions */ | /* internal persistency functions */ | ||||||
| @@ -137,6 +138,13 @@ ReplicationSlotsShmemInit(void) | |||||||
| 		ShmemInitStruct("ReplicationSlot Ctl", ReplicationSlotsShmemSize(), | 		ShmemInitStruct("ReplicationSlot Ctl", ReplicationSlotsShmemSize(), | ||||||
| 						&found); | 						&found); | ||||||
|  |  | ||||||
|  | 	ReplSlotIOLWLockTranche.name = "Replication Slot IO Locks"; | ||||||
|  | 	ReplSlotIOLWLockTranche.array_base = | ||||||
|  | 		((char *) ReplicationSlotCtl) + offsetof(ReplicationSlotCtlData, replication_slots) +offsetof(ReplicationSlot, io_in_progress_lock); | ||||||
|  | 	ReplSlotIOLWLockTranche.array_stride = sizeof(ReplicationSlot); | ||||||
|  | 	LWLockRegisterTranche(LWTRANCHE_REPLICATION_SLOT_IO_IN_PROGRESS, | ||||||
|  | 						  &ReplSlotIOLWLockTranche); | ||||||
|  |  | ||||||
| 	if (!found) | 	if (!found) | ||||||
| 	{ | 	{ | ||||||
| 		int			i; | 		int			i; | ||||||
| @@ -150,7 +158,7 @@ ReplicationSlotsShmemInit(void) | |||||||
|  |  | ||||||
| 			/* everything else is zeroed by the memset above */ | 			/* everything else is zeroed by the memset above */ | ||||||
| 			SpinLockInit(&slot->mutex); | 			SpinLockInit(&slot->mutex); | ||||||
| 			slot->io_in_progress_lock = LWLockAssign(); | 			LWLockInitialize(&slot->io_in_progress_lock, LWTRANCHE_REPLICATION_SLOT_IO_IN_PROGRESS); | ||||||
| 		} | 		} | ||||||
| 	} | 	} | ||||||
| } | } | ||||||
| @@ -1008,7 +1016,7 @@ SaveSlotToPath(ReplicationSlot *slot, const char *dir, int elevel) | |||||||
| 	if (!was_dirty) | 	if (!was_dirty) | ||||||
| 		return; | 		return; | ||||||
|  |  | ||||||
| 	LWLockAcquire(slot->io_in_progress_lock, LW_EXCLUSIVE); | 	LWLockAcquire(&slot->io_in_progress_lock, LW_EXCLUSIVE); | ||||||
|  |  | ||||||
| 	/* silence valgrind :( */ | 	/* silence valgrind :( */ | ||||||
| 	memset(&cp, 0, sizeof(ReplicationSlotOnDisk)); | 	memset(&cp, 0, sizeof(ReplicationSlotOnDisk)); | ||||||
| @@ -1101,7 +1109,7 @@ SaveSlotToPath(ReplicationSlot *slot, const char *dir, int elevel) | |||||||
| 		slot->dirty = false; | 		slot->dirty = false; | ||||||
| 	SpinLockRelease(&slot->mutex); | 	SpinLockRelease(&slot->mutex); | ||||||
|  |  | ||||||
| 	LWLockRelease(slot->io_in_progress_lock); | 	LWLockRelease(&slot->io_in_progress_lock); | ||||||
| } | } | ||||||
|  |  | ||||||
| /* | /* | ||||||
|   | |||||||
| @@ -353,9 +353,6 @@ NumLWLocks(void) | |||||||
| 	/* Predefined LWLocks */ | 	/* Predefined LWLocks */ | ||||||
| 	numLocks = NUM_FIXED_LWLOCKS; | 	numLocks = NUM_FIXED_LWLOCKS; | ||||||
|  |  | ||||||
| 	/* slot.c needs one for each slot */ |  | ||||||
| 	numLocks += max_replication_slots; |  | ||||||
|  |  | ||||||
| 	/* | 	/* | ||||||
| 	 * Add any requested by loadable modules; for backwards-compatibility | 	 * Add any requested by loadable modules; for backwards-compatibility | ||||||
| 	 * reasons, allocate at least NUM_USER_DEFINED_LWLOCKS of them even if | 	 * reasons, allocate at least NUM_USER_DEFINED_LWLOCKS of them even if | ||||||
|   | |||||||
| @@ -109,7 +109,7 @@ typedef struct ReplicationSlot | |||||||
| 	ReplicationSlotPersistentData data; | 	ReplicationSlotPersistentData data; | ||||||
|  |  | ||||||
| 	/* is somebody performing io on this slot? */ | 	/* is somebody performing io on this slot? */ | ||||||
| 	LWLock	   *io_in_progress_lock; | 	LWLock		io_in_progress_lock; | ||||||
|  |  | ||||||
| 	/* all the remaining data is only used for logical slots */ | 	/* all the remaining data is only used for logical slots */ | ||||||
|  |  | ||||||
|   | |||||||
| @@ -213,6 +213,7 @@ typedef enum BuiltinTrancheIds | |||||||
| 	LWTRANCHE_WAL_INSERT, | 	LWTRANCHE_WAL_INSERT, | ||||||
| 	LWTRANCHE_BUFFER_CONTENT, | 	LWTRANCHE_BUFFER_CONTENT, | ||||||
| 	LWTRANCHE_BUFFER_IO_IN_PROGRESS, | 	LWTRANCHE_BUFFER_IO_IN_PROGRESS, | ||||||
|  | 	LWTRANCHE_REPLICATION_SLOT_IO_IN_PROGRESS, | ||||||
| 	LWTRANCHE_PROC, | 	LWTRANCHE_PROC, | ||||||
| 	LWTRANCHE_FIRST_USER_DEFINED | 	LWTRANCHE_FIRST_USER_DEFINED | ||||||
| }	BuiltinTrancheIds; | }	BuiltinTrancheIds; | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user