During development of our application we have introduced Azure SQL Geo-replication to improve user experience and responsiveness in various geographical locations.
Currently in testing we have two instances - a primary and secondary*, one of which is in US, the other in Europe.
Newly updated data from the primary database does not appear to be available in the secondary database even though sp_wait_for_database_copy_sync is called, which should ensure this.
When an entity is about to be updated, transaction committed and data synchronization ensured, the following three lines of code are called, in order:
ISession.Save(object obj)
is used to save new entitiesISession.Flush()
is used to commit transactionISession.CreateSQLQuery("EXEC sys.sp_wait_for_database_copy_sync
@target_server = N\'secondary-server\', @target_database
= N\'database\';").ExecuteUpdate()
is used to execute the call blocking synchronization procedureWhat could be wrong with the above three lines of code? The possible culprits I see are:
ISession.Flush
not executing synchronously, therefore when the blocking stored procedure is executed the transaction is not yet actually committedISession.CreateSQLQuery("EXEC sys.sp_wait_for_database_copy_sync
@target_server = N\'secondary-server\', @target_database
= N\'database\';").ExecuteUpdate()
is not actually being blocked.Any ideas on how to troubleshoot the above two or perhaps some other issues you see would be greatly appreciated.
I have forgotten to post here, but the issue was that the following procedure, while blocking, did not actually guarantee that once unblocked data will be available in all instances: sp_wait_for_database_copy_sync.