Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow GSI names to be configured explicitly #89

Merged
merged 2 commits into from
Oct 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions core/src/main/resources/reference.conf
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,14 @@ akka.persistence.dynamodb {
# name of the table to use for events
table = "event_journal"

# Name of global secondary index to support queries and/or projections.
# "" is the default and denotes an index named "${table}_slice_idx"
# (viz. when table (see above) is "event_journal", the GSI will be
# "event_journal_slice_idx"). If for some reason an alternative GSI name
# is required, set that GSI name explicitly here; if set explicitly, this
# name will be used unmodified
by-slice-idx = ""

# Set this to off to disable publishing of events as Akka messages to running
# eventsBySlices queries.
# Tradeoff is more CPU and network resources that are used. The events
Expand Down Expand Up @@ -56,6 +64,14 @@ akka.persistence.dynamodb {
# name of the table to use for snapshots
table = "snapshot"

# Name of global secondary index to support queries and/or projections.
# "" is the default and denotes an index named "${table}_slice_idx"
# (viz. when table (see above) is "event_journal", the GSI will be
# "event_journal_slice_idx"). If for some reason an alternative GSI name
# is required, set that GSI name explicitly here; if set explicitly, this
# name will be used unmodified
by-slice-idx = ""

# Enables an optimization in Akka for avoiding snapshot deletes in retention.
only-one-snapshot = true
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,25 @@ object DynamoDBSettings {

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

val journalBySliceGsi = {
val indexName = config.getString("journal.by-slice-idx")
if (indexName.nonEmpty) indexName else journalTable + "_slice_idx"
}

val snapshotBySliceGsi = {
val indexName = config.getString("snapshot.by-slice-idx")
if (indexName.nonEmpty) indexName else snapshotTable + "_slice_idx"
}

new DynamoDBSettings(
journalTable,
journalPublishEvents,
snapshotTable,
querySettings,
cleanupSettings,
timeToLiveSettings)
timeToLiveSettings,
journalBySliceGsi,
snapshotBySliceGsi)
}

/**
Expand All @@ -68,11 +80,9 @@ final class DynamoDBSettings private (
val snapshotTable: String,
val querySettings: QuerySettings,
val cleanupSettings: CleanupSettings,
val timeToLiveSettings: TimeToLiveSettings) {

val journalBySliceGsi: String = journalTable + "_slice_idx"
val snapshotBySliceGsi: String = snapshotTable + "_slice_idx"
}
val timeToLiveSettings: TimeToLiveSettings,
val journalBySliceGsi: String,
val snapshotBySliceGsi: String)

final class QuerySettings(config: Config) {
val refreshInterval: FiniteDuration = config.getDuration("refresh-interval").toScala
Expand Down
5 changes: 3 additions & 2 deletions docs/src/main/paradox/journal.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,9 @@ An example `aws` CLI command for creating the event journal table:
### Indexes

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

| Attribute name | Attribute type | Key type |
Expand Down
5 changes: 3 additions & 2 deletions docs/src/main/paradox/snapshots.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,9 @@ An example `aws` CLI command for creating the snapshot table:
### Indexes

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

| Attribute name | Attribute type | Key type |
Expand Down
Loading