Example of Using Templates and Host Tags

This section provides an example of the use of templates. The example starts with the SQL QuickStart database, which uses the Single Host template, and converts the database to use the Minimally Redundant template. To accomplish this, the example uses template variables and host tags.

In this example, three hosts are configured. The template variables TE_HOST_TAG and SM_HOST_TAG control which hosts should run TEs and which hosts should run SMs. The template variable TE_HOST_TAG will be set to HOST_FOR_TE and the template variable SM_HOST_TAG will be set to HOST_FOR_SM. In the example domain:

This means one host will run both a TE and SM process, one host will run only a TE, and one host will run only an SM. A host tag is a key/value pair specified for the host. In this example, the value can be anything (1 in the example below) because the constraint specified for each template variable, TE_HOST_TAG and SM_HOST_TAG, is that it exists (ex:).

In the example below, the three hosts are Amazon EC2 instances. This example shows how to edit the single host SQL QuickStart database to convert it to a minimally redundant database. See Running the SQL QuickStart for more information about the QuickStart database. Changing the SQL QuickStart database from using the Single Host template to using the Minimally Redundant template is similar to the procedure described in Upgrading Your First Database to Be Minimally Redundant. The difference here is that the three hosts are configured to use host tags.

Use the Automation Console to see the three hosts in the domain:

For the first host, set the HOST_FOR_TE tag to 1 and set the HOST_FOR_SM tag to 1. It does not matter what value is specified because the constraint is that the tag exists (ex:).

For the second host, set the HOST_FOR_TE tag to 1 and for the third host, set the HOST_FOR_SM tag to 1. To see the host tags that are set in the domain, invoke the NuoDB Manager command tags list without specifying a host. For example:

nuodb [domain] > tags list
Host: 
ec2-54-165-58-157.compute-1.amazonaws.com/172.31.46.122:48004 (us-east-1):
    HOST_FOR_SM = 1
    archive_base = /var/opt/nuodb/production-archives
    cores = 1
...
ip-172-31-14-118/54.173.96.113:48004 (us-east-1):
    HOST_FOR_SM = 1
    HOST_FOR_TE = 1
    archive_base = /var/opt/nuodb/production-archives
    cores = 1
...
ip-172-31-40-24/107.23.52.10:48004 (us-east-1):
    HOST_FOR_TE = 1
    archive_base = /var/opt/nuodb/production-archives
    cores = 1
...

Run the SQL QuickStart to create a single host database. This does not do anything with the host tags that have been set in the domain. The domain has three hosts and one of those hosts is now running two processes: a TE and an SM:

Edit the SQL QuickStart database to change it to use the Minimally Redundant template. Set the template variable SM_HOST_TAG to HOST_FOR_SM with the exists constraint (ex:). Also set the template variable TE_HOST_TAG to HOST_FOR_TE with the exists constraint:

Now the domain looks like this:

The first host is running two processes, one TE and one SM. The second host is running one TE process and the third host is running one SM process. Use NuoDB Manager to look at the database configuration for this database:

nuodb [domain] > show database config
Database: test
Database: test, ACTIVE, Status=RUNNING, template [Minimally Redundant]
  Variables: {SM_HOST_TAG=HOST_FOR_SM, SM_MAX=2, TE_MAX=2, TE_MIN=2, 
      REGION=us-east-1, SM_MIN=2, TE_HOST_TAG=HOST_FOR_TE
  Options: {commit=remote:1, mem=2g, hostLimit=false}
  Default Options: { "commit": "${COMMIT:remote:1}","backoff.reqMinUptime":"30000","hostLimit":"${HOST_LIMIT:false}"}
  Archive Locations:
    ip-172-31-14-118/54.173.96.113:48004, requirements: SMs, region: us-east-1:
      archive: /var/opt/nuodb/production-archives/test
      journal-dir: /var/opt/nuodb/production-archives/test
    ip-172-31-46-122/54.165.58.157:48004, requirements: SMs, region: us-east-1:
      archive: /var/opt/nuodb/production-archives/test
      journal-dir: /var/opt/nuodb/production-archives/test
  Minimally Redundant MET

This shows that the test database is ACTIVE, RUNNING and uses the Minimally Redundant template. The database has the following template variables set:

Variable Setting
SM_HOST_TAG HOST_FOR_SM
SM_MAX 2
TE_MAX 2
TE_MIN 2
REGION us-east-1
SM_MIN 2
TE_HOST_TAG HOST_FOR_TE