Skip to content

Commit b2e67d8

Browse files
authored
feat: allow GSI names to be configured explicitly (#89)
1 parent 3aa6c93 commit b2e67d8

File tree

4 files changed

+38
-10
lines changed

4 files changed

+38
-10
lines changed

core/src/main/resources/reference.conf

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,14 @@ akka.persistence.dynamodb {
77
# name of the table to use for events
88
table = "event_journal"
99

10+
# Name of global secondary index to support queries and/or projections.
11+
# "" is the default and denotes an index named "${table}_slice_idx"
12+
# (viz. when table (see above) is "event_journal", the GSI will be
13+
# "event_journal_slice_idx"). If for some reason an alternative GSI name
14+
# is required, set that GSI name explicitly here; if set explicitly, this
15+
# name will be used unmodified
16+
by-slice-idx = ""
17+
1018
# Set this to off to disable publishing of events as Akka messages to running
1119
# eventsBySlices queries.
1220
# Tradeoff is more CPU and network resources that are used. The events
@@ -56,6 +64,14 @@ akka.persistence.dynamodb {
5664
# name of the table to use for snapshots
5765
table = "snapshot"
5866

67+
# Name of global secondary index to support queries and/or projections.
68+
# "" is the default and denotes an index named "${table}_slice_idx"
69+
# (viz. when table (see above) is "event_journal", the GSI will be
70+
# "event_journal_slice_idx"). If for some reason an alternative GSI name
71+
# is required, set that GSI name explicitly here; if set explicitly, this
72+
# name will be used unmodified
73+
by-slice-idx = ""
74+
5975
# Enables an optimization in Akka for avoiding snapshot deletes in retention.
6076
only-one-snapshot = true
6177
}

core/src/main/scala/akka/persistence/dynamodb/DynamoDBSettings.scala

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,13 +45,25 @@ object DynamoDBSettings {
4545

4646
val timeToLiveSettings = new TimeToLiveSettings(config.getConfig("time-to-live"))
4747

48+
val journalBySliceGsi = {
49+
val indexName = config.getString("journal.by-slice-idx")
50+
if (indexName.nonEmpty) indexName else journalTable + "_slice_idx"
51+
}
52+
53+
val snapshotBySliceGsi = {
54+
val indexName = config.getString("snapshot.by-slice-idx")
55+
if (indexName.nonEmpty) indexName else snapshotTable + "_slice_idx"
56+
}
57+
4858
new DynamoDBSettings(
4959
journalTable,
5060
journalPublishEvents,
5161
snapshotTable,
5262
querySettings,
5363
cleanupSettings,
54-
timeToLiveSettings)
64+
timeToLiveSettings,
65+
journalBySliceGsi,
66+
snapshotBySliceGsi)
5567
}
5668

5769
/**
@@ -68,11 +80,9 @@ final class DynamoDBSettings private (
6880
val snapshotTable: String,
6981
val querySettings: QuerySettings,
7082
val cleanupSettings: CleanupSettings,
71-
val timeToLiveSettings: TimeToLiveSettings) {
72-
73-
val journalBySliceGsi: String = journalTable + "_slice_idx"
74-
val snapshotBySliceGsi: String = snapshotTable + "_slice_idx"
75-
}
83+
val timeToLiveSettings: TimeToLiveSettings,
84+
val journalBySliceGsi: String,
85+
val snapshotBySliceGsi: String)
7686

7787
final class QuerySettings(config: Config) {
7888
val refreshInterval: FiniteDuration = config.getDuration("refresh-interval").toScala

docs/src/main/paradox/journal.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,9 @@ An example `aws` CLI command for creating the event journal table:
2424
### Indexes
2525

2626
If @ref:[queries](query.md) or @ref:[projections](projection.md) are being used, then a global secondary index needs to
27-
be added to the event journal table, to index events by slice. The default name for the secondary index is
28-
`event_journal_slice_idx`. The following attribute definitions should be added to the event journal table, with key
27+
be added to the event journal table, to index events by slice. The default name (derived from the configured @ref:[table name](#tables))
28+
for the secondary index is `event_journal_slice_idx` and may be explicitly set (see the
29+
@ref:[reference configuration](#reference-configuration)). The following attribute definitions should be added to the event journal table, with key
2930
schema for the event journal slice index:
3031

3132
| Attribute name | Attribute type | Key type |

docs/src/main/paradox/snapshots.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,9 @@ An example `aws` CLI command for creating the snapshot table:
2323
### Indexes
2424

2525
If @ref:[start-from-snapshot queries](query.md#eventsbyslicesstartingfromsnapshots) are being used, then a global
26-
secondary index needs to be added to the snapshot table, to index snapshots by slice. The default name for the
27-
secondary index is `snapshot_slice_idx`. The following attribute definitions should be added to the snapshot table,
26+
secondary index needs to be added to the snapshot table, to index snapshots by slice. The default name (derived from
27+
the configured @ref:[table name](#tables)) for the secondary index is `snapshot_slice_idx` and may be explicitly set
28+
(see the @ref:[reference configuration](#reference-configuration)). The following attribute definitions should be added to the snapshot table,
2829
with key schema for the snapshot slice index:
2930

3031
| Attribute name | Attribute type | Key type |

0 commit comments

Comments
 (0)