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

Commit c68f307

Browse files
committed
Use atomic write for updating WAL statistic
1 parent f55e0cc commit c68f307

File tree

4 files changed

+5
-6
lines changed

4 files changed

+5
-6
lines changed

src/backend/access/transam/xlog.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1487,7 +1487,7 @@ CopyXLogRecordToWAL(int write_len, bool isLogSwitch, XLogRecData *rdata,
14871487
freespace = INSERT_FREESPACE(CurrPos);
14881488

14891489
/* Accumulate amount of data written to WAL for pg_xact_activity */
1490-
MyProc->walWritten += write_len;
1490+
pg_atomic_write_u64(&MyProc->walWritten, pg_atomic_read_u64(&MyProc->walWritten) + write_len);
14911491

14921492
/*
14931493
* there should be enough space for at least the first field (xl_tot_len)

src/backend/storage/lmgr/proc.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -390,7 +390,7 @@ InitProcess(void)
390390
MyPgXact->xid = InvalidTransactionId;
391391
MyPgXact->xmin = InvalidTransactionId;
392392
MyProc->pid = MyProcPid;
393-
MyProc->walWritten = 0;
393+
pg_atomic_init_u64(&MyProc->walWritten, 0);
394394

395395
/* backendId, databaseId and roleId will be filled in later */
396396
MyProc->backendId = InvalidBackendId;

src/backend/utils/adt/pgstatfuncs.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -546,8 +546,7 @@ pg_stat_get_progress_info(PG_FUNCTION_ARGS)
546546
Datum
547547
pg_stat_get_activity(PG_FUNCTION_ARGS)
548548
{
549-
550-
#define PG_STAT_GET_ACTIVITY_COLS 29
549+
#define PG_STAT_GET_ACTIVITY_COLS 29
551550
int num_backends = pgstat_fetch_stat_numbackends();
552551
int curr_backend;
553552
int pid = PG_ARGISNULL(0) ? -1 : PG_GETARG_INT32(0);
@@ -931,7 +930,7 @@ pg_stat_get_wal_activity(PG_FUNCTION_ARGS)
931930
if (proc == NULL)
932931
PG_RETURN_NULL();
933932
else
934-
PG_RETURN_INT64(proc->walWritten);
933+
PG_RETURN_INT64(pg_atomic_read_u64(&proc->walWritten));
935934
}
936935

937936

src/include/storage/proc.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ struct PGPROC
207207
/*
208208
* Amount of data written to the WAL by this process
209209
*/
210-
uint64 walWritten;
210+
pg_atomic_uint64 walWritten;
211211
};
212212

213213
/* NOTE: "typedef struct PGPROC PGPROC" appears in storage/lock.h. */

0 commit comments

Comments
 (0)