mirror of
				https://github.com/matrix-org/synapse.git
				synced 2025-10-31 12:18:24 +00:00 
			
		
		
		
	Fix background update table-scanning events (#14374)
				
					
				
			When this background update did its last batch, it would try to update all the events that had been inserted since the bgupdate started, which could cause a table-scan. Make sure we limit the update correctly.
This commit is contained in:
		
							parent
							
								
									42f9d414c2
								
							
						
					
					
						commit
						2193513346
					
				
							
								
								
									
										1
									
								
								changelog.d/14374.bugfix
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										1
									
								
								changelog.d/14374.bugfix
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1 @@ | |||||||
|  | Fix a background database update, introduced in Synapse 1.64.0, which could cause poor database performance. | ||||||
| @ -1435,16 +1435,16 @@ class EventsBackgroundUpdatesStore(SQLBaseStore): | |||||||
|                 ), |                 ), | ||||||
|             ) |             ) | ||||||
| 
 | 
 | ||||||
|             endpoint = None |  | ||||||
|             row = txn.fetchone() |             row = txn.fetchone() | ||||||
|             if row: |             if row: | ||||||
|                 endpoint = row[0] |                 endpoint = row[0] | ||||||
|  |             else: | ||||||
|  |                 # if the query didn't return a row, we must be almost done. We just | ||||||
|  |                 # need to go up to the recorded max_stream_ordering. | ||||||
|  |                 endpoint = max_stream_ordering_inclusive | ||||||
| 
 | 
 | ||||||
|             where_clause = "stream_ordering > ?" |             where_clause = "stream_ordering > ? AND stream_ordering <= ?" | ||||||
|             args = [min_stream_ordering_exclusive] |             args = [min_stream_ordering_exclusive, endpoint] | ||||||
|             if endpoint: |  | ||||||
|                 where_clause += " AND stream_ordering <= ?" |  | ||||||
|                 args.append(endpoint) |  | ||||||
| 
 | 
 | ||||||
|             # now do the updates. |             # now do the updates. | ||||||
|             txn.execute( |             txn.execute( | ||||||
| @ -1458,13 +1458,13 @@ class EventsBackgroundUpdatesStore(SQLBaseStore): | |||||||
|             ) |             ) | ||||||
| 
 | 
 | ||||||
|             logger.info( |             logger.info( | ||||||
|                 "populated new `events` columns up to %s/%i: updated %i rows", |                 "populated new `events` columns up to %i/%i: updated %i rows", | ||||||
|                 endpoint, |                 endpoint, | ||||||
|                 max_stream_ordering_inclusive, |                 max_stream_ordering_inclusive, | ||||||
|                 txn.rowcount, |                 txn.rowcount, | ||||||
|             ) |             ) | ||||||
| 
 | 
 | ||||||
|             if endpoint is None: |             if endpoint >= max_stream_ordering_inclusive: | ||||||
|                 # we're done |                 # we're done | ||||||
|                 return True |                 return True | ||||||
| 
 | 
 | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user