# xSQL Sample Cluster

> This sample demonstrates a simple cluster configuration with 3 nodes using in-memory databases. The static schema is defined in the config files.

> The config files look like the following:

> `node1.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
>         },

>         cluster_params: {
>          nodes : [
>          {
>          addr : "127.0.0.1:6001",
>          qrank : 1
>          },
>          {
>          addr : "127.0.0.1:6002",
>          qrank : 1
>          },
>          {
>          addr : "127.0.0.1:6003",
>          qrank : 1
>          },
>          ],
>          node_id : 0,
>         },

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

> `node2.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
>         },

>         cluster_params: {
>          nodes : [
>          {
>          addr : "127.0.0.1:6001",
>          qrank : 1
>          },
>          {
>          addr : "127.0.0.1:6002",
>          qrank : 1
>          },
>          {
>          addr : "127.0.0.1:6003",
>          qrank : 1
>          },
>          ],
>          node_id : 1,
>         },

>         sql_trace : false,
>         sql_port : 5501

> `node3.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
>         },

>         cluster_params: {
>          nodes : [
>          {
>          addr : "127.0.0.1:6001",
>          qrank : 1
>          },
>          {
>          addr : "127.0.0.1:6002",
>          qrank : 1
>          },
>          {
>          addr : "127.0.0.1:6003",
>          qrank : 1
>          },
>          ],
>          node_id : 2,
>         },

>         sql_trace : false,
>         sql_port : 5502

> 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 3 separate console windows from directory `samples\xsql\configs\cluster` with the following commands:

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

> And

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

> And

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

> With xSQL started in interactive mode. Now the cluster is loaded and changes may be applied to any node. We can execute SQL statements.

> For example:

> In console 1 type:

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

>         Selected records: 3

>         XSQL>insert into Employee values (‘Chubaka’, 4);

> In console 2 type:

>         XSQL>update Employee set dept_no=7 where name=’Chubaka’;

> In console 3 type:

>         XSQL>select * from Employee;
>         auto_oid@       name    dept_no
>         ------------------------------------------------------------------------------
>         4       Chubaka 7
>         3       Darth Vader     2
>         2       Han Solo        1
>         1       Luke Skywalker  1
>         Selected records: 4