Skip to content

Commit

Permalink
fix: Fix REPLICATION_STREAM_ID parsing (#1901)
Browse files Browse the repository at this point in the history
  • Loading branch information
msfstef authored Oct 29, 2024
1 parent d43c375 commit 1cf8bf9
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 7 deletions.
5 changes: 5 additions & 0 deletions .changeset/big-shoes-care.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@core/sync-service": patch
---

Fix `REPLICATION_STREAM_ID` not being able to be set because of incorrect parsing
2 changes: 1 addition & 1 deletion integration-tests/scripts/electric_dev.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ set -e
SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &> /dev/null && pwd)

cd "$SCRIPT_DIR"/../../packages/sync-service
STORAGE_DIR="$SCRIPT_DIR/../_storage" iex -S mix
STORAGE_DIR="$SCRIPT_DIR/../_storage" REPLICATION_STREAM_ID=integration iex -S mix
4 changes: 2 additions & 2 deletions integration-tests/tests/invalidated-replication-slot.lux
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
[my invalidated_slot_error=
"""
[error] GenServer Electric.Connection.Manager terminating
** (Postgrex.Error) ERROR 55000 (object_not_in_prerequisite_state) cannot read from logical replication slot "electric_slot_default"
** (Postgrex.Error) ERROR 55000 (object_not_in_prerequisite_state) cannot read from logical replication slot "electric_slot_integration"

This slot has been invalidated because it exceeded the maximum reserved size.
"""]
Expand All @@ -34,7 +34,7 @@

## Confirm slot invalidation in Postgres.
[shell pg]
?invalidating slot "electric_slot_default" because its restart_lsn [\d\w]+/[\d\w]+ exceeds max_slot_wal_keep_size
?invalidating slot "electric_slot_integration" because its restart_lsn [\d\w]+/[\d\w]+ exceeds max_slot_wal_keep_size

## Observe the fatal connection error.
[shell electric]
Expand Down
8 changes: 4 additions & 4 deletions integration-tests/tests/rolling-deploy.lux
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
[invoke setup_electric_shell "electric_1" "3000" ""]

[shell electric_1]
??[info] Acquiring lock from postgres with name electric_slot_default
??[info] Lock acquired from postgres with name electric_slot_default
??[info] Acquiring lock from postgres with name electric_slot_integration
??[info] Lock acquired from postgres with name electric_slot_integration
??[info] Starting replication from postgres

# First service should be health and active
Expand All @@ -29,7 +29,7 @@
## in the second electric
[shell electric_2]
-Lock acquired from postgres|Starting replication from postgres|$fail_pattern
??[info] Acquiring lock from postgres with name electric_slot_default
??[info] Acquiring lock from postgres with name electric_slot_integration
[sleep 2]


Expand All @@ -50,7 +50,7 @@
## Lock should now be acquired and replication starting
[shell electric_2]
-$fail_pattern
??[info] Lock acquired from postgres with name electric_slot_default
??[info] Lock acquired from postgres with name electric_slot_integration
??[info] Starting replication from postgres

# Second service is now healthy and active
Expand Down
14 changes: 14 additions & 0 deletions packages/sync-service/lib/electric/postgres/identifiers.ex
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,20 @@ defmodule Electric.Postgres.Identifiers do
else: {:ok, unescape_quotes(ident)}
end

@doc """
Parse an unquoted PostgreSQL identifier, downcasing characters and failing if any
special characters are present
## Examples
iex> Electric.Postgres.Identifiers.parse_unquoted_identifier("FooBar")
{:ok, "foobar"}
iex> Electric.Postgres.Identifiers.parse_unquoted_identifier("foob@r")
{:error, ~S|Invalid unquoted identifier contains special characters: foob@r|}
"""
@spec parse(binary(), boolean(), boolean()) :: {:ok, binary()} | {:error, term()}
def parse_unquoted_identifier(ident, truncate \\ false, single_byte_encoding \\ false)

def parse_unquoted_identifier("", _, _), do: parse_quoted_identifier("")

def parse_unquoted_identifier(ident, truncate, single_byte_encoding) do
Expand Down

0 comments on commit 1cf8bf9

Please sign in to comment.