SaveSlotToPath(MyReplicationSlot, path);
}
+/*
+ * Signal that it would be useful if the currently acquired slot would be
+ * flushed out to disk.
+ *
+ * Note that the actual flush to disk can be delayed for a long time, if
+ * required for correctness explicitly do a ReplicationSlotSave().
+ */
+void
+ReplicationSlotMarkDirty(void)
+{
+ Assert(MyReplicationSlot != NULL);
+
+ {
+ volatile ReplicationSlot *vslot = MyReplicationSlot;
+
+ SpinLockAcquire(&vslot->mutex);
+ MyReplicationSlot->just_dirtied = true;
+ MyReplicationSlot->dirty = true;
+ SpinLockRelease(&vslot->mutex);
+ }
+}
+
/*
* Compute the oldest xmin across all slots and store it in the ProcArray.
*/
fsync_fname(tmppath, true);
+ slot->dirty = true; /* signal that we really need to write */
SaveSlotToPath(slot, tmppath);
if (rename(tmppath, path) != 0)
char path[MAXPGPATH];
int fd;
ReplicationSlotOnDisk cp;
+ bool was_dirty;
+
+ /* first check whether there's something to write out */
+ {
+ volatile ReplicationSlot *vslot = slot;
+
+ SpinLockAcquire(&vslot->mutex);
+ was_dirty = vslot->dirty;
+ vslot->just_dirtied = false;
+ SpinLockRelease(&vslot->mutex);
+ }
+
+ if (!was_dirty)
+ return;
LWLockAcquire(slot->io_in_progress_lock, LW_EXCLUSIVE);
END_CRIT_SECTION();
+ /*
+ * Successfully wrote, unset dirty bit, unless somebody dirtied again
+ * already.
+ */
+ {
+ volatile ReplicationSlot *vslot = slot;
+
+ SpinLockAcquire(&vslot->mutex);
+ if (!vslot->just_dirtied)
+ vslot->dirty = false;
+ SpinLockRelease(&vslot->mutex);
+ }
+
LWLockRelease(slot->io_in_progress_lock);
}
SpinLockRelease(&slot->mutex);
if (changed)
+ {
+ ReplicationSlotMarkDirty();
ReplicationSlotsComputeRequiredLSN();
+ }
/*
* One could argue that the slot should saved to disk now, but that'd be
if (changed)
{
- ReplicationSlotSave();
+ ReplicationSlotMarkDirty();
ReplicationSlotsComputeRequiredXmin();
}
}
bool active;
/* any outstanding modifications? */
+ bool just_dirtied;
bool dirty;
/*
extern void ReplicationSlotAcquire(const char *name);
extern void ReplicationSlotRelease(void);
extern void ReplicationSlotSave(void);
+extern void ReplicationSlotMarkDirty(void);
/* misc stuff */
extern bool ReplicationSlotValidateName(const char *name, int elevel);