-
Notifications
You must be signed in to change notification settings - Fork 219
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
Postgres #415
Changes from 148 commits
f069ddc
7d36eee
9a96da8
8cf83fb
d4f8dfa
0107d12
3b81d99
c8ece64
deaf5ef
2b1bdfb
8d317dd
af0e220
441ecee
fcd7fbc
bebdfa9
51878dc
ce9ae76
01b380e
3c6ea87
850dc60
6ed0263
ffd7c9b
96a86e2
2d3884a
d8b891c
fdb3b3e
f5278f3
0327411
6618e76
b4ae1d5
96a96a5
d9de2d4
b722b21
c273a6c
621c4c4
a653710
ffc08cf
972c5a3
07056c2
d148727
e4ba72f
2b3035f
7bf6b11
9570d4d
cf1e7b2
f56c72d
b4c4de2
2ee01f7
9f5036a
08eb303
d588605
4db1284
666bbfb
ba8b90b
3e09f9f
ccf2edb
1e24d70
5eea605
ff4b6fd
f224ed0
85c0422
c2591ac
586c803
1d9ef30
6281b50
8f57ebf
dc6ed54
8e27e30
e311434
e66baa7
067f8d5
448c369
09c42c3
d7bcca0
f122f72
dd84d32
22a6cfa
d370f5d
87b7acf
f3f259a
efda7b3
00de0a9
edb5650
9f1adb2
7dd7dbe
c3ef341
35124bf
7b52149
7f219d8
ae838b9
296ce68
94e5b79
90386a6
de3ecf1
b06c9bc
9deab2e
7858373
e57c3b9
6588e1d
12b8697
03d8fe1
46e1e33
4676590
e06fa6e
bedc480
6fe5f05
2423f86
1aa08e3
939c7c1
83d63c5
dd9c7f0
8f55e17
5ff6273
9f61e63
f4408fb
6aed238
a4c1c5b
c105fcd
b09ec2f
26bff14
7c1dfbd
7c92715
bd2bdd6
7dedcba
fb7778a
e8d8cac
d7a0f93
069babb
7f7f729
de68785
3c7ed5d
7fd4109
6e2e44d
721c1ab
a4d904e
cdf2831
9c7f20b
e87d5a6
5bb8654
5664c0a
e8bb169
015b770
60709e5
dafbf4b
6fe61cd
0ea20e6
97bbc22
bffa008
c9b263e
bb2659d
e5f15c5
9508a20
f6f8d5c
7a89234
08c5352
c23bc42
e839191
c9350de
e6a9cdb
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
.DS_Store | ||
testfiles/ | ||
fq | ||
.idea |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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"} There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's done |
||
PNG = "png" | ||
PRORES_FRAME = "prores_frame" | ||
PROTOBUF = "protobuf" | ||
|
@@ -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 { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The name convention i've settle on for in/out struct is There was a problem hiding this comment. Choose a reason for hiding this commentThe 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"` | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
*.sh |
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, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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) There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||
} | ||
) | ||
|
||
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 | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
pg_wal was removed?
There was a problem hiding this comment.
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.