Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Matrix
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Container Registry
Model registry
Operate
Environments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
TeDomum
Matrix
Commits
21018c2c
Commit
21018c2c
authored
8 years ago
by
Mark Haines
Browse files
Options
Downloads
Plain Diff
Merge pull request #783 from matrix-org/markjh/slave_account_data
Add a slaved datastore for account data
parents
a8affd60
3abab264
No related branches found
Branches containing commit
No related tags found
Tags containing commit
Loading
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
synapse/replication/slave/storage/account_data.py
+61
-0
61 additions, 0 deletions
synapse/replication/slave/storage/account_data.py
tests/replication/slave/storage/test_account_data.py
+56
-0
56 additions, 0 deletions
tests/replication/slave/storage/test_account_data.py
with
117 additions
and
0 deletions
synapse/replication/slave/storage/account_data.py
0 → 100644
+
61
−
0
View file @
21018c2c
# -*- coding: utf-8 -*-
# Copyright 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
._slaved_id_tracker
import
SlavedIdTracker
from
synapse.storage.account_data
import
AccountDataStore
class
SlavedAccountDataStore
(
BaseSlavedStore
):
def
__init__
(
self
,
db_conn
,
hs
):
super
(
SlavedAccountDataStore
,
self
).
__init__
(
db_conn
,
hs
)
self
.
_account_data_id_gen
=
SlavedIdTracker
(
db_conn
,
"
account_data_max_stream_id
"
,
"
stream_id
"
,
)
get_global_account_data_by_type_for_users
=
(
AccountDataStore
.
__dict__
[
"
get_global_account_data_by_type_for_users
"
]
)
get_global_account_data_by_type_for_user
=
(
AccountDataStore
.
__dict__
[
"
get_global_account_data_by_type_for_user
"
]
)
def
stream_positions
(
self
):
result
=
super
(
SlavedAccountDataStore
,
self
).
stream_positions
()
position
=
self
.
_account_data_id_gen
.
get_current_token
()
result
[
"
user_account_data
"
]
=
position
result
[
"
room_account_data
"
]
=
position
result
[
"
tag_account_data
"
]
=
position
return
result
def
process_replication
(
self
,
result
):
stream
=
result
.
get
(
"
user_account_data
"
)
if
stream
:
self
.
_account_data_id_gen
.
advance
(
int
(
stream
[
"
position
"
]))
for
row
in
stream
[
"
rows
"
]:
user_id
,
data_type
=
row
[
1
:
3
]
self
.
get_global_account_data_by_type_for_user
.
invalidate
(
(
data_type
,
user_id
,)
)
stream
=
result
.
get
(
"
room_account_data
"
)
if
stream
:
self
.
_account_data_id_gen
.
advance
(
int
(
stream
[
"
position
"
]))
stream
=
result
.
get
(
"
tag_account_data
"
)
if
stream
:
self
.
_account_data_id_gen
.
advance
(
int
(
stream
[
"
position
"
]))
This diff is collapsed.
Click to expand it.
tests/replication/slave/storage/test_account_data.py
0 → 100644
+
56
−
0
View file @
21018c2c
# Copyright 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
BaseSlavedStoreTestCase
from
synapse.replication.slave.storage.account_data
import
SlavedAccountDataStore
from
twisted.internet
import
defer
USER_ID
=
"
@feeling:blue
"
TYPE
=
"
my.type
"
class
SlavedAccountDataStoreTestCase
(
BaseSlavedStoreTestCase
):
STORE_TYPE
=
SlavedAccountDataStore
@defer.inlineCallbacks
def
test_user_account_data
(
self
):
yield
self
.
master_store
.
add_account_data_for_user
(
USER_ID
,
TYPE
,
{
"
a
"
:
1
}
)
yield
self
.
replicate
()
yield
self
.
check
(
"
get_global_account_data_by_type_for_user
"
,
[
TYPE
,
USER_ID
],
{
"
a
"
:
1
}
)
yield
self
.
check
(
"
get_global_account_data_by_type_for_users
"
,
[
TYPE
,
[
USER_ID
]],
{
USER_ID
:
{
"
a
"
:
1
}}
)
yield
self
.
master_store
.
add_account_data_for_user
(
USER_ID
,
TYPE
,
{
"
a
"
:
2
}
)
yield
self
.
replicate
()
yield
self
.
check
(
"
get_global_account_data_by_type_for_user
"
,
[
TYPE
,
USER_ID
],
{
"
a
"
:
2
}
)
yield
self
.
check
(
"
get_global_account_data_by_type_for_users
"
,
[
TYPE
,
[
USER_ID
]],
{
USER_ID
:
{
"
a
"
:
2
}}
)
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment