diff --git a/src/backend/access/transam/xact.c b/src/backend/access/transam/xact.c index 0487be1..22adedd 100644 --- a/src/backend/access/transam/xact.c +++ b/src/backend/access/transam/xact.c @@ -183,6 +183,12 @@ static TransactionStateData TopTransactionStateData = { }; /* + * Track total volume of WAL written by current top-level transaction + * to allow tracking, reporting and control of writing WAL. + */ +static uint64 currentTransactionWALVolume; + +/* * unreportedXids holds XIDs of all subtransactions that have not yet been * reported in a XLOG_XACT_ASSIGNMENT record. */ @@ -397,17 +403,26 @@ GetCurrentTransactionIdIfAny(void) } /* - * MarkCurrentTransactionIdLoggedIfAny + * ReportTransactionInsertedWAL * - * Remember that the current xid - if it is assigned - now has been wal logged. + * Remember that the current xid - if it is assigned - has now inserted WAL */ void -MarkCurrentTransactionIdLoggedIfAny(void) +ReportTransactionInsertedWAL(uint32 insertedWALVolume) { + currentTransactionWALVolume += insertedWALVolume; if (TransactionIdIsValid(CurrentTransactionState->transactionId)) CurrentTransactionState->didLogXid = true; } +/* + * GetCurrentTransactionWALVolume + */ +uint64 +GetCurrentTransactionWALVolume(void) +{ + return currentTransactionWALVolume; +} /* * GetStableLatestTransactionId @@ -1772,6 +1787,7 @@ StartTransaction(void) /* * initialize reported xid accounting */ + currentTransactionWALVolume = 0; nUnreportedXids = 0; s->didLogXid = false; diff --git a/src/backend/access/transam/xlog.c b/src/backend/access/transam/xlog.c index b53ae87..7255aa0 100644 --- a/src/backend/access/transam/xlog.c +++ b/src/backend/access/transam/xlog.c @@ -1192,6 +1192,7 @@ begin:; * already exactly at the beginning of a segment, so there was no need * to do anything. */ + write_len = 0; } /* @@ -1199,7 +1200,7 @@ begin:; */ WALInsertSlotRelease(); - MarkCurrentTransactionIdLoggedIfAny(); + ReportTransactionInsertedWAL(write_len); END_CRIT_SECTION(); diff --git a/src/include/access/xact.h b/src/include/access/xact.h index 634f5b2..31ca1ba 100644 --- a/src/include/access/xact.h +++ b/src/include/access/xact.h @@ -215,7 +215,8 @@ extern TransactionId GetCurrentTransactionId(void); extern TransactionId GetCurrentTransactionIdIfAny(void); extern TransactionId GetStableLatestTransactionId(void); extern SubTransactionId GetCurrentSubTransactionId(void); -extern void MarkCurrentTransactionIdLoggedIfAny(void); +extern void ReportTransactionInsertedWAL(uint32 insertedWALVolume); +extern uint64 GetCurrentTransactionWALVolume(void); extern bool SubTransactionIsActive(SubTransactionId subxid); extern CommandId GetCurrentCommandId(bool used); extern TimestampTz GetCurrentTransactionStartTimestamp(void);