-
Notifications
You must be signed in to change notification settings - Fork 205
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add string-interning data access [DPP-707]
* Add new table, and party_id to party_entries * Add write side basics (DbDto, Schema) * Add read side basic (StorageBackendStringInterning) * Add StorageBackend unit test * Support for all DB backends changelog_begin changelog_end
- Loading branch information
1 parent
d8898b8
commit d441a1f
Showing
16 changed files
with
157 additions
and
12 deletions.
There are no files selected for viewing
2 changes: 1 addition & 1 deletion
2
...n-api/src/main/resources/db/migration/h2database-appendonly/V1__Append_only_schema.sha256
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
86ded6839752d76bb3e3e6cde7f4ec103dea6cee6382b6695de95e84dd74d2da | ||
5e5e023d57d3b0b5a4ab83d9e370597fe98a1b7b4fbb114b94326d7779a8ffe7 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
...ion-api/src/main/resources/db/migration/oracle-appendonly/V3__Add_string_interning.sha256
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
226c3fbed157c8804d004f61996d855dd34132987a70b387cd5d38f070586f63 |
12 changes: 12 additions & 0 deletions
12
...ration-api/src/main/resources/db/migration/oracle-appendonly/V3__Add_string_interning.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
-- Copyright (c) 2021 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved. | ||
-- SPDX-License-Identifier: Apache-2.0 | ||
|
||
CREATE TABLE string_interning ( | ||
id NUMBER PRIMARY KEY NOT NULL, | ||
s VARCHAR2(4000) | ||
); | ||
|
||
ALTER TABLE party_entries | ||
ADD party_id NUMBER DEFAULT 0 NOT NULL; -- needed for efficient pruning, will be filled later | ||
|
||
CREATE INDEX idx_party_entries_party_id_and_ledger_offset ON party_entries(party_id, ledger_offset); |
1 change: 1 addition & 0 deletions
1
...api/src/main/resources/db/migration/postgres-appendonly/V112__add_string_interning.sha256
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
44d1b18342edd67f6c9be31ec8b1dffd37ac37cce7bb5a6bcf5f822aae6df51a |
12 changes: 12 additions & 0 deletions
12
...on-api/src/main/resources/db/migration/postgres-appendonly/V112__add_string_interning.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
-- Copyright (c) 2021 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved. | ||
-- SPDX-License-Identifier: Apache-2.0 | ||
|
||
CREATE TABLE string_interning ( | ||
id integer PRIMARY KEY NOT NULL, | ||
s text | ||
); | ||
|
||
ALTER TABLE party_entries | ||
ADD column party_id integer NOT NULL DEFAULT 0; -- needed for efficient pruning, will be filled later | ||
|
||
CREATE INDEX idx_party_entries_party_id_and_ledger_offset ON party_entries(party_id, ledger_offset); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
.../src/main/scala/platform/store/backend/common/StringInterningStorageBackendTemplate.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
// Copyright (c) 2021 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package com.daml.platform.store.backend.common | ||
|
||
import java.sql.Connection | ||
|
||
import anorm.SqlParser.{int, str} | ||
import anorm.{RowParser, SqlStringInterpolation, ~} | ||
import com.daml.platform.store.backend.StringInterningStorageBackend | ||
import com.daml.platform.store.SimpleSqlAsVectorOf.SimpleSqlAsVectorOf | ||
|
||
trait StringInterningStorageBackendTemplate extends StringInterningStorageBackend { | ||
|
||
private val StringInterningEntriesParser: RowParser[(Int, String)] = | ||
int("id") ~ str("s") map { case id ~ s => | ||
(id, s) | ||
} | ||
|
||
override def loadStringInterningEntries(fromIdExclusive: Int, untilIdInclusive: Int)( | ||
connection: Connection | ||
): Iterable[(Int, String)] = | ||
SQL""" | ||
SELECT id, s | ||
FROM string_interning | ||
WHERE | ||
id > $fromIdExclusive | ||
AND id <= $untilIdInclusive | ||
""".asVectorOf(StringInterningEntriesParser)(connection) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
...on-api/src/test/lib/scala/platform/store/backend/StorageBackendTestsStringInterning.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
// Copyright (c) 2021 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package com.daml.platform.store.backend | ||
|
||
import org.scalatest.Inside | ||
import org.scalatest.flatspec.AsyncFlatSpec | ||
import org.scalatest.matchers.should.Matchers | ||
|
||
private[backend] trait StorageBackendTestsStringInterning | ||
extends Matchers | ||
with Inside | ||
with StorageBackendSpec { | ||
this: AsyncFlatSpec => | ||
|
||
behavior of "StorageBackend (StringInterning)" | ||
|
||
it should "store and load string-interning entries" in { | ||
val dtos = Vector( | ||
DbDto.StringInterningDto(2, "a"), | ||
DbDto.StringInterningDto(3, "b"), | ||
DbDto.StringInterningDto(4, "c"), | ||
DbDto.StringInterningDto(5, "d"), | ||
) | ||
|
||
for { | ||
interningIdsBeforeBegin <- executeSql(backend.loadStringInterningEntries(0, 5)) | ||
_ <- executeSql(ingest(dtos, _)) | ||
interningIdsFull <- executeSql(backend.loadStringInterningEntries(0, 5)) | ||
interningIdsOverFetch <- executeSql(backend.loadStringInterningEntries(0, 10)) | ||
interningIdsEmpty <- executeSql(backend.loadStringInterningEntries(5, 10)) | ||
interningIdsSubset <- executeSql(backend.loadStringInterningEntries(3, 10)) | ||
} yield { | ||
val expectedFullList = List( | ||
2 -> "a", | ||
3 -> "b", | ||
4 -> "c", | ||
5 -> "d", | ||
) | ||
interningIdsBeforeBegin shouldBe Nil | ||
interningIdsFull shouldBe expectedFullList | ||
interningIdsOverFetch shouldBe expectedFullList | ||
interningIdsEmpty shouldBe Nil | ||
interningIdsSubset shouldBe expectedFullList.drop(2) | ||
} | ||
} | ||
} |