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

pg2k4j fails when xids are between 32-bit int max and unsigned 32-bit int max #24

Closed
teej opened this issue May 28, 2019 · 5 comments
Closed

Comments

@teej
Copy link

teej commented May 28, 2019

Postgres transaction IDs are of type xid, unsigned 32-bit int. pg2k4j assumes they are signed 32-bit ints https://github.com/disneystreaming/pg2k4j/blob/master/src/main/java/com/disneystreaming/pg2k4j/models/SlotMessage.java#L35. This causes JSON parsing of WAL messages into SlotMessage to fail with com.fasterxml.jackson.core.JsonParseException: Numeric value (...) out of range of int when a there's an xid between signed 32bit int max and unsigned 32bit int max.

@teej
Copy link
Author

teej commented May 29, 2019

I don’t know enough Java to suggest a fix, but switching to long works for me locally.

@rkass
Copy link
Contributor

rkass commented Jun 3, 2019

Thanks for submitting @teej we'll get this looked at and fixed this week.

@rkass
Copy link
Contributor

rkass commented Jun 3, 2019

@teej you're right it does seem that postgres uses unsigned ints for the transaction id field, though I had a tough time finding that info in any postgres documentation. I found this which indicates that the transaction id is unsigned but this seems far from official: http://www.interdb.jp/pg/pgsql05.html . If you found any official documentation that says this please point me in that direction.

See this pr for a fix #26 . This pr just changes the xid field from an int to a long as you suggested

@teej
Copy link
Author

teej commented Jun 3, 2019

The official Postrgres documentation calls them "32-bit quantities"

Another identifier type used by the system is xid, or transaction (abbreviated xact) identifier. This is the data type of the system columns xmin and xmax. Transaction identifiers are 32-bit quantities.

https://www.postgresql.org/docs/current/datatype-oid.html

The Postgres source defines TransactionId as type uint32 https://github.com/postgres/postgres/blob/REL_11_0/src/include/c.h#L474

I wish their documentation was less ambiguous but that's what I've got for ya. Thanks for the fix!

@rkass
Copy link
Contributor

rkass commented Jun 3, 2019

This issue is fixed in the latest release https://github.com/disneystreaming/pg2k4j/releases/tag/1.0.6 . Please reopen if you see it again and great catch!

@rkass rkass closed this as completed Jun 3, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants