Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

Option to replicate user profiles to another server #3112

Merged
merged 14 commits into from
Apr 26, 2018

Conversation

dbkr
Copy link
Member

@dbkr dbkr commented Apr 16, 2018

No description provided.

} for r in batch_rows
}

url = "https://%s/_matrix/federation/v1/replicate_profiles" % (host,)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There doesn't seem to be a handler for this. Are profiles intended to be replicated to a non-homeserver?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

correct; this is an experiment in replicating user profiles over to the IS so that for private IS deployments the IS can act as a global address book.

@@ -108,6 +112,10 @@ def default_config(self, **kwargs):
- vector.im
- riot.im

# If enabled, user IDs, display names and avatar URLs will be replicated
# to this server whenever they change.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we need to say that this is an experimental addition to the identity server API for supporting global user directories, and that the targets here should be identity server hostnames (otherwise folks will assume it's for HSes)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done, although it's in the /_matrix/federation path so I've said it's an API that's implemented by sydent rather than part of the IS API as such.

if len(self.hs.config.replicate_user_profiles_to) > 0:
reactor.callWhenRunning(self._assign_profile_replication_batches)
reactor.callWhenRunning(self._replicate_profiles)
self.clock.looping_call(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It'd be good to spell out in a comment why we're looping _replicate_profiles. I can see we'll need to do a catchup job at launch, but why do we then keep running it every 2 minutes, given whenever we set profile data it kicks off a sync anyway?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

logger.info("Assigned %d profile batch numbers", total)

@defer.inlineCallbacks
def _replicate_profiles(self):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How does this handle overlapping calls? (e.g. two _replicate_profiles runs being kicked off by two users setting profile data at the same time, or colliding with the looping syncer)?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

They'll get different batch numbers depending on which one got serviced first, then probably the first call to _replicate_profiles will send both batches and the second will do nothing. If it collides with the looping syncer it'll depend which db txn gets done first.

@ara4n
Copy link
Member

ara4n commented Apr 25, 2018

this looks very plausible - lgtm mod comments.

signed_body = sign_json(body, self.hs.hostname, self.hs.config.signing_key[0])
try:
yield self.http_client.post_json_get_json(url, signed_body)
self.store.update_replication_batch_for_host(host, batchnum)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

doesn't this need a yield?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah, yes it does, good spot

txn.execute("SELECT MAX(batch) as maxbatch FROM profiles")
rows = self.cursor_to_dict(txn)
return rows[0]['maxbatch']
max_batch = yield self.runInteraction(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you could just return self.runInteraction(...) rather than using inlineCallbacks

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

likewise below.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done


CREATE INDEX profiles_batch_idx ON profiles(batch);

CREATE TABLE profile_replication_status (
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please can we get into the habit of commenting our schema files to describe what the tables and the columns therein do.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@@ -75,7 +75,7 @@ def register_query_handler(query_type, handler):
@defer.inlineCallbacks
def test_get_my_name(self):
yield self.store.set_profile_displayname(
self.frank.localpart, "Frank"
self.frank.localpart, "Frank", 1
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it'd be nice to add trailing commas while you're here

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah yep, done (plus the others)

Unnecessary inlineCallbacks, missing yield, SQL comments & trailing
commas.
@dbkr dbkr merged commit e2adb36 into dinsic Apr 26, 2018
@hawkowl hawkowl deleted the dbkr/profile_replication branch September 20, 2018 13:59
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants