Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 57f3702

Browse files
committed
Use aux process resource owner in walsender
AIO will need a resource owner to do IO. Right now we create a resowner on-demand during basebackup, and we could do the same for AIO. But it seems easier to just always create an aux process resowner. Reviewed-by: Heikki Linnakangas <hlinnaka@iki.fi> Reviewed-by: Noah Misch <noah@leadboat.com> Discussion: https://postgr.es/m/1f6b50a7-38ef-4d87-8246-786d39f46ab9@iki.fi
1 parent 755a4c1 commit 57f3702

File tree

3 files changed

+13
-40
lines changed

3 files changed

+13
-40
lines changed

src/backend/backup/basebackup.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -250,8 +250,10 @@ perform_base_backup(basebackup_options *opt, bbsink *sink,
250250
state.bytes_total_is_valid = false;
251251

252252
/* we're going to use a BufFile, so we need a ResourceOwner */
253-
Assert(CurrentResourceOwner == NULL);
254-
CurrentResourceOwner = ResourceOwnerCreate(NULL, "base backup");
253+
Assert(AuxProcessResourceOwner != NULL);
254+
Assert(CurrentResourceOwner == AuxProcessResourceOwner ||
255+
CurrentResourceOwner == NULL);
256+
CurrentResourceOwner = AuxProcessResourceOwner;
255257

256258
backup_started_in_recovery = RecoveryInProgress();
257259

@@ -672,7 +674,7 @@ perform_base_backup(basebackup_options *opt, bbsink *sink,
672674
FreeBackupManifest(&manifest);
673675

674676
/* clean up the resource owner we created */
675-
WalSndResourceCleanup(true);
677+
ReleaseAuxProcessResources(true);
676678

677679
basebackup_progress_done();
678680
}

src/backend/replication/walsender.c

Lines changed: 8 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -282,10 +282,8 @@ InitWalSender(void)
282282
/* Create a per-walsender data structure in shared memory */
283283
InitWalSenderSlot();
284284

285-
/*
286-
* We don't currently need any ResourceOwner in a walsender process, but
287-
* if we did, we could call CreateAuxProcessResourceOwner here.
288-
*/
285+
/* need resource owner for e.g. basebackups */
286+
CreateAuxProcessResourceOwner();
289287

290288
/*
291289
* Let postmaster know that we're a WAL sender. Once we've declared us as
@@ -346,7 +344,7 @@ WalSndErrorCleanup(void)
346344
* without a transaction, we've got to clean that up now.
347345
*/
348346
if (!IsTransactionOrTransactionBlock())
349-
WalSndResourceCleanup(false);
347+
ReleaseAuxProcessResources(false);
350348

351349
if (got_STOPPING || got_SIGUSR2)
352350
proc_exit(0);
@@ -355,34 +353,6 @@ WalSndErrorCleanup(void)
355353
WalSndSetState(WALSNDSTATE_STARTUP);
356354
}
357355

358-
/*
359-
* Clean up any ResourceOwner we created.
360-
*/
361-
void
362-
WalSndResourceCleanup(bool isCommit)
363-
{
364-
ResourceOwner resowner;
365-
366-
if (CurrentResourceOwner == NULL)
367-
return;
368-
369-
/*
370-
* Deleting CurrentResourceOwner is not allowed, so we must save a pointer
371-
* in a local variable and clear it first.
372-
*/
373-
resowner = CurrentResourceOwner;
374-
CurrentResourceOwner = NULL;
375-
376-
/* Now we can release resources and delete it. */
377-
ResourceOwnerRelease(resowner,
378-
RESOURCE_RELEASE_BEFORE_LOCKS, isCommit, true);
379-
ResourceOwnerRelease(resowner,
380-
RESOURCE_RELEASE_LOCKS, isCommit, true);
381-
ResourceOwnerRelease(resowner,
382-
RESOURCE_RELEASE_AFTER_LOCKS, isCommit, true);
383-
ResourceOwnerDelete(resowner);
384-
}
385-
386356
/*
387357
* Handle a client's connection abort in an orderly manner.
388358
*/
@@ -685,8 +655,10 @@ UploadManifest(void)
685655
* parsing the manifest will use the cryptohash stuff, which requires a
686656
* resource owner
687657
*/
688-
Assert(CurrentResourceOwner == NULL);
689-
CurrentResourceOwner = ResourceOwnerCreate(NULL, "base backup");
658+
Assert(AuxProcessResourceOwner != NULL);
659+
Assert(CurrentResourceOwner == AuxProcessResourceOwner ||
660+
CurrentResourceOwner == NULL);
661+
CurrentResourceOwner = AuxProcessResourceOwner;
690662

691663
/* Prepare to read manifest data into a temporary context. */
692664
mcxt = AllocSetContextCreate(CurrentMemoryContext,
@@ -723,7 +695,7 @@ UploadManifest(void)
723695
uploaded_manifest_mcxt = mcxt;
724696

725697
/* clean up the resource owner we created */
726-
WalSndResourceCleanup(true);
698+
ReleaseAuxProcessResources(true);
727699
}
728700

729701
/*

src/include/replication/walsender.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ extern PGDLLIMPORT bool log_replication_commands;
3838
extern void InitWalSender(void);
3939
extern bool exec_replication_command(const char *cmd_string);
4040
extern void WalSndErrorCleanup(void);
41-
extern void WalSndResourceCleanup(bool isCommit);
4241
extern void PhysicalWakeupLogicalWalSnd(void);
4342
extern XLogRecPtr GetStandbyFlushRecPtr(TimeLineID *tli);
4443
extern void WalSndSignals(void);

0 commit comments

Comments
 (0)