# xSQL Sample HA

> This sample demonstrates a High Availability configuration. It includes master and replica nodes, both using an in-memory database. A static schema is declared in the config files.

> The config files looks like the following:

> `xsql_master.cfg:`

>         #
>         #  Simple In-Memory configuration
>         #
>         database_name : imdb,
>         database_size    :  20m,

>         runtime_configuration : {
>             debug_library : false,
>             disk_support : false,
>             shared_memory : false,
>             transaction_manager : mursiw
>           },
>         schema : "
>         #define uint2     unsigned<2>

>         declare database  locatedb;
>         declare auto_oid [2000];

>         class Employee
>         {
>           string name;
>           uint2 dept_no;

>           unique tree<name> Iname;
>           tree<dept_no>     Idept;
>         };
>         ",
>         db_params: {
>             mem_page_size : 512,
>             disk_page_size : 8192
>         },

>         ha_params: {
>           master_ports : [ 6000 ],
>           #	   cancel_port : 10000
>         },

>         sql_trace : false,
>         sql_port : 5500,
>         sql_statements : "INSERT INTO Employee(name, dept_no) VALUES (['Luke Skywalker', 'Han Solo', 'Darth Vader'], [1,1,2]);"

> `xsql_replica.cfg:`

>         #
>         #  Simple In-Memory configuration
>         #
>         database_name : imdb,
>         database_size    :  20m,

>         runtime_configuration : {
>             debug_library : false,
>             disk_support : false,
>             shared_memory : false,
>             transaction_manager : mursiw
>           },
>         schema : "
>         #define uint2     unsigned<2>

>         declare database  locatedb;
>         declare auto_oid [2000];

>         class Employee
>         {
>           string name;
>           uint2 dept_no;

>           unique tree<name> Iname;
>           tree<dept_no>     Idept;
>         };
>         ",
>         db_params: {
>           mem_page_size : 512,
>           disk_page_size : 8192
>         },

>         ha_params: {
>           master_ports : [6001],
>           connection_strings : ["localhost:6000"]
>         },

>         sql_trace : false,
>         sql_port : 5501

> Note that section `schema` defines the database with inline DDL text and the `sql_statements` section specifies the SQL statements to be executed once the database has been created.

> This sample can be run from two separate command line windows from directory `samples\xsql\configs\ha` with the following command:

>         ..\..\..\..\target\bin\xsql -c xsql_master.cfg -i

> And

>         ..\..\..\..\target\bin\xsql -c xsql_replica.cfg -i

> eXtremeDB will start the master and insert records into it. When the replica is attached, a copy of the master database will be downloaded to it. With xSQL started in interactive mode, we can now execute SQL statements from both master and replica consoles.

> For example:

>         XSQL>select * from Employee;
>         name    dept_no
>         ------------------------------------------------------------------------------
>         Darth Vader     2
>         Han Solo        1
>         Luke Skywalker  1

>         Selected records: 3