pushers.py 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. # -*- coding: utf-8 -*-
  2. # Copyright 2016 OpenMarket Ltd
  3. # Copyright 2018 New Vector Ltd
  4. #
  5. # Licensed under the Apache License, Version 2.0 (the "License");
  6. # you may not use this file except in compliance with the License.
  7. # You may obtain a copy of the License at
  8. #
  9. # http://www.apache.org/licenses/LICENSE-2.0
  10. #
  11. # Unless required by applicable law or agreed to in writing, software
  12. # distributed under the License is distributed on an "AS IS" BASIS,
  13. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. # See the License for the specific language governing permissions and
  15. # limitations under the License.
  16. from ._base import BaseSlavedStore
  17. from ._slaved_id_tracker import SlavedIdTracker
  18. from synapse.storage.pusher import PusherWorkerStore
  19. class SlavedPusherStore(PusherWorkerStore, BaseSlavedStore):
  20. def __init__(self, db_conn, hs):
  21. super(SlavedPusherStore, self).__init__(db_conn, hs)
  22. self._pushers_id_gen = SlavedIdTracker(
  23. db_conn, "pushers", "id",
  24. extra_tables=[("deleted_pushers", "stream_id")],
  25. )
  26. def stream_positions(self):
  27. result = super(SlavedPusherStore, self).stream_positions()
  28. result["pushers"] = self._pushers_id_gen.get_current_token()
  29. return result
  30. def process_replication_rows(self, stream_name, token, rows):
  31. if stream_name == "pushers":
  32. self._pushers_id_gen.advance(token)
  33. return super(SlavedPusherStore, self).process_replication_rows(
  34. stream_name, token, rows
  35. )