1
0
mirror of https://github.com/postgres/postgres.git synced 2025-10-15 05:46:52 +03:00

Make some use of anonymous unions [reorderbuffer xact_time]

Make some use of anonymous unions, which are allowed as of C11, as
examples and encouragement for future code, and to test compilers.

This commit changes the ReorderBufferTXN struct.

Reviewed-by: Chao Li <li.evan.chao@gmail.com>
Discussion: https://www.postgresql.org/message-id/flat/f00a9968-388e-4f8c-b5ef-5102e962d997%40eisentraut.org
This commit is contained in:
Peter Eisentraut
2025-09-30 12:24:15 +02:00
parent 4b7e6c73b0
commit 57d46dff9b
5 changed files with 22 additions and 22 deletions

View File

@@ -340,7 +340,7 @@ pg_decode_commit_txn(LogicalDecodingContext *ctx, ReorderBufferTXN *txn,
if (data->include_timestamp) if (data->include_timestamp)
appendStringInfo(ctx->out, " (at %s)", appendStringInfo(ctx->out, " (at %s)",
timestamptz_to_str(txn->xact_time.commit_time)); timestamptz_to_str(txn->commit_time));
OutputPluginWrite(ctx, true); OutputPluginWrite(ctx, true);
} }
@@ -391,7 +391,7 @@ pg_decode_prepare_txn(LogicalDecodingContext *ctx, ReorderBufferTXN *txn,
if (data->include_timestamp) if (data->include_timestamp)
appendStringInfo(ctx->out, " (at %s)", appendStringInfo(ctx->out, " (at %s)",
timestamptz_to_str(txn->xact_time.prepare_time)); timestamptz_to_str(txn->prepare_time));
OutputPluginWrite(ctx, true); OutputPluginWrite(ctx, true);
} }
@@ -413,7 +413,7 @@ pg_decode_commit_prepared_txn(LogicalDecodingContext *ctx, ReorderBufferTXN *txn
if (data->include_timestamp) if (data->include_timestamp)
appendStringInfo(ctx->out, " (at %s)", appendStringInfo(ctx->out, " (at %s)",
timestamptz_to_str(txn->xact_time.commit_time)); timestamptz_to_str(txn->commit_time));
OutputPluginWrite(ctx, true); OutputPluginWrite(ctx, true);
} }
@@ -437,7 +437,7 @@ pg_decode_rollback_prepared_txn(LogicalDecodingContext *ctx,
if (data->include_timestamp) if (data->include_timestamp)
appendStringInfo(ctx->out, " (at %s)", appendStringInfo(ctx->out, " (at %s)",
timestamptz_to_str(txn->xact_time.commit_time)); timestamptz_to_str(txn->commit_time));
OutputPluginWrite(ctx, true); OutputPluginWrite(ctx, true);
} }
@@ -874,7 +874,7 @@ pg_decode_stream_prepare(LogicalDecodingContext *ctx,
if (data->include_timestamp) if (data->include_timestamp)
appendStringInfo(ctx->out, " (at %s)", appendStringInfo(ctx->out, " (at %s)",
timestamptz_to_str(txn->xact_time.prepare_time)); timestamptz_to_str(txn->prepare_time));
OutputPluginWrite(ctx, true); OutputPluginWrite(ctx, true);
} }
@@ -903,7 +903,7 @@ pg_decode_stream_commit(LogicalDecodingContext *ctx,
if (data->include_timestamp) if (data->include_timestamp)
appendStringInfo(ctx->out, " (at %s)", appendStringInfo(ctx->out, " (at %s)",
timestamptz_to_str(txn->xact_time.commit_time)); timestamptz_to_str(txn->commit_time));
OutputPluginWrite(ctx, true); OutputPluginWrite(ctx, true);
} }

View File

@@ -52,7 +52,7 @@ logicalrep_write_begin(StringInfo out, ReorderBufferTXN *txn)
/* fixed fields */ /* fixed fields */
pq_sendint64(out, txn->final_lsn); pq_sendint64(out, txn->final_lsn);
pq_sendint64(out, txn->xact_time.commit_time); pq_sendint64(out, txn->commit_time);
pq_sendint32(out, txn->xid); pq_sendint32(out, txn->xid);
} }
@@ -88,7 +88,7 @@ logicalrep_write_commit(StringInfo out, ReorderBufferTXN *txn,
/* send fields */ /* send fields */
pq_sendint64(out, commit_lsn); pq_sendint64(out, commit_lsn);
pq_sendint64(out, txn->end_lsn); pq_sendint64(out, txn->end_lsn);
pq_sendint64(out, txn->xact_time.commit_time); pq_sendint64(out, txn->commit_time);
} }
/* /*
@@ -120,7 +120,7 @@ logicalrep_write_begin_prepare(StringInfo out, ReorderBufferTXN *txn)
/* fixed fields */ /* fixed fields */
pq_sendint64(out, txn->final_lsn); pq_sendint64(out, txn->final_lsn);
pq_sendint64(out, txn->end_lsn); pq_sendint64(out, txn->end_lsn);
pq_sendint64(out, txn->xact_time.prepare_time); pq_sendint64(out, txn->prepare_time);
pq_sendint32(out, txn->xid); pq_sendint32(out, txn->xid);
/* send gid */ /* send gid */
@@ -173,7 +173,7 @@ logicalrep_write_prepare_common(StringInfo out, LogicalRepMsgType type,
/* send fields */ /* send fields */
pq_sendint64(out, prepare_lsn); pq_sendint64(out, prepare_lsn);
pq_sendint64(out, txn->end_lsn); pq_sendint64(out, txn->end_lsn);
pq_sendint64(out, txn->xact_time.prepare_time); pq_sendint64(out, txn->prepare_time);
pq_sendint32(out, txn->xid); pq_sendint32(out, txn->xid);
/* send gid */ /* send gid */
@@ -253,7 +253,7 @@ logicalrep_write_commit_prepared(StringInfo out, ReorderBufferTXN *txn,
/* send fields */ /* send fields */
pq_sendint64(out, commit_lsn); pq_sendint64(out, commit_lsn);
pq_sendint64(out, txn->end_lsn); pq_sendint64(out, txn->end_lsn);
pq_sendint64(out, txn->xact_time.commit_time); pq_sendint64(out, txn->commit_time);
pq_sendint32(out, txn->xid); pq_sendint32(out, txn->xid);
/* send gid */ /* send gid */
@@ -311,7 +311,7 @@ logicalrep_write_rollback_prepared(StringInfo out, ReorderBufferTXN *txn,
pq_sendint64(out, prepare_end_lsn); pq_sendint64(out, prepare_end_lsn);
pq_sendint64(out, txn->end_lsn); pq_sendint64(out, txn->end_lsn);
pq_sendint64(out, prepare_time); pq_sendint64(out, prepare_time);
pq_sendint64(out, txn->xact_time.commit_time); pq_sendint64(out, txn->commit_time);
pq_sendint32(out, txn->xid); pq_sendint32(out, txn->xid);
/* send gid */ /* send gid */
@@ -1119,7 +1119,7 @@ logicalrep_write_stream_commit(StringInfo out, ReorderBufferTXN *txn,
/* send fields */ /* send fields */
pq_sendint64(out, commit_lsn); pq_sendint64(out, commit_lsn);
pq_sendint64(out, txn->end_lsn); pq_sendint64(out, txn->end_lsn);
pq_sendint64(out, txn->xact_time.commit_time); pq_sendint64(out, txn->commit_time);
} }
/* /*

View File

@@ -2830,7 +2830,7 @@ ReorderBufferReplay(ReorderBufferTXN *txn,
txn->final_lsn = commit_lsn; txn->final_lsn = commit_lsn;
txn->end_lsn = end_lsn; txn->end_lsn = end_lsn;
txn->xact_time.commit_time = commit_time; txn->commit_time = commit_time;
txn->origin_id = origin_id; txn->origin_id = origin_id;
txn->origin_lsn = origin_lsn; txn->origin_lsn = origin_lsn;
@@ -2922,7 +2922,7 @@ ReorderBufferRememberPrepareInfo(ReorderBuffer *rb, TransactionId xid,
*/ */
txn->final_lsn = prepare_lsn; txn->final_lsn = prepare_lsn;
txn->end_lsn = end_lsn; txn->end_lsn = end_lsn;
txn->xact_time.prepare_time = prepare_time; txn->prepare_time = prepare_time;
txn->origin_id = origin_id; txn->origin_id = origin_id;
txn->origin_lsn = origin_lsn; txn->origin_lsn = origin_lsn;
@@ -2979,7 +2979,7 @@ ReorderBufferPrepare(ReorderBuffer *rb, TransactionId xid,
txn->gid = pstrdup(gid); txn->gid = pstrdup(gid);
ReorderBufferReplay(txn, rb, xid, txn->final_lsn, txn->end_lsn, ReorderBufferReplay(txn, rb, xid, txn->final_lsn, txn->end_lsn,
txn->xact_time.prepare_time, txn->origin_id, txn->origin_lsn); txn->prepare_time, txn->origin_id, txn->origin_lsn);
/* /*
* Send a prepare if not already done so. This might occur if we have * Send a prepare if not already done so. This might occur if we have
@@ -3018,7 +3018,7 @@ ReorderBufferFinishPrepared(ReorderBuffer *rb, TransactionId xid,
* be later used for rollback. * be later used for rollback.
*/ */
prepare_end_lsn = txn->end_lsn; prepare_end_lsn = txn->end_lsn;
prepare_time = txn->xact_time.prepare_time; prepare_time = txn->prepare_time;
/* add the gid in the txn */ /* add the gid in the txn */
txn->gid = pstrdup(gid); txn->gid = pstrdup(gid);
@@ -3050,12 +3050,12 @@ ReorderBufferFinishPrepared(ReorderBuffer *rb, TransactionId xid,
* prepared after the restart. * prepared after the restart.
*/ */
ReorderBufferReplay(txn, rb, xid, txn->final_lsn, txn->end_lsn, ReorderBufferReplay(txn, rb, xid, txn->final_lsn, txn->end_lsn,
txn->xact_time.prepare_time, txn->origin_id, txn->origin_lsn); txn->prepare_time, txn->origin_id, txn->origin_lsn);
} }
txn->final_lsn = commit_lsn; txn->final_lsn = commit_lsn;
txn->end_lsn = end_lsn; txn->end_lsn = end_lsn;
txn->xact_time.commit_time = commit_time; txn->commit_time = commit_time;
txn->origin_id = origin_id; txn->origin_id = origin_id;
txn->origin_lsn = origin_lsn; txn->origin_lsn = origin_lsn;
@@ -3095,7 +3095,7 @@ ReorderBufferAbort(ReorderBuffer *rb, TransactionId xid, XLogRecPtr lsn,
if (txn == NULL) if (txn == NULL)
return; return;
txn->xact_time.abort_time = abort_time; txn->abort_time = abort_time;
/* For streamed transactions notify the remote node about the abort. */ /* For streamed transactions notify the remote node about the abort. */
if (rbtxn_is_streamed(txn)) if (rbtxn_is_streamed(txn))

View File

@@ -1888,7 +1888,7 @@ pgoutput_stream_abort(struct LogicalDecodingContext *ctx,
OutputPluginPrepareWrite(ctx, true); OutputPluginPrepareWrite(ctx, true);
logicalrep_write_stream_abort(ctx->out, toptxn->xid, txn->xid, abort_lsn, logicalrep_write_stream_abort(ctx->out, toptxn->xid, txn->xid, abort_lsn,
txn->xact_time.abort_time, write_abort_info); txn->abort_time, write_abort_info);
OutputPluginWrite(ctx, true); OutputPluginWrite(ctx, true);

View File

@@ -359,7 +359,7 @@ typedef struct ReorderBufferTXN
TimestampTz commit_time; TimestampTz commit_time;
TimestampTz prepare_time; TimestampTz prepare_time;
TimestampTz abort_time; TimestampTz abort_time;
} xact_time; };
/* /*
* The base snapshot is used to decode all changes until either this * The base snapshot is used to decode all changes until either this