Add some slaved stores that we'll need for the synchrotron
parent
8e5b0955ba
commit
aab3f1a846
|
@ -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.receipts import SlavedReceiptsStore
|
||||||
from synapse.replication.slave.storage.account_data import SlavedAccountDataStore
|
from synapse.replication.slave.storage.account_data import SlavedAccountDataStore
|
||||||
from synapse.replication.slave.storage.appservice import SlavedApplicationServiceStore
|
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.server import HomeServer
|
||||||
from synapse.storage.engines import create_engine
|
from synapse.storage.engines import create_engine
|
||||||
from synapse.util.httpresourcetree import create_resource_tree
|
from synapse.util.httpresourcetree import create_resource_tree
|
||||||
|
@ -43,6 +46,7 @@ from daemonize import Daemonize
|
||||||
|
|
||||||
import sys
|
import sys
|
||||||
import logging
|
import logging
|
||||||
|
import contextlib
|
||||||
|
|
||||||
logger = logging.getLogger("synapse.app.synchrotron")
|
logger = logging.getLogger("synapse.app.synchrotron")
|
||||||
|
|
||||||
|
@ -94,14 +98,27 @@ class SynchrotronConfig(DatabaseConfig, LoggingConfig, AppServiceConfig):
|
||||||
|
|
||||||
|
|
||||||
class SynchrotronSlavedStore(
|
class SynchrotronSlavedStore(
|
||||||
|
SlavedPushRuleStore,
|
||||||
SlavedEventStore,
|
SlavedEventStore,
|
||||||
SlavedReceiptsStore,
|
SlavedReceiptsStore,
|
||||||
SlavedAccountDataStore,
|
SlavedAccountDataStore,
|
||||||
SlavedApplicationServiceStore,
|
SlavedApplicationServiceStore,
|
||||||
|
SlavedRegistrationStore,
|
||||||
|
SlavedFilteringStore,
|
||||||
):
|
):
|
||||||
|
def get_current_presence_token(self):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
class SynchrotronPresence(object):
|
||||||
|
def set_state(self, user, state):
|
||||||
|
pass
|
||||||
|
|
||||||
|
@contextlib.contextmanager
|
||||||
|
def user_syncing(self, user, affect_presence):
|
||||||
|
yield
|
||||||
|
|
||||||
|
|
||||||
class SynchrotronServer(HomeServer):
|
class SynchrotronServer(HomeServer):
|
||||||
def get_db_conn(self, run_new_connection=True):
|
def get_db_conn(self, run_new_connection=True):
|
||||||
# Any param beginning with cp_ is a parameter for adbapi, and should
|
# Any param beginning with cp_ is a parameter for adbapi, and should
|
||||||
|
@ -192,7 +209,7 @@ def setup(config_options):
|
||||||
config=config,
|
config=config,
|
||||||
version_string=get_version_string("Synapse", synapse),
|
version_string=get_version_string("Synapse", synapse),
|
||||||
database_engine=database_engine,
|
database_engine=database_engine,
|
||||||
presence_handler=object(),
|
presence_handler=SynchrotronPresence(),
|
||||||
)
|
)
|
||||||
|
|
||||||
ss.setup()
|
ss.setup()
|
||||||
|
|
|
@ -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"]
|
|
@ -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)
|
|
@ -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__
|
Loading…
Reference in New Issue