Skip to content

Commit

Permalink
Switch to H2 BINARY LARGE OBJECT to work around a limitation with BYT…
Browse files Browse the repository at this point in the history
…EA (#12334)

CHANGELOG_BEGIN
CHANGELOG_END
  • Loading branch information
nmarton-da authored Jan 11, 2022
1 parent fdee5cb commit c8753b5
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 20 deletions.
Original file line number Diff line number Diff line change
@@ -1 +1 @@
efdb7e3932363e223f1ead19bf4b2e69ca1acafcf26380ee9010b020981d21d9
8f22abf50be616e45c6a8cb4069ebbac2f90c048337c73ede365869dec006fce
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ CREATE TABLE configuration_entries (
recorded_at BIGINT NOT NULL,
submission_id VARCHAR NOT NULL,
typ VARCHAR NOT NULL,
configuration BYTEA NOT NULL,
configuration BINARY LARGE OBJECT NOT NULL,
rejection_reason VARCHAR,

CONSTRAINT configuration_entries_check_reason
Expand All @@ -46,7 +46,7 @@ CREATE TABLE packages (
package_size BIGINT NOT NULL,
known_since BIGINT NOT NULL,
ledger_offset VARCHAR NOT NULL,
package BYTEA NOT NULL
package BINARY LARGE OBJECT NOT NULL
);

CREATE INDEX idx_packages_ledger_offset ON packages (ledger_offset);
Expand Down Expand Up @@ -132,7 +132,7 @@ CREATE TABLE participant_command_completions (
-- (decided by the ledger driver), and may be `NULL` even if the other two columns are set.
rejection_status_code INTEGER,
rejection_status_message VARCHAR,
rejection_status_details BYTEA
rejection_status_details BINARY LARGE OBJECT
);

CREATE INDEX participant_command_completion_offset_application_idx ON participant_command_completions (completion_offset, application_id);
Expand Down Expand Up @@ -161,7 +161,7 @@ CREATE TABLE participant_events_divulgence (
tree_event_witnesses INTEGER ARRAY NOT NULL DEFAULT ARRAY[], -- informees

-- * contract data
create_argument BYTEA,
create_argument BINARY LARGE OBJECT,

-- * compression flags
create_argument_compression SMALLINT
Expand Down Expand Up @@ -207,11 +207,11 @@ CREATE TABLE participant_events_create (
tree_event_witnesses INTEGER ARRAY NOT NULL DEFAULT ARRAY[], -- informees

-- * contract data
create_argument BYTEA NOT NULL,
create_argument BINARY LARGE OBJECT NOT NULL,
create_signatories INTEGER ARRAY NOT NULL,
create_observers INTEGER ARRAY NOT NULL,
create_agreement_text VARCHAR,
create_key_value BYTEA,
create_key_value BINARY LARGE OBJECT,
create_key_hash VARCHAR,

-- * compression flags
Expand Down Expand Up @@ -268,12 +268,12 @@ CREATE TABLE participant_events_consuming_exercise (
tree_event_witnesses INTEGER ARRAY NOT NULL DEFAULT ARRAY[], -- informees

-- * information about the corresponding create event
create_key_value BYTEA, -- used for the mutable state cache
create_key_value BINARY LARGE OBJECT, -- used for the mutable state cache

-- * choice data
exercise_choice VARCHAR NOT NULL,
exercise_argument BYTEA NOT NULL,
exercise_result BYTEA,
exercise_argument BINARY LARGE OBJECT NOT NULL,
exercise_result BINARY LARGE OBJECT,
exercise_actors INTEGER ARRAY NOT NULL,
exercise_child_event_ids VARCHAR ARRAY NOT NULL,

Expand Down Expand Up @@ -329,12 +329,12 @@ CREATE TABLE participant_events_non_consuming_exercise (
tree_event_witnesses INTEGER ARRAY NOT NULL DEFAULT ARRAY[], -- informees

-- * information about the corresponding create event
create_key_value BYTEA, -- used for the mutable state cache
create_key_value BINARY LARGE OBJECT, -- used for the mutable state cache

-- * choice data
exercise_choice VARCHAR NOT NULL,
exercise_argument BYTEA NOT NULL,
exercise_result BYTEA,
exercise_argument BINARY LARGE OBJECT NOT NULL,
exercise_result BINARY LARGE OBJECT,
exercise_actors INTEGER ARRAY NOT NULL,
exercise_child_event_ids VARCHAR ARRAY NOT NULL,

Expand Down Expand Up @@ -390,11 +390,11 @@ SELECT
NULL::INTEGER ARRAY as create_signatories,
NULL::INTEGER ARRAY as create_observers,
NULL::VARCHAR as create_agreement_text,
NULL::BYTEA as create_key_value,
NULL::BINARY LARGE OBJECT as create_key_value,
NULL::VARCHAR as create_key_hash,
NULL::VARCHAR as exercise_choice,
NULL::BYTEA as exercise_argument,
NULL::BYTEA as exercise_result,
NULL::BINARY LARGE OBJECT as exercise_argument,
NULL::BINARY LARGE OBJECT as exercise_result,
NULL::INTEGER ARRAY as exercise_actors,
NULL::VARCHAR ARRAY as exercise_child_event_ids,
create_argument_compression,
Expand Down Expand Up @@ -426,8 +426,8 @@ SELECT
create_key_value,
create_key_hash,
NULL::VARCHAR as exercise_choice,
NULL::BYTEA as exercise_argument,
NULL::BYTEA as exercise_result,
NULL::BINARY LARGE OBJECT as exercise_argument,
NULL::BINARY LARGE OBJECT as exercise_result,
NULL::INTEGER ARRAY as exercise_actors,
NULL::VARCHAR ARRAY as exercise_child_event_ids,
create_argument_compression,
Expand All @@ -452,7 +452,7 @@ SELECT
template_id,
flat_event_witnesses,
tree_event_witnesses,
NULL::BYTEA as create_argument,
NULL::BINARY LARGE OBJECT as create_argument,
NULL::INTEGER ARRAY as create_signatories,
NULL::INTEGER ARRAY as create_observers,
NULL::VARCHAR as create_agreement_text,
Expand Down Expand Up @@ -485,7 +485,7 @@ SELECT
template_id,
flat_event_witnesses,
tree_event_witnesses,
NULL::BYTEA as create_argument,
NULL::BINARY LARGE OBJECT as create_argument,
NULL::INTEGER ARRAY as create_signatories,
NULL::INTEGER ARRAY as create_observers,
NULL::VARCHAR as create_agreement_text,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

package com.daml.platform.store.backend.h2

import java.io.{ByteArrayInputStream, InputStream}

import com.daml.platform.store.backend.common.Field
import com.daml.platform.store.interning.StringInterning

Expand All @@ -17,3 +19,15 @@ private[h2] case class IntArrayOptional[FROM](
override def convert: Option[Iterable[Int]] => Array[java.lang.Integer] =
_.map(_.view.map(Int.box).toArray).orNull
}

private[h2] case class H2Bytea[FROM](extract: StringInterning => FROM => Array[Byte])
extends Field[FROM, Array[Byte], InputStream] {
override def convert: Array[Byte] => InputStream = new ByteArrayInputStream(_)
}

private[h2] case class H2ByteaOptional[FROM](
extract: StringInterning => FROM => Option[Array[Byte]]
) extends Field[FROM, Option[Array[Byte]], InputStream] {
override def convert: Option[Array[Byte]] => InputStream =
_.map(new ByteArrayInputStream(_)).orNull
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,16 @@ private[h2] object H2Schema {
): Field[FROM, Option[Iterable[Int]], _] =
IntArrayOptional(extractor)

override def bytea[FROM, _](
extractor: StringInterning => FROM => Array[Byte]
): Field[FROM, Array[Byte], _] =
H2Bytea(extractor)

override def byteaOptional[FROM, _](
extractor: StringInterning => FROM => Option[Array[Byte]]
): Field[FROM, Option[Array[Byte]], _] =
H2ByteaOptional(extractor)

override def insert[FROM](tableName: String)(
fields: (String, Field[FROM, _, _])*
): Table[FROM] =
Expand Down

0 comments on commit c8753b5

Please sign in to comment.