1 | /*------------------------------------------------------------------------- |
2 | * |
3 | * committsdesc.c |
4 | * rmgr descriptor routines for access/transam/commit_ts.c |
5 | * |
6 | * Portions Copyright (c) 1996-2019, PostgreSQL Global Development Group |
7 | * Portions Copyright (c) 1994, Regents of the University of California |
8 | * |
9 | * |
10 | * IDENTIFICATION |
11 | * src/backend/access/rmgrdesc/committsdesc.c |
12 | * |
13 | *------------------------------------------------------------------------- |
14 | */ |
15 | #include "postgres.h" |
16 | |
17 | #include "access/commit_ts.h" |
18 | #include "utils/timestamp.h" |
19 | |
20 | |
21 | void |
22 | commit_ts_desc(StringInfo buf, XLogReaderState *record) |
23 | { |
24 | char *rec = XLogRecGetData(record); |
25 | uint8 info = XLogRecGetInfo(record) & ~XLR_INFO_MASK; |
26 | |
27 | if (info == COMMIT_TS_ZEROPAGE) |
28 | { |
29 | int pageno; |
30 | |
31 | memcpy(&pageno, rec, sizeof(int)); |
32 | appendStringInfo(buf, "%d" , pageno); |
33 | } |
34 | else if (info == COMMIT_TS_TRUNCATE) |
35 | { |
36 | xl_commit_ts_truncate *trunc = (xl_commit_ts_truncate *) rec; |
37 | |
38 | appendStringInfo(buf, "pageno %d, oldestXid %u" , |
39 | trunc->pageno, trunc->oldestXid); |
40 | } |
41 | else if (info == COMMIT_TS_SETTS) |
42 | { |
43 | xl_commit_ts_set *xlrec = (xl_commit_ts_set *) rec; |
44 | int nsubxids; |
45 | |
46 | appendStringInfo(buf, "set %s/%d for: %u" , |
47 | timestamptz_to_str(xlrec->timestamp), |
48 | xlrec->nodeid, |
49 | xlrec->mainxid); |
50 | nsubxids = ((XLogRecGetDataLen(record) - SizeOfCommitTsSet) / |
51 | sizeof(TransactionId)); |
52 | if (nsubxids > 0) |
53 | { |
54 | int i; |
55 | TransactionId *subxids; |
56 | |
57 | subxids = palloc(sizeof(TransactionId) * nsubxids); |
58 | memcpy(subxids, |
59 | XLogRecGetData(record) + SizeOfCommitTsSet, |
60 | sizeof(TransactionId) * nsubxids); |
61 | for (i = 0; i < nsubxids; i++) |
62 | appendStringInfo(buf, ", %u" , subxids[i]); |
63 | pfree(subxids); |
64 | } |
65 | } |
66 | } |
67 | |
68 | const char * |
69 | commit_ts_identify(uint8 info) |
70 | { |
71 | switch (info) |
72 | { |
73 | case COMMIT_TS_ZEROPAGE: |
74 | return "ZEROPAGE" ; |
75 | case COMMIT_TS_TRUNCATE: |
76 | return "TRUNCATE" ; |
77 | case COMMIT_TS_SETTS: |
78 | return "SETTS" ; |
79 | default: |
80 | return NULL; |
81 | } |
82 | } |
83 | |