mirror of
				https://github.com/asterisk/asterisk.git
				synced 2025-10-31 02:37:10 +00:00 
			
		
		
		
	sorcery: Prevent duplicate objects and ensure missing objects are created on update
This patch resolves two issues in Sorcery objectset handling with multiple
backends:
1. Prevent duplicate objects:
   When an object exists in more than one backend (e.g., a contact in both
   'astdb' and 'realtime'), the objectset previously returned multiple instances
   of the same logical object. This caused logic failures in components like the
   PJSIP registrar, where duplicate contact entries led to overcounting and
   incorrect deletions, when max_contacts=1 and remove_existing=yes.
   This patch ensures only one instance of an object with a given key is added
   to the objectset, avoiding these duplicate-related side effects.
2. Ensure missing objects are created:
   When using multiple writable backends, a temporary backend failure can lead
   to objects missing permanently from that backend.
   Currently, .update() silently fails if the object is not present,
   and no .create() is attempted.
   This results in inconsistent state across backends (e.g. astdb vs. realtime).
   This patch introduces a new global option in sorcery.conf:
     [general]
     update_or_create_on_update_miss = yes|no
   Default: no (preserves existing behavior).
   When enabled: if .update() fails with no data found, .create() is attempted
   in that backend. This ensures that objects missing due to temporary backend
   outages are re-synchronized once the backend is available again.
   Added a new CLI command:
     sorcery show settings
   Displays global Sorcery settings, including the current value of
   update_or_create_on_update_miss.
   Updated tests to validate both flag enabled/disabled behavior.
Fixes: #1289
UserNote: Users relying on Sorcery multiple writable backends configurations
(e.g., astdb + realtime) may now enable update_or_create_on_update_miss = yes
in sorcery.conf to ensure missing objects are recreated after temporary backend
failures. Default behavior remains unchanged unless explicitly enabled.
(cherry picked from commit 658b775fd6)
			
			
This commit is contained in:
		
				
					committed by
					
						 George Joseph
						George Joseph
					
				
			
			
				
	
			
			
			
						parent
						
							60b8f1d4ed
						
					
				
				
					commit
					44034cf841
				
			| @@ -2141,11 +2141,18 @@ AST_TEST_DEFINE(object_update_uncreated) | ||||
| 		return AST_TEST_FAIL; | ||||
| 	} | ||||
|  | ||||
| 	ast_sorcery_update_or_create_on_update_miss = 0; | ||||
| 	if (!ast_sorcery_update(sorcery, obj)) { | ||||
| 		ast_test_status_update(test, "Successfully updated an object which has not been created yet\n"); | ||||
| 		return AST_TEST_FAIL; | ||||
| 	} | ||||
|  | ||||
| 	ast_sorcery_update_or_create_on_update_miss = 1; | ||||
| 	if (ast_sorcery_update(sorcery, obj)) { | ||||
| 		ast_test_status_update(test, "Failed to create object when update() finds no object in a backend\n"); | ||||
| 		return AST_TEST_FAIL; | ||||
| 	} | ||||
|  | ||||
| 	return AST_TEST_PASS; | ||||
| } | ||||
|  | ||||
|   | ||||
| @@ -511,11 +511,18 @@ AST_TEST_DEFINE(object_update_uncreated) | ||||
| 		return AST_TEST_FAIL; | ||||
| 	} | ||||
|  | ||||
| 	ast_sorcery_update_or_create_on_update_miss = 0; | ||||
| 	if (!ast_sorcery_update(sorcery, obj)) { | ||||
| 		ast_test_status_update(test, "Successfully updated an object which has not been created yet\n"); | ||||
| 		return AST_TEST_FAIL; | ||||
| 	} | ||||
|  | ||||
| 	ast_sorcery_update_or_create_on_update_miss = 1; | ||||
| 	if (ast_sorcery_update(sorcery, obj)) { | ||||
| 		ast_test_status_update(test, "Failed to create object when update() finds no object in a backend\n"); | ||||
| 		return AST_TEST_FAIL; | ||||
| 	} | ||||
|  | ||||
| 	return AST_TEST_PASS; | ||||
| } | ||||
|  | ||||
|   | ||||
		Reference in New Issue
	
	Block a user