0002-Address-Shveta-s-comments-20251028.patch

text/x-patch

Filename: 0002-Address-Shveta-s-comments-20251028.patch
Type: text/x-patch
Part: 0
Message: Re: Report bytes and transactions actually sent downtream

Patch

Same data as JSON: GET /api/v1/attachments/:id/patch the parsed metadata as JSON — format, series position, per-file stats; never the diff bytes. API reference →
Format: format-patch
Series: patch 0002
Subject: Address Shveta's comments
File+
src/backend/replication/logical/logicalfuncs.c 5 1
src/include/replication/output_plugin.h 1 1
From 287217cf4aefeee0461bb77aa3377804752bc6e0 Mon Sep 17 00:00:00 2001
From: Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
Date: Tue, 28 Oct 2025 12:42:04 +0530
Subject: [PATCH 2/2] Address Shveta's comments

---
 src/backend/replication/logical/logicalfuncs.c | 6 +++++-
 src/include/replication/output_plugin.h        | 2 +-
 2 files changed, 6 insertions(+), 2 deletions(-)

diff --git a/src/backend/replication/logical/logicalfuncs.c b/src/backend/replication/logical/logicalfuncs.c
index d2ab41de438..55e02e7ee21 100644
--- a/src/backend/replication/logical/logicalfuncs.c
+++ b/src/backend/replication/logical/logicalfuncs.c
@@ -65,6 +65,7 @@ LogicalOutputWrite(LogicalDecodingContext *ctx, XLogRecPtr lsn, TransactionId xi
 	Datum		values[3];
 	bool		nulls[3];
 	DecodingOutputState *p;
+	int64		sentBytes = 0;
 
 	/* SQL Datums can only be of a limited length... */
 	if (ctx->out->len > MaxAllocSize - VARHDRSZ)
@@ -74,7 +75,9 @@ LogicalOutputWrite(LogicalDecodingContext *ctx, XLogRecPtr lsn, TransactionId xi
 
 	memset(nulls, 0, sizeof(nulls));
 	values[0] = LSNGetDatum(lsn);
+	sentBytes += sizeof(XLogRecPtr);
 	values[1] = TransactionIdGetDatum(xid);
+	sentBytes += sizeof(TransactionId);
 
 	/*
 	 * Assert ctx->out is in database encoding when we're writing textual
@@ -87,6 +90,7 @@ LogicalOutputWrite(LogicalDecodingContext *ctx, XLogRecPtr lsn, TransactionId xi
 
 	/* ick, but cstring_to_text_with_len works for bytea perfectly fine */
 	values[2] = PointerGetDatum(cstring_to_text_with_len(ctx->out->data, ctx->out->len));
+	sentBytes += ctx->out->len;
 
 	tuplestore_putvalues(p->tupstore, p->tupdesc, values, nulls);
 
@@ -95,7 +99,7 @@ LogicalOutputWrite(LogicalDecodingContext *ctx, XLogRecPtr lsn, TransactionId xi
 	 * data sent downstream.
 	 */
 	if (ctx->stats)
-		ctx->stats->sentBytes += ctx->out->len + sizeof(XLogRecPtr) + sizeof(TransactionId);
+		ctx->stats->sentBytes += sentBytes;
 
 	p->returned_rows++;
 }
diff --git a/src/include/replication/output_plugin.h b/src/include/replication/output_plugin.h
index 02018f0593c..4cc939e6c98 100644
--- a/src/include/replication/output_plugin.h
+++ b/src/include/replication/output_plugin.h
@@ -38,7 +38,7 @@ typedef struct OutputPluginStats
 	int64		sentTxns;		/* number of transactions decoded and sent
 								 * downstream */
 	int64		sentBytes;		/* amount of data decoded and sent downstream */
-	int64		filteredBytes;	/* amount of data from reoder buffer that was
+	int64		filteredBytes;	/* amount of data from reorder buffer that was
 								 * filtered out by the output plugin */
 } OutputPluginStats;
 
-- 
2.34.1