Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

Update synapse_port_db for new sequences #15965

Closed
wants to merge 1 commit into from

Conversation

vanguacamolie
Copy link

@vanguacamolie vanguacamolie commented Jul 20, 2023

This makes sure we that the port script sets up the application_services_txns sequence (#12209). and the un_partial_stated_event_stream_sequence sequence (#14545), which fixes errors like the one below from appearing when trying to connect to the postgresql database after running the script:

Postgres sequence 'application_services_txn_id_seq' is inconsistent with associated
table 'application_services_txns'. This can happen if Synapse has been downgraded and
then upgraded again, or due to a bad migration.

To fix this error, shut down Synapse (including any and all workers)
and run the following SQL:

    SELECT setval('application_services_txn_id_seq', (
        SELECT GREATEST(MAX(txn_id), 0) FROM application_services_txns
    ));

See docs/postgres.md for more information.

Pull Request Checklist

  • Pull request is based on the develop branch
  • Pull request includes a changelog file. The entry should:
    • Be a short description of your change which makes sense to users. "Fixed a bug that prevented receiving messages from other servers." instead of "Moved X method from EventStore to EventWorkerStore.".
    • Use markdown where necessary, mostly for code blocks.
    • End with either a period (.) or an exclamation mark (!).
    • Start with a capital letter.
    • Feel free to credit yourself, by adding a sentence "Contributed by @github_username." or "Contributed by [Your Name]." to the end of the entry.
  • Pull request includes a sign off
  • Code style is correct
    (run the linters)

@vanguacamolie vanguacamolie requested a review from a team as a code owner July 20, 2023 00:14
This makes sure we that the port script sets up the
"application_services_txns" sequence (matrix-org#12209). and the
"un_partial_stated_event_stream_sequence" sequence (matrix-org#14545), which fixes
errors like the one below from appearing when trying to connect to the
postgresql database after running the script:

    Postgres sequence 'application_services_txn_id_seq' is inconsistent with associated
    table 'application_services_txns'. This can happen if Synapse has been downgraded and
    then upgraded again, or due to a bad migration.

    To fix this error, shut down Synapse (including any and all workers)
    and run the following SQL:

        SELECT setval('application_services_txn_id_seq', (
            SELECT GREATEST(MAX(txn_id), 0) FROM application_services_txns
        ));

    See docs/postgres.md for more information.

Signed-off-by: Guacamolie <guac@amolie.nl>
Comment on lines +1150 to +1160
def r(txn: LoggingTransaction) -> None:
txn.execute(
"ALTER SEQUENCE application_services_txn_id_seq RESTART WITH %s",
(curr_tnx_id + 1,),
)

if curr_tnx_id is not None:
await self.postgres_store.db_pool.runInteraction(
"_setup_application_services_sequence",
r,
)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this will fix the mypy issue:

Suggested change
def r(txn: LoggingTransaction) -> None:
txn.execute(
"ALTER SEQUENCE application_services_txn_id_seq RESTART WITH %s",
(curr_tnx_id + 1,),
)
if curr_tnx_id is not None:
await self.postgres_store.db_pool.runInteraction(
"_setup_application_services_sequence",
r,
)
if curr_tnx_id is not None:
def r(txn: LoggingTransaction) -> None:
txn.execute(
"ALTER SEQUENCE application_services_txn_id_seq RESTART WITH %s",
(curr_tnx_id + 1,),
)
await self.postgres_store.db_pool.runInteraction(
"_setup_application_services_sequence",
r,
)

Comment on lines +1142 to +1144
curr_tnx_id: Optional[
int
] = await self.sqlite_store.db_pool.simple_select_one_onecol(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this ever really None since we have the coalesce?

@clokep clokep changed the title teach synapse_port_db about new sequences Update synapse_port_db for new sequences Aug 1, 2023
@clokep
Copy link
Member

clokep commented Aug 1, 2023

@vanguacamolie Are you interested in updating this branch? If not, can you mark it as allowing edits by maintainers?

@clokep
Copy link
Member

clokep commented Aug 1, 2023

#16043 is a simpler version of this.

@clokep clokep closed this Aug 1, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants