Synchronization Sequence
Putting together all the parts above, the full synchronization sequence is:
- RPC Manager obtains a Write lock on the client.
- When the Write lock has been obtained, RPC Manager launches GetClientRevision() on the client, into the service scope and on the service’s thread.
- RPC Manager launches GetClientChanges() on the client, into the service scope and on the service’s thread. This is done after 2, but RPC Manager does not wait for GetClientRevision to complete before launching GetClientChanges().
- RPC Manager then waits for both GetClientRevision() and GetClientChanges() to terminate, by slaying themselves or returning Invalid and then sends the client revision and changes streams to the server.
- RPC Manager, on the server, obtains either a Read or a Write lock, depending on whether there is a client changes stream.
- When the lock has been obtained, RPC Manager, on the server, atomically starts buffering service RPCs for the service and launches GetServerChanges().
- When GetServerChanges() calls SetDivert(), the buffered service RPCs are released for processing and service RPCs destined for the synchronising client start buffering.
- When GetServerChanges() terminates, by slaying itself or returning Invalid, RPC Manager queues the RPC package from GetServerChanges() for transmission to the client. If an RPC package was received from the client, RPC Manager, on the server, now processes that call package, calling the RPC subroutines within the package and then waits for SetSyncComplete() to be called on the server.
- RPC Manager, on the client, executes the RPC package from the server and waits for the client service instance to call SetSyncComplete(). When this is called, the client instance is marked as ready and the Write lock, obtained in 1, is released.
- When the server sees the client instance marked as ready (and 7, above, has completed), any buffered RPCs from the service for that client are queued for transmission to the client and synchronization terminates, clearing the Read or Write lock, obtained in 5, above.