Instructing clients to migrate to a different server

This section discusses the requirements for an Open Server to migrate clients to other servers. When migrating clients to a different server your application must:

  1. Create a unique session ID and send it to the clients in the connection handler.

  2. Initiate connection migration.

  3. Handle migration events.

  4. Share the context of the connection, using the connection’s session ID, to other servers.

  5. (Optional) Act on ongoing migrations in existing handlers.

The following sections further discuss these activities.


Requesting a client to migrate

Open Server can use srv_send_ctlinfo() to send a migration request to the client. Client migration can be requested from any Open Server thread.


Managing the connect (SRV_CONNECT) event

In the SRV_CONNECT event handler, your application must:


Managing the migrate state (SRV_MIGRATE_STATE) event

The SRV_MIGRATE_STATE event handler must manage the migration state changes and execute the actions appropriate for each change:


Sharing client context

For servers to start and continue servicing a client, the servers must have access to the client’s context which is identified by the client’s session ID. Typically, the client’s context contains data, such as global data, that event handlers for the client can access. The amount of context required for a connection depends on the service that the Open Server application provides. The more context-free the service is, the less context needs to be shared.


Managing the migrate resume (SRV_MIGRATE_RESUME) event

Your application sends the remaining results and messages to the client inside the SRV_MIGRATE_RESUME event handler. The results and messages that Open Server sends to the client depend on your application and the migration type. However, your application must end the SRV_MIGRATE_RESUME event handler by sending the SRV_DONE_FINAL result type to the client.


Managing the disconnect (SRV_DISCONNECT) event

In the SRV_DISCONNECT event handler, your application must check SRV_T_MIGRATE_STATE to determine the client’s migration state:


Managing in-batch migration

An event handler that runs for long periods of time must occasionally inspect the migration state. Other Open Server threads can send a migration request even while an event handler process is still running. In this case, the event handler, if it is able to, must interrupt the process, and postpone the generation and sending of results until the connection has migrated to the new server.


Attention handling

When a client sends an attention message to cancel an outstanding request, the SRV_T_GOTATTENTION thread property is set to CS_TRUE and the SRV_ATTENTION event handler is called. The specific attention handling needs of a connection migration are described below:


Disconnecting Open Server

Your application can terminate a client connection even when a migration has been requested; however, a new client command that is sent just before Open Server issued the termination command may get lost. To avoid this, your application must: