Skip to content

Commit

Permalink
Record both start and end lsn
Browse files Browse the repository at this point in the history
  • Loading branch information
Ethan committed Mar 31, 2015
1 parent 909393d commit 7877e73
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions wal2json.c
Original file line number Diff line number Diff line change
Expand Up @@ -212,12 +212,8 @@ pg_decode_begin_txn(LogicalDecodingContext *ctx, ReorderBufferTXN *txn)
appendStringInfo(ctx->out, "\t\"xid\": %u,\n", txn->xid);

if (data->include_lsn) {
// uint32 id, off;
// id = (uint32) (ctx->write_location >> 32);
// off = (uint32) ctx->write_location;
// appendStringInfo(ctx->out, "\t\"lsn\": %X/%X,\n", id, off);
char *lsn_str = DatumGetCString(DirectFunctionCall1(pg_lsn_out, ctx->write_location));
appendStringInfo(ctx->out, "\t\"lsn\": \"%s\",\n", lsn_str);
appendStringInfo(ctx->out, "\t\"start_lsn\": \"%s\",\n", lsn_str);
pfree(lsn_str);
}

Expand Down Expand Up @@ -246,7 +242,14 @@ pg_decode_commit_txn(LogicalDecodingContext *ctx, ReorderBufferTXN *txn,
/* Transaction ends */
OutputPluginPrepareWrite(ctx, true);

appendStringInfoString(ctx->out, "\t]\n}");
/* Make sure the commas and new lines work with and without include_lsn */
appendStringInfoString(ctx->out, "\t]");
if (data->include_lsn) {
char *lsn_str = DatumGetCString(DirectFunctionCall1(pg_lsn_out, commit_lsn));
appendStringInfo(ctx->out, ",\n\t\"end_lsn\": \"%s\"", lsn_str);
pfree(lsn_str);
}
appendStringInfoString(ctx->out, "\n}");

OutputPluginWrite(ctx, true);
}
Expand Down

0 comments on commit 7877e73

Please sign in to comment.