mirror of
https://github.com/wader/fq.git
synced 2024-11-29 23:27:12 +03:00
postgres: wal refactoring
This commit is contained in:
parent
7c92715f2a
commit
bd2bdd649a
@ -2,7 +2,6 @@ package common
|
||||
|
||||
import (
|
||||
"github.com/wader/fq/pkg/decode"
|
||||
"github.com/wader/fq/pkg/scalar"
|
||||
)
|
||||
|
||||
//nolint:revive
|
||||
@ -11,62 +10,6 @@ const (
|
||||
XLP_LONG_HEADER = 2
|
||||
)
|
||||
|
||||
//nolint:revive
|
||||
const (
|
||||
BKPBLOCK_FORK_MASK = 0x0F
|
||||
BKPBLOCK_FLAG_MASK = 0xF0
|
||||
BKPBLOCK_HAS_IMAGE = 0x10 /* block data is an XLogRecordBlockImage */
|
||||
BKPBLOCK_HAS_DATA = 0x20
|
||||
BKPBLOCK_WILL_INIT = 0x40 /* redo will re-init the page */
|
||||
BKPBLOCK_SAME_REL = 0x80 /* RelFileNode omitted, same as previous */
|
||||
)
|
||||
|
||||
/* Information stored in bimg_info */
|
||||
//nolint:revive
|
||||
const (
|
||||
BKPIMAGE_HAS_HOLE = 0x01 /* page image has "hole" */
|
||||
BKPIMAGE_IS_COMPRESSED = 0x02 /* page image is compressed */
|
||||
BKPIMAGE_APPLY = 0x04 /* page image should be restored during replay */
|
||||
)
|
||||
|
||||
var rmgrIds = scalar.UToScalar{
|
||||
0: {Sym: "XLOG", Description: "RM_XLOG_ID"},
|
||||
1: {Sym: "Transaction", Description: "RM_XACT_ID"},
|
||||
2: {Sym: "Storage", Description: "RM_SMGR_ID"},
|
||||
3: {Sym: "CLOG", Description: "RM_CLOG_ID"},
|
||||
4: {Sym: "Database", Description: "RM_DBASE_ID"},
|
||||
5: {Sym: "Tablespace", Description: "RM_TBLSPC_ID"},
|
||||
6: {Sym: "MultiXact", Description: "RM_MULTIXACT_ID"},
|
||||
7: {Sym: "RelMap", Description: "RM_RELMAP_ID"},
|
||||
8: {Sym: "Standby", Description: "RM_STANDBY_ID"},
|
||||
9: {Sym: "Heap2", Description: "RM_HEAP2_ID"},
|
||||
10: {Sym: "Heap", Description: "RM_HEAP_ID"},
|
||||
11: {Sym: "Btree", Description: "RM_BTREE_ID"},
|
||||
12: {Sym: "Hash", Description: "RM_HASH_ID"},
|
||||
13: {Sym: "Gin", Description: "RM_GIN_ID"},
|
||||
14: {Sym: "Gist", Description: "RM_GIST_ID"},
|
||||
15: {Sym: "Sequence", Description: "RM_SEQ_ID"},
|
||||
16: {Sym: "SPGist", Description: "RM_SPGIST_ID"},
|
||||
17: {Sym: "BRIN", Description: "RM_BRIN_ID"},
|
||||
18: {Sym: "CommitTs", Description: "RM_COMMIT_TS_ID"},
|
||||
19: {Sym: "ReplicationOrigin", Description: "RM_REPLORIGIN_ID"},
|
||||
20: {Sym: "Generic", Description: "RM_GENERIC_ID"},
|
||||
21: {Sym: "LogicalMessage", Description: "RM_LOGICALMSG_ID"},
|
||||
}
|
||||
|
||||
const (
|
||||
XLOG_PAGE_MAGIC_MASK = 0xD000
|
||||
XLOG_PAGE_MAGIC_POSTGRES14 = 0xD10D
|
||||
)
|
||||
|
||||
const (
|
||||
XLR_MAX_BLOCK_ID = 32
|
||||
XLR_BLOCK_ID_DATA_SHORT = 255
|
||||
XLR_BLOCK_ID_DATA_LONG = 254
|
||||
XLR_BLOCK_ID_ORIGIN = 253
|
||||
XLR_BLOCK_ID_TOPLEVEL_XID = 252
|
||||
)
|
||||
|
||||
// struct XLogLongPageHeaderData {
|
||||
// /* 0 | 24 */ XLogPageHeaderData std;
|
||||
// /* 24 | 8 */ uint64 xlp_sysid;
|
||||
@ -104,34 +47,6 @@ const (
|
||||
//
|
||||
/* total size (bytes): 12 */
|
||||
|
||||
func decodeXLogPageHeaderData(d *decode.D) {
|
||||
/* 0 | 2 */ // uint16 xlp_magic;
|
||||
/* 2 | 2 */ // uint16 xlp_info;
|
||||
/* 4 | 4 */ // TimeLineID xlp_tli;
|
||||
/* 8 | 8 */ // XLogRecPtr xlp_pageaddr;
|
||||
/* 16 | 4 */ // uint32 xlp_rem_len;
|
||||
/* XXX 4-byte padding */
|
||||
xlpMagic := d.FieldU16("xlp_magic")
|
||||
xlpInfo := d.FieldU16("xlp_info")
|
||||
d.FieldU32("xlp_timeline")
|
||||
d.FieldU64("xlp_pageaddr")
|
||||
d.FieldU32("xlp_rem_len")
|
||||
d.FieldU32("padding0")
|
||||
|
||||
if (xlpMagic & XLOG_PAGE_MAGIC_MASK) == 0 {
|
||||
d.Fatalf("invalid xlp_magic = %X\n", xlpMagic)
|
||||
}
|
||||
|
||||
if (xlpInfo & XLP_LONG_HEADER) != 0 {
|
||||
// Long header
|
||||
d.FieldStruct("XLogLongPageHeaderData", func(d *decode.D) {
|
||||
d.FieldU64("xlp_sysid")
|
||||
d.FieldU32("xlp_seg_size")
|
||||
d.FieldU32("xlp_xlog_blcksz")
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
type walD struct {
|
||||
maxOffset int64
|
||||
page *walPage
|
||||
|
@ -11,8 +11,7 @@ import (
|
||||
"strings"
|
||||
)
|
||||
|
||||
// TO DO
|
||||
// not ready yet
|
||||
// partial parsing of WAL
|
||||
|
||||
func init() {
|
||||
interp.RegisterFormat(decode.Format{
|
||||
@ -26,18 +25,6 @@ func init() {
|
||||
})
|
||||
}
|
||||
|
||||
// https://pgpedia.info/x/XLOG_PAGE_MAGIC.html
|
||||
//nolint:revive
|
||||
const (
|
||||
XLOG_PAGE_MAGIC_15 = uint16(0xD10F)
|
||||
XLOG_PAGE_MAGIC_14 = uint16(0xD10D)
|
||||
XLOG_PAGE_MAGIC_13 = uint16(0xD106)
|
||||
XLOG_PAGE_MAGIC_12 = uint16(0xD101)
|
||||
XLOG_PAGE_MAGIC_11 = uint16(0xD098)
|
||||
XLOG_PAGE_MAGIC_10 = uint16(0xD097)
|
||||
XLOG_PAGE_MAGIC_96 = uint16(0xD093)
|
||||
)
|
||||
|
||||
func ParseLsn(lsn string) (uint32, error) {
|
||||
// check for 0/4E394440
|
||||
str1 := lsn
|
||||
|
Loading…
Reference in New Issue
Block a user