summary refs log tree commit diff
diff options
context:
space:
mode:
authorMark Haines <mark.haines@matrix.org>2016-05-17 15:37:38 +0100
committerMark Haines <mark.haines@matrix.org>2016-05-17 15:37:38 +0100
commitaab3f1a846a6d935675e4c63fadff0d0cafe30fd (patch)
tree32a0e9856966f3e001dbfc34d100b66ac7891e40
parentMerge branch 'develop' into markjh/synchrotron (diff)
downloadsynapse-aab3f1a846a6d935675e4c63fadff0d0cafe30fd.tar.xz
Add some slaved stores that we'll need for the synchrotron
-rw-r--r--synapse/app/synchrotron.py21
-rw-r--r--synapse/replication/slave/storage/filtering.py24
-rw-r--r--synapse/replication/slave/storage/push_rule.py50
-rw-r--r--synapse/replication/slave/storage/registration.py32
4 files changed, 125 insertions, 2 deletions
diff --git a/synapse/app/synchrotron.py b/synapse/app/synchrotron.py
index e7144c2865..865c7f34e7 100644
--- a/synapse/app/synchrotron.py
+++ b/synapse/app/synchrotron.py
@@ -28,6 +28,9 @@ from synapse.replication.slave.storage.events import SlavedEventStore
 from synapse.replication.slave.storage.receipts import SlavedReceiptsStore
 from synapse.replication.slave.storage.account_data import SlavedAccountDataStore
 from synapse.replication.slave.storage.appservice import SlavedApplicationServiceStore
+from synapse.replication.slave.storage.registration import SlavedRegistrationStore
+from synapse.replication.slave.storage.filtering import SlavedFilteringStore
+from synapse.replication.slave.storage.push_rule import SlavedPushRuleStore
 from synapse.server import HomeServer
 from synapse.storage.engines import create_engine
 from synapse.util.httpresourcetree import create_resource_tree
@@ -43,6 +46,7 @@ from daemonize import Daemonize
 
 import sys
 import logging
+import contextlib
 
 logger = logging.getLogger("synapse.app.synchrotron")
 
@@ -94,12 +98,25 @@ class SynchrotronConfig(DatabaseConfig, LoggingConfig, AppServiceConfig):
 
 
 class SynchrotronSlavedStore(
+    SlavedPushRuleStore,
     SlavedEventStore,
     SlavedReceiptsStore,
     SlavedAccountDataStore,
     SlavedApplicationServiceStore,
+    SlavedRegistrationStore,
+    SlavedFilteringStore,
 ):
-    pass
+    def get_current_presence_token(self):
+        pass
+
+
+class SynchrotronPresence(object):
+    def set_state(self, user, state):
+        pass
+
+    @contextlib.contextmanager
+    def user_syncing(self, user, affect_presence):
+        yield
 
 
 class SynchrotronServer(HomeServer):
@@ -192,7 +209,7 @@ def setup(config_options):
         config=config,
         version_string=get_version_string("Synapse", synapse),
         database_engine=database_engine,
-        presence_handler=object(),
+        presence_handler=SynchrotronPresence(),
     )
 
     ss.setup()
diff --git a/synapse/replication/slave/storage/filtering.py b/synapse/replication/slave/storage/filtering.py
new file mode 100644
index 0000000000..5037f395b9
--- /dev/null
+++ b/synapse/replication/slave/storage/filtering.py
@@ -0,0 +1,24 @@
+# -*- coding: utf-8 -*-
+# Copyright 2015, 2016 OpenMarket Ltd
+#
+# 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.
+
+from ._base import BaseSlavedStore
+from synapse.storage.filtering import FilteringStore
+
+
+class SlavedFilteringStore(BaseSlavedStore):
+    def __init__(self, db_conn, hs):
+        super(SlavedFilteringStore, self).__init__(db_conn, hs)
+
+    get_user_filter = FilteringStore.__dict__["get_user_filter"]
diff --git a/synapse/replication/slave/storage/push_rule.py b/synapse/replication/slave/storage/push_rule.py
new file mode 100644
index 0000000000..56796d9bd4
--- /dev/null
+++ b/synapse/replication/slave/storage/push_rule.py
@@ -0,0 +1,50 @@
+# -*- coding: utf-8 -*-
+# Copyright 2015, 2016 OpenMarket Ltd
+#
+# 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.
+
+from .events import SlavedEventStore
+from ._slaved_id_tracker import SlavedIdTracker
+from synapse.storage.push_rule import PushRuleStore
+
+
+class SlavedPushRuleStore(SlavedEventStore):
+    def __init__(self, db_conn, hs):
+        super(SlavedPushRuleStore, self).__init__(db_conn, hs)
+        self._push_rules_stream_id_gen = SlavedIdTracker(
+            db_conn, "push_rules_stream", "stream_id",
+        )
+
+    get_push_rules_for_user = PushRuleStore.__dict__["get_push_rules_for_user"]
+
+    def get_push_rules_stream_token(self):
+        return (
+            self._push_rules_stream_id_gen.get_current_token(),
+            self._stream_id_gen.get_current_token(),
+        )
+
+    def stream_positions(self):
+        result = super(SlavedPushRuleStore, self).stream_positions()
+        result["push_rules"] = self._push_rules_stream_id_gen.get_current_token()
+        return result
+
+    def process_replication(self, result):
+        stream = result.get("push_rules")
+        if stream:
+            for row in stream["rows"]:
+                user_id = row[1]
+                self.get_push_rules_for_user.invalidate((user_id,))
+
+            self._push_rules_stream_id_gen.advance(int(stream["position"]))
+
+        return super(SlavedPushRuleStore, self).process_replication(result)
diff --git a/synapse/replication/slave/storage/registration.py b/synapse/replication/slave/storage/registration.py
new file mode 100644
index 0000000000..8f39e4f7aa
--- /dev/null
+++ b/synapse/replication/slave/storage/registration.py
@@ -0,0 +1,32 @@
+# -*- coding: utf-8 -*-
+# Copyright 2015, 2016 OpenMarket Ltd
+#
+# 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.
+
+from ._base import BaseSlavedStore
+from synapse.storage import DataStore
+from synapse.storage.registration import RegistrationStore
+
+
+class SlavedRegistrationStore(BaseSlavedStore):
+    def __init__(self, db_conn, hs):
+        super(SlavedRegistrationStore, self).__init__(db_conn, hs)
+
+    # TODO: Remove deleted tokens from the cache
+    get_user_by_access_token = RegistrationStore.__dict__[
+        "get_user_by_access_token"
+    ]
+
+    insert_client_ip = DataStore.insert_client_ip.__func__
+
+    _query_for_auth = DataStore._query_for_auth.__func__