Avoid using setBinaryStream to not confuse H2 (#5474)

There have been reports of sporadic occurrences of
`java.lang.RuntimeException: Lob not found: 49/-2`
when running the participant server with H2.

It seems like using `setBinaryStream` triggers H2 to go through the BLOB
machinery. Since this issue is not easily reproducible, it seems like an
altogether better solution to switch to using `setBytes`. Offsets aren't
that large anyway, so going directly for byte array should be fine.
Better than a broken query anway.

CHANGELOG_BEGIN
CHANGELOG_END
This commit is contained in:
Gerolf Seitz 2020-04-07 21:07:09 +02:00 committed by GitHub
parent 26f073bda7
commit a9755cb852
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -3,7 +3,6 @@
package com.daml.platform.store
import java.io.InputStream
import java.sql.PreparedStatement
import java.time.Instant
import java.util.Date
@ -152,14 +151,14 @@ object Conversions {
implicit def offsetToStatement: ToStatement[Offset] = new ToStatement[Offset] {
override def set(s: PreparedStatement, index: Int, v: Offset): Unit =
s.setBinaryStream(index, v.toInputStream)
s.setBytes(index, v.toByteArray)
}
def offset(name: String): RowParser[Offset] =
SqlParser.get[InputStream](name).map(Offset.fromInputStream)
SqlParser.get[Array[Byte]](name).map(Offset.fromByteArray)
implicit def columnToOffset(implicit c: Column[InputStream]): Column[Offset] =
Column.nonNull((value: Any, meta) => c(value, meta).toEither.map(Offset.fromInputStream))
implicit def columnToOffset(implicit c: Column[Array[Byte]]): Column[Offset] =
Column.nonNull((value: Any, meta) => c(value, meta).toEither.map(Offset.fromByteArray))
// Instant