This repository was archived by the owner on Apr 26, 2024. It is now read-only.
  
  
  - 
          
 - 
                Notifications
    
You must be signed in to change notification settings  - Fork 2.1k
 
Sequence backed id generators #15480
          
     Closed
      
      
            alexcornet
  wants to merge
  2
  commits into
  matrix-org:develop
from
alexcornet:sequence-backed-id-generators
  
      
      
   
      
    
  
     Closed
                    Changes from all commits
      Commits
    
    
            Show all changes
          
          
            2 commits
          
        
        Select commit
          Hold shift + click to select a range
      
      
    File filter
Filter by extension
Conversations
          Failed to load comments.   
        
        
          
      Loading
        
  Jump to
        
          Jump to file
        
      
      
          Failed to load files.   
        
        
          
      Loading
        
  Diff view
Diff view
There are no files selected for viewing
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| Make all ID generators rely on Postgres sequences to improve support for running with multiple homeserver nodes. | ||
| 
     | 
||
| 1. Update the implementation of `IdGenerator` to use defer to `SequenceGenerator`. | ||
| * The `SequenceGenerator` object is obtained from `build_sequence_generator`, which returns a | ||
| `PostgresSequenceGenerator` backed by a Postgres sequence when running against Postgres. | ||
| * `get_next` now involves querying the next value from the DB in an async fashion, hence we add a synchronous | ||
| `get_next_txn` which can be used when a `Cursor` object is already available. | ||
| 2. Replace all instances of `StreamIdGenerator` with `MultiWriterIdGenerator`, which is backed by Postgres sequences, | ||
| when running with Postgres. `SequenceIdGenerator` is kept when running with SQLite, which doesn't support sequences. | ||
| 3. Bump schema version and add delta files to create the Postgres sequences, and add `instance_name` columns to tables | ||
| used with `MultiWriterIdGenerator`. | ||
| * Note that in case of downgrade, the sequence will get out of sync with the database and startup consistency checks | ||
| will fail when upgrading again. | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
        
          
  
    
      
          
            12 changes: 12 additions & 0 deletions
          
          12 
        
  synapse/storage/schema/main/delta/75/01_add_instance_name.sql
  
  
      
      
   
        
      
      
    
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| ALTER TABLE device_lists_stream ADD COLUMN instance_name TEXT; | ||
| 
     | 
||
| ALTER TABLE user_signature_stream ADD COLUMN instance_name TEXT; | ||
| ALTER TABLE device_lists_outbound_pokes ADD COLUMN instance_name TEXT; | ||
| ALTER TABLE device_lists_changes_in_room ADD COLUMN instance_name TEXT; | ||
| ALTER TABLE device_lists_remote_pending ADD COLUMN instance_name TEXT; | ||
| ALTER TABLE device_lists_changes_converted_stream_position ADD COLUMN instance_name TEXT; | ||
| 
     | 
||
| ALTER TABLE e2e_cross_signing_keys ADD COLUMN instance_name TEXT; | ||
| 
     | 
||
| ALTER TABLE pushers ADD COLUMN instance_name TEXT; | ||
| ALTER TABLE deleted_pushers ADD COLUMN instance_name TEXT; | 
      
      Oops, something went wrong.
        
    
  
  Add this suggestion to a batch that can be applied as a single commit.
  This suggestion is invalid because no changes were made to the code.
  Suggestions cannot be applied while the pull request is closed.
  Suggestions cannot be applied while viewing a subset of changes.
  Only one suggestion per line can be applied in a batch.
  Add this suggestion to a batch that can be applied as a single commit.
  Applying suggestions on deleted lines is not supported.
  You must change the existing code in this line in order to create a valid suggestion.
  Outdated suggestions cannot be applied.
  This suggestion has been applied or marked resolved.
  Suggestions cannot be applied from pending reviews.
  Suggestions cannot be applied on multi-line comments.
  Suggestions cannot be applied while the pull request is queued to merge.
  Suggestion cannot be applied right now. Please check back later.
  
    
  
    
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Following the pattern I noticed in other files where
MultiWriterIdGeneratoris used, although I think we could refactor this and create a helper function to get the rightAbstractStreamIdGeneratordepending on the engine, similarly to whatbuild_sequence_generatoris doing.It would be less verbose and abstract some complexity away from the callee by making
MultiWriterIdGeneratorandStreamIdGeneratorimplementation details.If you agree with this I could start by making the refactor on develop and then use the new pattern here.
Note that I think that eventually,
StreamIdGeneratorandMultiWriterIdGeneratorshould become private to prevent someone from usingStreamIdGeneratorand breaking the multi node setup.