rolang / dumbo

Simple database migration tool for Postgres with skunk on JVM and Native
MIT License
26 stars 3 forks source link

Option to use `Typer.Strategy.BuiltinsOnly` to workaround bug in Skunk's oid codec? #42

Closed benhutchison closed 3 months ago

benhutchison commented 4 months ago

When I tried out Dumbo for the first time (on a cockroachDB database that has been working with Skunk+Flyway for a while), I hit an error. Excess stack traces are boring so I trimmed for relevance.

skunk.exception.DecodeException:
πŸ”₯
πŸ”₯  DecodeException
πŸ”₯
πŸ”₯    Problem: Decoding error.
πŸ”₯     Detail: This query's decoder was unable to decode a row of data.
πŸ”₯
πŸ”₯  The statement under consideration was defined
πŸ”₯    at Β«skunk internalΒ»:0
πŸ”₯
πŸ”₯    SELECT oid typid, typname, typarray, typrelid
πŸ”₯    FROM   pg_type
πŸ”₯    WHERE typnamespace IN (
πŸ”₯      SELECT oid
πŸ”₯      FROM   pg_namespace
πŸ”₯      WHERE nspname = ANY(current_schemas(true))
πŸ”₯    )
πŸ”₯
πŸ”₯  The row in question returned the following values (truncated to 15 chars).
πŸ”₯
πŸ”₯    typid     oid   ->  4294967108    β”œβ”€β”€ java.lang.NumberFormatException (see below)
πŸ”₯    typname   name  ->  pg_aggregate
πŸ”₯    typarray  oid   ->  0
πŸ”₯    typrelid  oid   ->  4294967108
πŸ”₯
πŸ”₯  The decoder threw the following exception:
πŸ”₯
πŸ”₯    java.lang.NumberFormatException: For input string: "4294967108"
πŸ”₯      java.base/java.lang.NumberFormatException.forInputString(NumberFormatException.java:67)
πŸ”₯      java.base/java.lang.Integer.parseInt(Integer.java:668)
πŸ”₯      java.base/java.lang.Integer.parseInt(Integer.java:786)
πŸ”₯      scala.collection.StringOps$.toInt$extension(StringOps.scala:910)
πŸ”₯      skunk.util.Typer$ProtocolOps.$init$$$anonfun$4(Typer.scala:180)
πŸ”₯      skunk.Codec$.simple$$anonfun$2(Codec.scala:113)
...

Root cause is a bug in Skunk's oid Codec, which tries to fit an unsigned Int into an Int 😱

This potentially has a lot of surface area in Skunk's Typer and may not be a straightforward fix.

As a possibly easier workaround, would you consider some config option to instead use the simpler Typer.Strategy.BuiltinsOnly in Dumbo, which IIUC won't need to hit the problematic code?

rolang commented 4 months ago

hi @benhutchison, thanks for reporting. I haven't tested it with cockroachDB before. After I just tried there seem to be other issues / incompatibilities, like with history table types and locking seem to work differently in cockroachDB. May I know what cockroachDB version you were running it with? I guess different versions may behave differently.

Making the Typer.Strategy configurable or changing the default to BuiltinsOnly should be simple, but I think there are more things that would need changing. I'd need to run some more experiments.

benhutchison commented 4 months ago

Im using CockroachDB cloud, v23.2.4

On Sun, May 5, 2024 at 12:39β€―AM Roman Langolf @.***> wrote:

hi @benhutchison https://github.com/benhutchison, thanks for reporting. I haven't tested it with cockroachDB before. After I just tried there seem to be other issues / incompatibilities, like with history table types and locking seem to work differently in cockroachDB. May I know what cockroachDB version you were running it with? I guess different versions may behave differently.

Making the Typer.Strategy configurable or changing the default to BuiltinsOnly should be simple, but I think there are more things that would need changing. I'd need to run some more experiments.

β€” Reply to this email directly, view it on GitHub https://github.com/rolang/dumbo/issues/42#issuecomment-2094224464, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAAXJZBUYIYEIUT64FCDG2LZATXJ7AVCNFSM6AAAAABHFODMOOVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDAOJUGIZDINBWGQ . You are receiving this because you were mentioned.Message ID: @.***>

rolang commented 3 months ago

@benhutchison I updated the tests to run with CockroachDB (v23.2.4), together with some compatibility updates. It's released with 0.3.2. You can give it another try. I hardcoded the Typer.Strategy to BuiltinsOnly and don't think that it'll need changing, dumbo actually doesn't need to deal with user defined types.

There are some (maybe minor) differences in behavior:

rolang commented 3 months ago

Updated skunk to 1.0.0-M6 which includes the oid fix in release 0.3.3. Going to close the issue.