summary refs log tree commit diff
diff options
context:
space:
mode:
authorAndrew Morgan <andrew@amorgan.xyz>2020-03-20 14:42:18 +0000
committerAndrew Morgan <andrew@amorgan.xyz>2020-03-20 14:42:18 +0000
commit8468c90dfe1a699b154c8870f0dc3561a0105510 (patch)
tree0631b946647e728d4d01359c009344017bdaf138
parentPort some admin handlers to async/await (#6559) (diff)
parentExplode on duplicate delta file names. (#6565) (diff)
downloadsynapse-8468c90dfe1a699b154c8870f0dc3561a0105510.tar.xz
Explode on duplicate delta file names. (#6565)
* commit '0b5dbadd9':
  Explode on duplicate delta file names. (#6565)
-rw-r--r--changelog.d/6565.misc1
-rw-r--r--synapse/storage/prepare_database.py18
2 files changed, 19 insertions, 0 deletions
diff --git a/changelog.d/6565.misc b/changelog.d/6565.misc
new file mode 100644

index 0000000000..e83f245bf0 --- /dev/null +++ b/changelog.d/6565.misc
@@ -0,0 +1 @@ +Add assertion that schema delta file names are unique. diff --git a/synapse/storage/prepare_database.py b/synapse/storage/prepare_database.py
index 0195edf4ac..403848ad03 100644 --- a/synapse/storage/prepare_database.py +++ b/synapse/storage/prepare_database.py
@@ -18,6 +18,7 @@ import imp import logging import os import re +from collections import Counter import attr @@ -315,6 +316,9 @@ def _upgrade_existing_database( ) ) + # Used to check if we have any duplicate file names + file_name_counter = Counter() + # Now find which directories have anything of interest. directory_entries = [] for directory in directories: @@ -325,6 +329,9 @@ def _upgrade_existing_database( _DirectoryListing(file_name, os.path.join(directory, file_name)) for file_name in file_names ) + + for file_name in file_names: + file_name_counter[file_name] += 1 except FileNotFoundError: # Data stores can have empty entries for a given version delta. pass @@ -333,6 +340,17 @@ def _upgrade_existing_database( "Could not open delta dir for version %d: %s" % (v, directory) ) + duplicates = set( + file_name for file_name, count in file_name_counter.items() if count > 1 + ) + if duplicates: + # We don't support using the same file name in the same delta version. + raise PrepareDatabaseException( + "Found multiple delta files with the same name in v%d: %s", + v, + duplicates, + ) + # We sort to ensure that we apply the delta files in a consistent # order (to avoid bugs caused by inconsistent directory listing order) directory_entries.sort()