Migration

Overview

This page describes the behavior of migration on Diarkis servers.

What is Migration?

Diarkis servers are configured in a cluster, and users connect to one of these servers. Consider a case where the connected Diarkis server is scaled in and the user’s connected server is stopped. On a typical server, users connected at that time would be disconnected due to server shutdown. However, Diarkis servers can move within the cluster, allowing the service to continue without disconnecting from the server.

This mechanism of re-establishing the connection from the current server to another server to maintain service is called Migration.

While a scale-in was used as a straightforward example, migration can occur for various reasons outside of scale-in events as well. When migration occurs, both the server and client application need to cooperate to advance the migration process. The next section will explain the specific procedures when migration occurs.

If you are participating in a Room, please refer to the Room-specific migration instead of using the following features.

Entire Migration Process Flow

Migration begins with a notification from the server. When the server determines that migration is necessary due to various factors, it notifies the client of the need for migration, triggering DiarkisTcpBase::OnOffline/DiarkisUdpBase::OnOffline(). Upon receiving this event, which indicates the necessity for migration, the client executes DiarkisTcpBase::SendMigrate()/DiarkisUdpBase::SendMigrate() to request the server to start migrating. Upon receiving the request, the server disconnects the requesting client, moves the user’s data on the server to the new target server, and then the client reconnects to the new server. This sequence of processes takes place during migration.

Client Response During Migration

As explained in the previous section, on the client side, after receiving DiarkisTcpBase::OnOffline/DiarkisUdpBase::OnOffline(), it is necessary to execute DiarkisTcpBase::SendMigrate()/DiarkisUdpBase::SendMigrate() to proceed with the migration process.

In the sample provided with the SDK, it is implemented as follows to call SendMigrate() immediately after OnOffline() is triggered:

void DiarkisTcp::OnOffline()
{
    DiarkisTcpBase::OnOffline();

    // Due to server scale-in, the connected server will go offline.
    // Invoke SendMigrate at an appropriate timing that matches the app’s implementation to perform server migration.
    this->SendMigrate();
}
void DiarkisUdp::OnOffline()
{
    DiarkisUdpBase::OnOffline();

    // Due to server scale-in, the connected server will go offline.
    // Invoke SendMigrate at an appropriate timing that matches the app’s implementation to perform server migration.
    this->SendMigrate();
}

Note that once DiarkisTcpBase::SendMigrate()/DiarkisUdpBase::SendMigrate() is executed, the reconnection process starts, and the connection to the server is temporarily lost, making communication unavailable for a brief period. The timing of this disconnection can be controlled by when you execute DiarkisTcpBase::SendMigrate()/DiarkisUdpBase::SendMigrate(), so adjust it according to the application's needs.

Last updated