Migrate replication slot I/O locks into a separate tranche.
authorRobert Haas <rhaas@postgresql.org>
Fri, 29 Jan 2016 14:44:29 +0000 (09:44 -0500)
committerRobert Haas <rhaas@postgresql.org>
Fri, 29 Jan 2016 14:45:38 +0000 (09:45 -0500)
This is following in a long train of similar changes and for the same
reasons - see b319356f0e94a6482c726cf4af96597c211d8d6e and
fe702a7b3f9f2bc5bf6d173166d7d55226af82c8 inter alia.

Author: Amit Kapila
Reviewed-by: Alexander Korotkov, Robert Haas
src/backend/replication/slot.c
src/backend/storage/lmgr/lwlock.c
src/include/replication/slot.h
src/include/storage/lwlock.h

index c12e41286657fbd51ad86c250f4621ca580efb2b..251b549768dc3484f9da2083dd0f7fe3f069dea0 100644 (file)
@@ -97,6 +97,7 @@ ReplicationSlot *MyReplicationSlot = NULL;
 int            max_replication_slots = 0;  /* the maximum number of replication
                                         * slots */
 
+static LWLockTranche ReplSlotIOLWLockTranche;
 static void ReplicationSlotDropAcquired(void);
 
 /* internal persistency functions */
@@ -137,6 +138,13 @@ ReplicationSlotsShmemInit(void)
        ShmemInitStruct("ReplicationSlot Ctl", ReplicationSlotsShmemSize(),
                        &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)
    {
        int         i;
@@ -150,7 +158,7 @@ ReplicationSlotsShmemInit(void)
 
            /* everything else is zeroed by the memset above */
            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)
        return;
 
-   LWLockAcquire(slot->io_in_progress_lock, LW_EXCLUSIVE);
+   LWLockAcquire(&slot->io_in_progress_lock, LW_EXCLUSIVE);
 
    /* silence valgrind :( */
    memset(&cp, 0, sizeof(ReplicationSlotOnDisk));
@@ -1101,7 +1109,7 @@ SaveSlotToPath(ReplicationSlot *slot, const char *dir, int elevel)
        slot->dirty = false;
    SpinLockRelease(&slot->mutex);
 
-   LWLockRelease(slot->io_in_progress_lock);
+   LWLockRelease(&slot->io_in_progress_lock);
 }
 
 /*
index 5e276a08da3f859622fa522c4c8269795d70aad4..d087139c2864796473fa86dae37a558ea688b4b4 100644 (file)
@@ -353,9 +353,6 @@ NumLWLocks(void)
    /* Predefined 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
     * reasons, allocate at least NUM_USER_DEFINED_LWLOCKS of them even if
index 80ad02aba030922ae647606665875f4bb65894f4..8be8ab62a0f573e57280304f73a277a13bf7256b 100644 (file)
@@ -109,7 +109,7 @@ typedef struct ReplicationSlot
    ReplicationSlotPersistentData data;
 
    /* 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 */
 
index 3f1da5155ef14987e73a8def9747c8b8e1e5c728..9e4f512e2c816b27a6aede3828c17f8962fe48f1 100644 (file)
@@ -213,6 +213,7 @@ typedef enum BuiltinTrancheIds
    LWTRANCHE_WAL_INSERT,
    LWTRANCHE_BUFFER_CONTENT,
    LWTRANCHE_BUFFER_IO_IN_PROGRESS,
+   LWTRANCHE_REPLICATION_SLOT_IO_IN_PROGRESS,
    LWTRANCHE_PROC,
    LWTRANCHE_FIRST_USER_DEFINED
 }  BuiltinTrancheIds;