You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

44 lines
1.4 KiB

  1. # Copyright 2016 OpenMarket Ltd
  2. #
  3. # Licensed under the Apache License, Version 2.0 (the "License");
  4. # you may not use this file except in compliance with the License.
  5. # You may obtain a copy of the License at
  6. #
  7. # http://www.apache.org/licenses/LICENSE-2.0
  8. #
  9. # Unless required by applicable law or agreed to in writing, software
  10. # distributed under the License is distributed on an "AS IS" BASIS,
  11. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. # See the License for the specific language governing permissions and
  13. # limitations under the License.
  14. import logging
  15. from synapse.storage.database import LoggingTransaction
  16. from synapse.storage.engines import BaseDatabaseEngine, PostgresEngine
  17. from synapse.storage.prepare_database import get_statements
  18. logger = logging.getLogger(__name__)
  19. # This stream is used to notify workers over replication that some caches have
  20. # been invalidated that they cannot infer from the other streams.
  21. CREATE_TABLE = """
  22. CREATE TABLE cache_invalidation_stream (
  23. stream_id BIGINT,
  24. cache_func TEXT,
  25. keys TEXT[],
  26. invalidation_ts BIGINT
  27. );
  28. CREATE INDEX cache_invalidation_stream_id ON cache_invalidation_stream(stream_id);
  29. """
  30. def run_create(cur: LoggingTransaction, database_engine: BaseDatabaseEngine) -> None:
  31. if not isinstance(database_engine, PostgresEngine):
  32. return
  33. for statement in get_statements(CREATE_TABLE.splitlines()):
  34. cur.execute(statement)