Migrate Room When Server Is Auto-Shrinking

Diarkis server is capable of auto-scale and scaling servers go both ways. It is especially critical to handle server scale in with connected clients to make sure the clients will not be affected by the auto shrink of the server.

When the server that the client is connected is marked for shutdown for auto-shrink, an event called "OnOffline" is raised. By handling "OnOffline" event, the client may continue with the service without being interrupted.

The clients are able to continue with the message communication with other clients, but the client should be switching its connection to another server as soon as possible.

Diarkis Room comes with a unique feature called "Room Migration". 

It allows a room to preserve room states including properties and its members to migrate to another server that will not shutdown.

room-migration

NOTE: Room owner will be maintained, but if the room owner fails to "re-join" the migrated room, another member will be auto-elected to be a new owner of the room.

IMPORTANT: The room that the clients migrate to will have a different room ID than before the migration.

C# Client Code Example:

The example executes Room migration when the client raises the OnOffline event triggered by the server.

// UDP client
udpDiarkisClient.OnOffline(HandleOnOffline);

// TCP client
tcpDiarkisClient.OnOffline(HandleOnOffline);

private void HandleOnOffline()

{

  // This will start Room Migration immediately.
  // room.OnMemberLeave and room.OnMemberJoin will be raised respectively.
    room.Migrate();

}

Detecting Room Migration On the Server

The room module can detect room migration and allows you to execute operations using callbacks.

Server Code Example:

import "github.com/Diarkis/diarkis/room"

room.SetOnMigrated(handleOnRoomMigration)

func handleOnRoomMigration(newRoomID string, oldRoomID string) {
// if you manage room IDs outside of Diarkis such as KVS and RDB etc.
// update the room IDs here and now
}