Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Store MLS messages separately #330

Closed
wants to merge 8 commits into from
Closed

Store MLS messages separately #330

wants to merge 8 commits into from

Conversation

snormore
Copy link
Contributor

Fixes #319

What this includes:

  • Add messages table to MLS DB
  • Implement InsertMessage and QueryMessages in MLS store

What this doesn't include that the existing messages DB has:

  • Cleaner process for MLS messages
  • DB metrics for MLS messages
  • Reader connection for MLS DB
  • E2E tests for MLS topics that write to this DB

@snormore snormore requested a review from neekolas January 10, 2024 19:31
}, nil
}

func (s *Store) QueryMessages(ctx context.Context, query *messagev1.QueryRequest) (*messagev1.QueryResponse, error) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The mixing of messagev1 types into this feels a bit uncomfortable

if s.mlsStore == nil {
return nil, errors.New("mls store not configured")
}
return s.mlsStore.QueryMessages(ctx, req)
Copy link
Contributor Author

@snormore snormore Jan 10, 2024

Choose a reason for hiding this comment

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

Alternatively we could add QueryMessages to the mls/v3 service with it's own isolated types, rather than hijacking the messagev1 service+types for it, but that would have some downstream impact

Copy link
Collaborator

Choose a reason for hiding this comment

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

Downstream impact isn't a huge deal right now. There isn't that much downstream at the moment. Basically a single caller.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok great I think I'll add the mls/v3 protos to separate this all out cleanly then

@snormore snormore requested a review from richardhuaaa January 10, 2024 19:45
@snormore snormore marked this pull request as draft January 10, 2024 20:40
@snormore
Copy link
Contributor Author

snormore commented Jan 10, 2024

Converted back into a draft PR while I do the separated proto work for querying.

Where("id = ?", installationId).
Where("revoked_at IS NULL").
Exec(ctx)

return err
}

func (s *Store) InsertMessage(ctx context.Context, topic string, content []byte) (*messagev1.Envelope, error) {
createdAt := s.config.now()
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'm not sure this ordering is as total as we want. Clock drift between nodes could have newer messages actually end up before older messages.


CREATE TABLE messages (
topic VARCHAR(200) NOT NULL,
tid VARCHAR(96) NOT NULL,
Copy link
Collaborator

Choose a reason for hiding this comment

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

Given how strict the ordering requirements are, I'd really rather this rely on a sequence than the server time. Clocks can drift, and any re-ordering can corrupt the group state with the way MLS works. Even if those conflicts are improbable, it makes debugging a lot easier if they are impossible.

Copy link
Contributor Author

@snormore snormore Jan 10, 2024

Choose a reason for hiding this comment

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

Ok agree, that makes sense. I'll update it to use a simpler sequenced id primary key.

I'm going to close down this PR as it is, I think I'd also like to just split up the messages table by type too; group vs welcome messages, and get rid of the idea of topics completely.

@snormore snormore closed this Jan 10, 2024
@snormore snormore deleted the mls-msgs branch January 10, 2024 23:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants