This repository was archived by the owner on Apr 26, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Use a sequence to generate AS transaction IDs, drop last_txn AS state
#12209
Merged
richvdh
merged 14 commits into
matrix-org:develop
from
Fizzadar:use-sequence-for-appservice-transactions
Apr 1, 2022
Merged
Changes from 12 commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
d272a69
Use a sequence to generate AS transaction IDs, drop `last_txn` AS state
Fizzadar cceb2b9
Show warning when running slow AS sequence query
Fizzadar 722f6ce
Restore writing AS state `last_txn` for this release
Fizzadar 81f5220
Add changelog file
Fizzadar 6d35ceb
Fix database variable
Fizzadar ccc2e63
Update AS storage tests for new sequence generated TXN IDs
Fizzadar ca0daba
Add database migration to create postgres sequence
Fizzadar ca4a78a
Lint migration
Fizzadar c9c0b06
Remove AS txn sequence test as tested elsewhere
Fizzadar c919194
Merge branch 'develop' into use-sequence-for-appservice-transactions
Fizzadar d62adee
Update DB schema migration to version 69
Fizzadar 175f4d3
Update changelog w/note about shutting AS worker down before upgrade
Fizzadar 5803f05
Update changelog.d/12209.misc
richvdh 226820b
Add notes to upgrade.md
richvdh File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 @@ | ||
| Switch to using a sequence to generate AS transaction IDs. Contributed by Nick Beeper. If running synapse with a dedicated appservice worker, this MUST be shutdown before upgrading the main process and database. | ||
This file contains hidden or 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 hidden or 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 hidden or 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,44 @@ | ||
| # Copyright 2022 Beeper | ||
| # | ||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
|
|
||
|
|
||
| """ | ||
| Adds a postgres SEQUENCE for generating application service transaction IDs. | ||
| """ | ||
|
|
||
| from synapse.storage.engines import PostgresEngine | ||
|
|
||
|
|
||
| def run_create(cur, database_engine, *args, **kwargs): | ||
| if isinstance(database_engine, PostgresEngine): | ||
| # If we already have some AS TXNs we want to start from the current | ||
| # maximum value. There are two potential places this is stored - the | ||
| # actual TXNs themselves *and* the AS state table. At time of migration | ||
| # it is possible the TXNs table is empty so we must include the AS state | ||
| # last_txn as a potential option, and pick the maximum. | ||
|
|
||
| cur.execute("SELECT COALESCE(max(txn_id), 0) FROM application_services_txns") | ||
| row = cur.fetchone() | ||
| txn_max = row[0] | ||
|
|
||
| cur.execute("SELECT COALESCE(max(last_txn), 0) FROM application_services_state") | ||
| row = cur.fetchone() | ||
| last_txn_max = row[0] | ||
|
|
||
| start_val = max(last_txn_max, txn_max) + 1 | ||
|
|
||
| cur.execute( | ||
| "CREATE SEQUENCE application_services_txn_id_seq START WITH %s", | ||
| (start_val,), | ||
| ) |
This file contains hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.