-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Add endpoints for backfilling history (MSC2716) #9247
Changes from all commits
22c038e
4836954
c0b0936
bf90053
bcc6943
7f4c3a6
800f3a3
9b5e057
447eaa8
7ec22b5
afa5e5d
f1f3fb0
e7d7f92
b9024f7
d204880
dbba361
f1c31f1
19aa93c
c074584
c02079d
412ffc3
7160f3b
5ff398d
864b98f
6f174f1
ba1eb39
6d4fcb6
5d5fb8b
ed76d5f
1aa3af9
e63ef8e
c90af9e
270e5ee
4359ab8
641e871
6d8514f
5dacc86
61dc89f
e12a77d
8549219
6c96622
23d0379
ea37564
7008ee0
0d4736f
49631e5
06dccec
8e0684d
cbd16b8
044a761
86ec915
81b45b5
02b7335
82708cb
f0fb732
c525c5d
5deee7c
960ec21
779ef25
7dcc0fa
52b1e7b
1d6cf78
13b18a8
3d513bf
e92a9e9
e9ae5e1
a978f38
2c22929
0501a11
e231a99
176a854
a6a05f8
25aef56
0580d09
ef68832
d8316d6
513d7a2
f36bdde
c2e1924
88327fb
34f130c
2f35954
6ce47d3
b032370
22881e2
ae85719
d59d6be
c236a3c
429e130
29c3708
89e08c5
bfe458c
2c1750f
e851dac
7dcbba9
f7158ff
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Add experimental support for backfilling history into rooms ([MSC2716](https://github.com/matrix-org/matrix-doc/pull/2716)). | ||
MadLittleMods marked this conversation as resolved.
Show resolved
Hide resolved
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we not need to change the behaviour of getting backfill from the DB? Or are we punting that to a separate PR? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm going to work on the insertion/marker event logic in another PR after this merges so it doesn't grow more and I don't have to keep refactoring across PR's. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. SGTM! |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,6 +11,7 @@ | |
# 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. | ||
import logging | ||
from typing import Any, Dict, List, Optional, Tuple, Union | ||
|
||
import attr | ||
|
@@ -33,6 +34,8 @@ | |
from synapse.util import Clock | ||
from synapse.util.stringutils import random_string | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
||
@attr.s(slots=True, cmp=False, frozen=True) | ||
class EventBuilder: | ||
|
@@ -100,6 +103,7 @@ async def build( | |
self, | ||
prev_event_ids: List[str], | ||
auth_event_ids: Optional[List[str]], | ||
depth: Optional[int] = None, | ||
) -> EventBase: | ||
"""Transform into a fully signed and hashed event | ||
|
||
|
@@ -108,6 +112,9 @@ async def build( | |
auth_event_ids: The event IDs to use as the auth events. | ||
Should normally be set to None, which will cause them to be calculated | ||
based on the room state at the prev_events. | ||
depth: Override the depth used to order the event in the DAG. | ||
Should normally be set to None, which will cause the depth to be calculated | ||
based on the prev_events. | ||
|
||
Returns: | ||
The signed and hashed event. | ||
|
@@ -131,8 +138,14 @@ async def build( | |
auth_events = auth_event_ids | ||
prev_events = prev_event_ids | ||
|
||
old_depth = await self._store.get_max_depth_of(prev_event_ids) | ||
depth = old_depth + 1 | ||
# Otherwise, progress the depth as normal | ||
if depth is None: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The last test failures are coming from this new line (if I comment it out to always calculate Test failure: https://github.com/matrix-org/synapse/pull/10049/checks?check_run_id=2764607442#step:8:2373 Reproduction locally:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Setting the env to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It looks like I accidentally set Found the problem first by logging what the weird logger.info("depth1=%s", depth) Then I added this line which will cause it to throw an exception (because no if depth == False:
logging.info("Why is depth False?", depth) $ SYNAPSE_TEST_LOG_LEVEL=DEBUG python -m twisted.trial tests.handlers.test_presence.PresenceJoinTestCase.test_remote_gets_presence_when_local_user_joins
tests.handlers.test_presence
PresenceJoinTestCase
test_remote_gets_presence_when_local_user_joins ... [FAIL]
===============================================================================
[FAIL]
Traceback (most recent call last):
File "/Users/eric/Documents/github/element/synapse/tests/handlers/test_presence.py", line 815, in test_remote_gets_presence_when_local_user_joins
self._add_new_user(room_id, "@alice:server2")
- File "/Users/eric/Documents/github/element/synapse/tests/handlers/test_presence.py", line 866, in _add_new_user
- event = self.get_success(builder.build(prev_event_ids, None, False))
File "/Users/eric/Documents/github/element/synapse/tests/unittest.py", line 500, in get_success
return self.successResultOf(d)
File "/Users/eric/.pyenv/versions/3.8.6/lib/python3.8/site-packages/twisted/trial/_synctest.py", line 706, in successResultOf
self.fail(
twisted.trial.unittest.FailTest: Success result expected on <Deferred at 0x10de9a3a0 current result: None>, found failure result instead:
Traceback (most recent call last):
File "/Users/eric/.pyenv/versions/3.8.6/lib/python3.8/site-packages/twisted/internet/defer.py", line 477, in callback
self._startRunCallbacks(result)
File "/Users/eric/.pyenv/versions/3.8.6/lib/python3.8/site-packages/twisted/internet/defer.py", line 580, in _startRunCallbacks
self._runCallbacks()
File "/Users/eric/.pyenv/versions/3.8.6/lib/python3.8/site-packages/twisted/internet/defer.py", line 662, in _runCallbacks
current.result = callback(current.result, *args, **kw)
File "/Users/eric/.pyenv/versions/3.8.6/lib/python3.8/site-packages/twisted/internet/defer.py", line 1514, in gotResult
current_context.run(_inlineCallbacks, r, g, status)
--- <exception caught here> ---
File "/Users/eric/.pyenv/versions/3.8.6/lib/python3.8/site-packages/twisted/internet/defer.py", line 1445, in _inlineCallbacks
result = current_context.run(g.send, result)
File "/Users/eric/Documents/github/element/synapse/synapse/events/builder.py", line 142, in build
logging.info("Why is depth False?", depth)
File "/Users/eric/.pyenv/versions/3.8.6/lib/python3.8/logging/__init__.py", line 2070, in info
root.info(msg, *args, **kwargs)
File "/Users/eric/.pyenv/versions/3.8.6/lib/python3.8/logging/__init__.py", line 1434, in info
self._log(INFO, msg, args, **kwargs)
File "/Users/eric/.pyenv/versions/3.8.6/lib/python3.8/logging/__init__.py", line 1577, in _log
self.handle(record)
File "/Users/eric/.pyenv/versions/3.8.6/lib/python3.8/logging/__init__.py", line 1587, in handle
self.callHandlers(record)
File "/Users/eric/.pyenv/versions/3.8.6/lib/python3.8/logging/__init__.py", line 1649, in callHandlers
hdlr.handle(record)
File "/Users/eric/.pyenv/versions/3.8.6/lib/python3.8/logging/__init__.py", line 950, in handle
self.emit(record)
File "/Users/eric/Documents/github/element/synapse/tests/test_utils/logging_setup.py", line 28, in emit
log_entry = self.format(record)
File "/Users/eric/.pyenv/versions/3.8.6/lib/python3.8/logging/__init__.py", line 925, in format
return fmt.format(record)
File "/Users/eric/.pyenv/versions/3.8.6/lib/python3.8/logging/__init__.py", line 664, in format
record.message = record.getMessage()
File "/Users/eric/.pyenv/versions/3.8.6/lib/python3.8/logging/__init__.py", line 369, in getMessage
msg = msg % self.args
builtins.TypeError: not all arguments converted during string formatting Is there a better way to get a stack trace/call stack? I tried
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Documented the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you raise if depth is wrong? That gives me a good stack trace. I think the defer code does special things to make the stack traces work out? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Is there a way I can just log a line and get a stack trace without breaking the normal execution flow? In JavaScript, I would use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think creating a twisted |
||
( | ||
_, | ||
most_recent_prev_event_depth, | ||
) = await self._store.get_max_depth_of(prev_event_ids) | ||
|
||
depth = most_recent_prev_event_depth + 1 | ||
|
||
# we cap depth of generated events, to ensure that they are not | ||
# rejected by other servers (and so that they can be persisted in | ||
|
Uh oh!
There was an error while loading. Please reload this page.