Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Postgres #415

Merged
merged 159 commits into from
May 6, 2023
Merged
Show file tree
Hide file tree
Changes from 148 commits
Commits
Show all changes
159 commits
Select commit Hold shift + click to select a range
f069ddc
[WIP] initial attempt to add postgres
mizhka Jul 12, 2022
7d36eee
Merge branch 'master' of https://github.com/wader/fq
Jul 18, 2022
9a96da8
Add postgres pg_control parser
Jul 19, 2022
8cf83fb
pg_control implementation
Jul 19, 2022
d4f8dfa
Add flavour arg to postgres parser
Jul 20, 2022
0107d12
Add pgproee14 flavour to postgres
Jul 20, 2022
3b81d99
DBState enum for postgres
Jul 20, 2022
c8ece64
show mock_authentication_nonce as hex
Jul 20, 2022
deaf5ef
WalLevel for postgres
Jul 20, 2022
2b1bdfb
add icu version mapper
Jul 20, 2022
8d317dd
lsn mapper
Jul 20, 2022
af0e220
unix time mapper for postgres
Jul 21, 2022
441ecee
pgpro version mapper
Jul 21, 2022
fcd7fbc
mappers for postgres
Jul 21, 2022
bebdfa9
Try to implement pgwal - fail.
Jul 28, 2022
51878dc
PostgreSQL heap page parser implememtation.
Jul 29, 2022
ce9ae76
PostgreSQL: heap tuples implementation
Jul 29, 2022
01b380e
PostgrreSQl heap decode refactoring
Jul 29, 2022
3c6ea87
Add heap infomask flags parser to PostgreSQL
Aug 1, 2022
850dc60
PostgreSQL: lp_flags format
Aug 1, 2022
6ed0263
PostgreSQL: accept only normal item pointers
Aug 1, 2022
ffd7c9b
PostgreSQL: implement pgproee 14
Aug 2, 2022
96a86e2
PostgreSQL: fixes
Aug 2, 2022
2d3884a
PostgreSQL: pgproee11 heap impl
Aug 2, 2022
d8b891c
PostgreSQL: pgproee11 pg_control impl
Aug 2, 2022
fdb3b3e
PostgreSQl: fix offset
Aug 3, 2022
f5278f3
PostgreSQL: pg_control for ver 12
Aug 3, 2022
0327411
ref
Aug 3, 2022
6618e76
PostgreSQL: heap impl for version 11
Aug 3, 2022
b4ae1d5
PostgreSQL: add pg_control for pgproee 12
Aug 4, 2022
96a96a5
PostgreSQL: heap impl for pgproee 12
Aug 4, 2022
d9de2d4
PostgreSQL: fix
Aug 4, 2022
b722b21
PostgreSQL: ref
Aug 4, 2022
c273a6c
PostgreSQl: pg_control impl for version 13
Aug 4, 2022
621c4c4
PostgreSQl: heap impl for version 13
Aug 4, 2022
a653710
PostgreSQL: add pg_control to pgpro14
Aug 5, 2022
ffc08cf
PostgreSQL: add heap for pgpro14
Aug 5, 2022
972c5a3
PostgreSQL: pg_control, pgheap impl for pgproee13
Aug 5, 2022
07056c2
PostgreSQL: pg_control impl for pgproee 10
Aug 5, 2022
d148727
PostgreSQL: pgheap impl for pgproee10
Aug 5, 2022
e4ba72f
Merge remote-tracking branch 'github/master'
Aug 25, 2022
2b3035f
add pgpro13 to postgres
Aug 26, 2022
7bf6b11
add pgpro13 heap
Aug 26, 2022
9570d4d
add pgpro12 postgres
Aug 26, 2022
cf1e7b2
add pgpro11 for postgres
Aug 26, 2022
f56c72d
add postgres tests for mem, cpu profiling
Aug 31, 2022
b4c4de2
Merge remote-tracking branch 'github/master'
Aug 31, 2022
2ee01f7
allow to change FillGaps in decoder
Sep 2, 2022
9f5036a
postgres: made root an array
Sep 2, 2022
08eb303
postgres: add postgres format docs, refactoing postgres flavours
Sep 2, 2022
d588605
Merge branch 'master' of github.com:pnsafonov/fq into postgres
Sep 2, 2022
4db1284
postgres: add tests
Sep 2, 2022
666bbfb
postgres: fix some unknown, chanche tests tovalue -> dv
Sep 5, 2022
ba8b90b
postgres: fill gap alignment in heap tuple
Sep 5, 2022
3e09f9f
postgres: change tuple struct in heap
Sep 5, 2022
ccf2edb
postgres: better versions probing in pg_control, fix holes, better tests
Sep 6, 2022
1e24d70
postgres: move SeekAbs(0) to Probe
Sep 6, 2022
5eea605
postgres: remove duplicate tests
Sep 6, 2022
ff4b6fd
postgres: refactoring - remove GetHeapD
Sep 6, 2022
f224ed0
postgres: refactoring
Sep 6, 2022
85c0422
postgres: fix linter
Sep 6, 2022
c2591ac
postgres: add test data with specific values
Sep 7, 2022
586c803
postgres: try to implement wal
Sep 9, 2022
1d9ef30
postgres: first correct read of WAL file
Sep 9, 2022
6281b50
postgres: exclude wal tests for now
Sep 9, 2022
8f57ebf
Merge remote-tracking branch 'github/master'
Sep 9, 2022
dc6ed54
Merge branch 'master' into postgres
Sep 9, 2022
8e27e30
Merge branch 'wader_master' into postgres
Sep 9, 2022
e311434
postgres: wal decoding implement
Sep 12, 2022
e66baa7
postgres: add wal checks
Sep 12, 2022
067f8d5
postgres: pgwal checks
Sep 12, 2022
448c369
postgres: try to implement pg_wal
Sep 15, 2022
09c42c3
postgres: add state to wal struct
Sep 16, 2022
d7bcca0
postgres: refactoring
Sep 16, 2022
f122f72
Merge branch 'wader_master' into postgres
Sep 16, 2022
dd84d32
postgres: pg_btree begin impl
Sep 19, 2022
22a6cfa
postgres: pg_btree add opaque flags
Sep 19, 2022
d370f5d
postgres: btree impl
Sep 20, 2022
87b7acf
postgres: btree impl
Sep 20, 2022
f3f259a
postgres: btree add free space
Sep 20, 2022
efda7b3
postgres: btree handle full file
Sep 20, 2022
00de0a9
postgres: pg_heap refactoring
Sep 21, 2022
edb5650
postgres: pg_control refactoring
Sep 21, 2022
9f1adb2
postgres: change AssertPosBytes to AssertPos (bits)
Sep 21, 2022
7dd7dbe
postgres: pg_heap reafactoring
Sep 21, 2022
c3ef341
postgresql: general logic for pg_heap, pg_btree
Sep 21, 2022
35124bf
postgres: pg_heap refactoring
Sep 21, 2022
7b52149
postgres: refactoring
Sep 21, 2022
7f219d8
Merge branch 'wader_master' into postgres
Sep 21, 2022
ae838b9
postgres: move postgres.md to formats.md, add btree tests
Sep 22, 2022
296ce68
postgres: refactoring
Sep 22, 2022
94e5b79
Merge branch 'wader_master' into postgres
Sep 23, 2022
90386a6
postgres: add postgres.md to format
Sep 23, 2022
de3ecf1
postgres: generate docs by embedded md
Sep 23, 2022
b06c9bc
postgres: pg_control change default flavour to empty string - it uses…
Sep 23, 2022
9deab2e
postgres: pg_heap fix page_begin, page_end
Sep 26, 2022
7858373
postgres: postgres 10 support
Oct 5, 2022
e57c3b9
postgres: refactoring
Oct 5, 2022
6588e1d
Merge branch 'wader_master' into postgres
Oct 5, 2022
12b8697
postgres: regenerate docs
Oct 5, 2022
03d8fe1
postgres: page sum impl
Oct 7, 2022
46e1e33
postgres: make page size const
Oct 7, 2022
4676590
postgres: add argument to calc page's check sum correctly
Oct 7, 2022
e06fa6e
postgres: refactoring
Oct 7, 2022
bedc480
postgres: refactoring
Oct 7, 2022
6fe5f05
postgres: lint, doc
Oct 7, 2022
2423f86
postgres: add how_to.md - how to generate test files for postgres
Oct 10, 2022
1aa08e3
postgres: add btree, pg_control to how_to.md
Oct 10, 2022
939c7c1
postgres: how_to.md
Oct 10, 2022
83d63c5
Merge branch 'wader_master' into postgres
Oct 10, 2022
dd9c7f0
Merge branch 'postgres' into postgres_wal_sync_with_postgres
Oct 12, 2022
8f55e17
postgres: remove SeekAbs(0) where it's not used.
Oct 12, 2022
5ff6273
postgres: add additional checks in pg_heap
Oct 24, 2022
9f61e63
postgres: allow all flovours to decode btree index
Oct 24, 2022
f4408fb
Merge branch 'postgres' into postgres_wal_sync_with_postgres
Oct 24, 2022
6aed238
postgres: add pg_wal for pgproee11 as copy of postgres14
Oct 24, 2022
a4c1c5b
postgres: wal const
Oct 24, 2022
c105fcd
postgres: wal impl
Oct 26, 2022
b09ec2f
postgres: wal refactoing
Oct 26, 2022
26bff14
postgres: wal refactoing
Oct 26, 2022
7c1dfbd
postgres: wal implementation
Oct 26, 2022
7c92715
postgres: refactoring
Oct 26, 2022
bd2bdd6
postgres: wal refactoring
Oct 26, 2022
7dedcba
postgres: refactoring
Oct 26, 2022
fb7778a
postgres: add wal tests
Oct 27, 2022
e8d8cac
postgres: pgpro wal implementation
Oct 28, 2022
d7a0f93
postgres: pgpro wal refactoring
Oct 28, 2022
069babb
postgres: wal refactoring
Oct 28, 2022
7f7f729
postgres: refactoring, tests
Oct 28, 2022
de68785
postgres: add test files
Oct 31, 2022
3c7ed5d
postgres: add tests data
Oct 31, 2022
7fd4109
postgres: add btree index tests
Oct 31, 2022
6e2e44d
postgres: remove arg in pg_btree
Oct 31, 2022
721c1ab
psotgres: refactoring
Oct 31, 2022
a4d904e
postgres: refactoring
Oct 31, 2022
cdf2831
Merge branch 'wader_master' into postgres
Nov 1, 2022
9c7f20b
Merge branch 'postgres' into postgres_wal_sync_with_postgres
Nov 1, 2022
e87d5a6
postgres: remove unused code
Nov 7, 2022
5bb8654
postgres: remove lsn parameter in pg_wal
Nov 7, 2022
5664c0a
postgres: refactor ItemIdData
Nov 7, 2022
e8bb169
postgres: fix pg_wal when XLogRecord size is more than page size
Nov 9, 2022
015b770
postgres: wal support multiple xlog_body for wal record
Nov 10, 2022
60709e5
postgres: remove pg_wal. Failed to implement.
Nov 23, 2022
dafbf4b
postgres: lint fixes
Nov 23, 2022
6fe61cd
Merge branch 'wader_master' into postgres_wal_removed
Nov 23, 2022
0ea20e6
postgres: fail on error in pg_heap
Nov 23, 2022
97bbc22
postgres: add page arg in pg_btree, change args names in pg_heap
Dec 22, 2022
bffa008
postgres: fix error in tests
Dec 26, 2022
c9b263e
postgres: version 15 support
Apr 17, 2023
bb2659d
Merge remote-tracking branch 'master' into postgres_merge_master_0
May 3, 2023
e5f15c5
postgres: fix compilation, fix tests
May 3, 2023
9508a20
postgres: fix lint
May 3, 2023
f6f8d5c
postgres: refactoring
May 3, 2023
7a89234
postgres: update doc
May 4, 2023
08c5352
postgres: refactoring
May 4, 2023
c23bc42
postgres: fix line endings in error messages, simplify code, add comm…
May 4, 2023
e839191
postgres: btree refactored by Mattias Wadman
May 5, 2023
c9350de
postgres: use bit stream instead of masks to get flags
May 6, 2023
e6a9cdb
postgres: doc
May 6, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
.DS_Store
testfiles/
fq
.idea
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,10 @@ ogg_page,
opus_packet,
[pcap](doc/formats.md#pcap),
pcapng,
[pg_btree](doc/formats.md#pg_btree),
[pg_control](doc/formats.md#pg_control),
[pg_heap](doc/formats.md#pg_heap),
[pg_wal](doc/formats.md#pg_wal),
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pg_wal was removed?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, pg_wal is removed.

png,
prores_frame,
[protobuf](doc/formats.md#protobuf),
Expand Down
1 change: 1 addition & 0 deletions format/all/all.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ import (
_ "github.com/wader/fq/format/opus"
_ "github.com/wader/fq/format/pcap"
_ "github.com/wader/fq/format/png"
_ "github.com/wader/fq/format/postgres"
_ "github.com/wader/fq/format/prores"
_ "github.com/wader/fq/format/protobuf"
_ "github.com/wader/fq/format/riff"
Expand Down
17 changes: 17 additions & 0 deletions format/format.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,9 @@ const (
OPUS_PACKET = "opus_packet"
PCAP = "pcap"
PCAPNG = "pcapng"
PG_BTREE = "pg_btree"
PG_CONTROL = "pg_control"
PG_HEAP = "pg_heap"
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi, i did quite large refactor how formats are registered to allow some new things in the futue (probe via schema, filename etc). To make it build again change to:

	PgBtree            = &decode.Group{Name: "pg_btree"}
	PgControl          = &decode.Group{Name: "pg_control"}
	PgHeap             = &decode.Group{Name: "pg_heap"}

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's done

PNG = "png"
PRORES_FRAME = "prores_frame"
PROTOBUF = "protobuf"
Expand Down Expand Up @@ -323,3 +326,17 @@ type CSVLIn struct {
type BitCoinBlockIn struct {
HasHeader bool `doc:"Has blkdat header"`
}

type PostgresIn struct {
Flavour string `doc:"PostgreSQL flavour: postgres14, pgproee14.., postgres10"`
}

type PostgresHeapIn struct {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The name convention i've settle on for in/out struct is <format-name>_In/Out where format name is camel case and same underscoring as the format name, so Pg_Heap_In

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's done.

Flavour string `doc:"PostgreSQL flavour: postgres14, pgproee14.., postgres10"`
Page int `doc:"First page number in file, default is 0"`
Segment int `doc:"Segment file number (16790.1 is 1), default is 0"`
}

type PostgresBTreeIn struct {
Page int `doc:"First page number in file, default is 0"`
}
1 change: 1 addition & 0 deletions format/postgres/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*.sh
68 changes: 68 additions & 0 deletions format/postgres/common/checksum.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
package common

import "encoding/binary"

const (
nSums = 32
fnvPrime = 16777619
nSumsSize = 4 * nSums
mainBlockLen = PageSize / nSumsSize
RelSegSize = 131072
)

var (
checksumBaseOffsets = [nSums]uint32{
0x5B1F36E9, 0xB8525960, 0x02AB50AA, 0x1DE66D2A,
0x79FF467A, 0x9BB9F8A3, 0x217E7CD2, 0x83E13D2C,
0xF8D4474F, 0xE39EB970, 0x42C6AE16, 0x993216FA,
0x7B093B5D, 0x98DAFF3C, 0xF718902A, 0x0B1C9CDB,
0xE58F764B, 0x187636BC, 0x5D7B3BB1, 0xE73DE7DE,
0x92BEC979, 0xCCA6C0B2, 0x304A0979, 0x85AA43D4,
0x783125BB, 0x6CA8EAA2, 0xE407EAC6, 0x4B5CFC3E,
0x9FBF8C76, 0x15CA20BE, 0xF2CA9FD3, 0x959BD756,
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this a well known checksum or postgres specific? The go standard library has some standard ones and fq has a checksum package with some additional ones. They all implement the hash.Hash interface. Had some plan for a while to make the decode API be able to do something generic for checksums but got complicated, maybe in the future. One things nice with hash.Hash interface design is that it embeds a io.Writer so they are meant to use used with io.Copy etc (see flac_frame)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's looks like FNV-1a. But PostgrerSQL hashes doesn't match to FNV-1a hashes in Golang.
This hash is PostgreSQL specific.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, would it be possible implement the postgres variant based on some of the fvn code in the standard library (copy the code and change it)? Thinking it would be nice to have it as a hash.Hash implementation to make it more similar to checksumming in other decoders and also prepare for more generic checksum support in the decode API.
I've thought about doing something similar to what you do now, having a struct with calculated, actual and valid fields etc and it would be used some like this: d.FieldChecksum("page_checksum", start, stop, [zeroGaps somehow?], crc32.New()) and it would take care of add a struct, fields, do all the io stuff etc.

}
)

func checksumComp(checksum uint32, value uint32) uint32 {
tmp := checksum ^ value
checksum = tmp*fnvPrime ^ (tmp >> 17)
return checksum
}

func pgChecksumBlock(page []byte) uint32 {
sums := [nSums]uint32{0}
for i := 0; i < nSums; i++ {
sums[i] = checksumBaseOffsets[i]
}
result := uint32(0)

for i := 0; i < mainBlockLen; i++ {
for j := 0; j < nSums; j++ {
v2 := binary.LittleEndian.Uint32(page[i*nSumsSize+j*4:])
sums[j] = checksumComp(sums[j], v2)
}
}

for i := 0; i < 2; i++ {
for j := 0; j < nSums; j++ {
sums[j] = checksumComp(sums[j], 0)
}
}

for i := 0; i < nSums; i++ {
result = result ^ sums[i]
}

return result
}

func CheckSumBlock(page []byte, blockNumber uint32) uint16 {
// set pd_checksum to zero
page[8] = 0
page[9] = 0

sum := pgChecksumBlock(page)
sum1 := sum ^ blockNumber
sum2 := uint16((sum1 % 65535) + 1)
return sum2
}
Loading