element-hq / element-hq/synapse

I'm confused about the `instance_name` parameter in Streams' `get_updates` and `get_updates_since`.

Open
#11,348 0 comments 0 reactions 0 assignees View on GitHub
T-Other
Dominant language
Python
Stars
4.6k
Forks
600
Avg merge
5d 22h
Merged PRs (30d)
51

Description

This issue has been migrated from [#11348](https://github.com/matrix-org/synapse/issues/11348).

---

I'm specifically trying to track down the cache invalidation stream (the one used by `invalidate_cache_and_stream()` and using the `cache_invalidation_stream_by_instance` table), but I got confused along the way and thought I'd try and write it down...

The type of an update function seems to say that the first argument is the name of the writer (and given that `invalidate_cache_and_stream()` appears to write the writing instance's name down, that seems likely).

https://github.com/matrix-org/synapse/blob/af54167516c7211937efa5b800853f3088ef5178/synapse/replication/tcp/streams/_base.py#L68-L78

However here on line 160 here in `get_updates` seems to show the reader providing its own name as the writer (going through `get_updates_since`, which passes the given instance name through to the `update_function`):
https://github.com/matrix-org/synapse/blob/af54167516c7211937efa5b800853f3088ef5178/synapse/replication/tcp/streams/_base.py#L148-L160
It doesn't seem very sensible for a process to read its own stream; so I must have gotten the wrong end of the stick somewhere.

Note that `get_updates_since` accepts an `instance_name` parameter. I find few uses of this function, but something in the TCP replication handler uses the command sender's name (which seems correct — though isn't the TCP replication stuff old hat?) and something elsewhere uses the instance's own name for reading.

I haven't yet found the consumer of the `cache_invalidation_stream_by_instance` messages :/.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.