# Persistence configuration

Transformer’s built-in Persistence Service provides a persistent key-value store, shareable between nodes in a Transformer cluster. The configuration items here are used to define how persistence databases and files are accessed and controlled.

## Overview

The Persistence Service is disabled by default. To activate the Persistence Service, see Activating the Persistence Service 7.

The Persistence Service 7 persists data to a JDBC-compliant relational database server or to the local file system. From version 7 of the Persistence Service, a JDBC database server is the only persistence store that can be used in a Transformer cluster. File-backed persistence (persisting data to the local file system) is provided as an option of convenience for development environments, but it is unsupported in production environments.

 File-backed persistence is unsupported in production environments, and, from version 7 of the Persistence Service, file-backed persistence cannot be used in Transformer clusters.

To configure persistence to a database, besides defining the relevant configuration items that are documented here, you’ll also need to set up the persistence database, giving it a name, defining the table and columns needed to store the persisted data, and defining the usernames(s) and access permissions that will allow Transformer to write and read the data.

Add your persistence configuration to the file `<Framework-root>/global_config/overrides/PersistenceService/Transformer/etc/persistence.conf`, where `<Framework-root>` is your Deployment Framework’s top-level directory.

 In the following documentation, the term "this Transformer" means the Transformer for which you are defining the configuration, and "this node" means the cluster node that "this Transformer" represents.

## Example configuration

Example persistence configuration for Transformer 6.2 and Transformer 7:

Persist to a JDBC database (Transformer 7)
```persistence-classid com/caplin/transformer/persistence/JdbcPersistorImpl
init-string    jdbc:mysql://192.168.1.50:3306/rtas
Persist to a JDBC database (Transformer 6.2)
```persistence-classid com/caplin/transformer/persistence/JdbcPersistorImpl
init-string    jdbc:mysql://192.168.1.50:3306/rtas
table-name     persistence
columns        pers_key pers_val
Persist to a local file (not supported in production)
```enable-file-database
init-string    ${ccd}/persistence.db end-add-database-params``` ## add-database-params `add-database-params` specifies parameters for the database or file used to persist data. Syntax: Persist to a JDBC database ```add-database-params init-string [string] driver-name [string] username [string] password [string] table-name [string] columns [array of strings] extra-params [array of strings] end-add-database-params``` Persist to a local file (not supported in production) ```add-database-params init-string [string] end-add-database-params``` Option Type Default Description `columns` array of strings [none] A space-separated list of the names of the database columns where the persisted data is stored. Each piece of data is stored as a key-value pair. The names of the database columns should be listed in this order: <key column> <value column>. For example, to persist keys to a column called 'pers_key' and values to a column called 'pers_val', use the configuration below: `columns pers_key pers_val`  This option is for Transformer 6.2 only. This option is not recognised by Transformer 7 and its presence will raise an error. `driver-name` string [none] The name of the JDBC driver. For example: `org.mariadb.jdbc.Driver` `extra-params` array of strings [implementation dependent] An optional list of additional parameters recognised by the `Persistor` class specified by the `persistence-classid` configuration item. The default JDBC implementation of `Persistor` in Transformer 7 is `JdbcPersistorImpl`. The `extra-params` option for this class has the following syntax: `extra-params <connection-validation-timeout> <query-execution-timeout>` <connection-validation-timeout> Timeout in seconds when checking that a JDBC `Connection` has not been closed and is still valid. Defaults to 5 (seconds). This value is passed to the JDBC method call `Connection.isValid(int timeout)` Example: set connection validation timeout to 5 seconds `extra-params 5` <query-execution-timeout> Timeout in seconds for query execution. Defaults to 1 (second). Specify -1 for no timeout. Available since Transformer 7.1.2. Example: set query execution timeout to 1 second `extra-params 5 1` `init-string` string [none] Initialisation string for the persistence database or file. • If data is persisted to a file, this is the directory name and path of the file. In the Persistence Config blade the default file path and name is `${ccd}/persistence`, where `\${ccd}` is the Transformer’s current configuration directory.

• If data is persisted to a database, this is the JDBC URL of the database; for example: `jdbc:mysql://localhost/mydatabase`

`password`

string

[none]

The database access password associated with `username`.

`table-name`

string

[none]

The name of the database table where the persisted data is stored.

 This option is for Transformer 6.2 only. This option is not recognised by Transformer 7 and its presence will raise an error.

`username`

string

[none]

## disable-cluster-replication

 Persistence Service 6.2 only. The Persistence Service 7 does not replicate persisted values between nodes in a cluster.

`disable-cluster-replication` when `TRUE`, prevents this Transformer from sending to the other Transformers in the cluster data that it has already persisted.

When persistence is file-based, don’t specify `disable-cluster-replication`. The default value of `FALSE` then applies, and, although each Transformer in the cluster maintains its own persistence file, this Transformer sends a copy of its persisted data to every other Transformer so that they can also write it to their own persistence files.

Conversely, when a (shared) persistence database is used, you should set `disable-cluster-replication` to `TRUE` on every node in the cluster to prevent multiple copies of the same data being persisted to the (shared) database. You should set `dont-persist-cluster-messages` to `TRUE` as well.

Version: 6.2

Syntax: `disable-cluster-replication <boolean>`

Type: boolean

Default value: `FALSE`

## dont-persist-cluster-messages

 Persistence Service 6.2 only. The Persistence Service 7 does not replicate persisted values between nodes in a cluster.

`dont-persist-cluster-messages` when `TRUE`, ensures that messages received from another Transformer in the cluster are not persisted on this Transformer.

When persistence is file-based, don’t specify `dont-persist-cluster-messages`. The default value of `FALSE` then applies, so that this Transformer saves to its own persistence file all the persisted data that other Transformers in the cluster send to it.

Conversely, when a (shared) persistence database is used, you should set `dont-persist-cluster-messages` to `TRUE` on every node in the cluster, to prevent the same data being persisted to the database multiple times (the data’s then persisted solely by the Transformer where it originated). You should set `disable-cluster-replication` to `TRUE` as well.

Version: 6.2

Syntax: `dont-persist-cluster-messages <boolean>`

Type: boolean

Default value: `FALSE` (messages from another cluster node are always persisted on this node)

## enable-file-database

`enable-file-database` when `TRUE`, enables file-based persistence.

 File-backed persistence is unsupported in production environments, and, from version 7 of the Persistence Service, file-backed persistence cannot be used in Transformer clusters.

Version: 6.2, 7.0+

Syntax: `enable-file-database <boolean>`

Type: boolean

Default value: `FALSE` (data is persisted to a database)

## logfile

`logfile` specifies the name of the file in which events about persisting data are recorded.

The filename can contain the parameters `%a` and `%h` At run time, `%a` is replaced by the Transformer’s application name (see the DataSource configuration item `application-name`), and `%h` is replaced by the host name of the machine on which the Transformer is running.

Version: 6.2, 7.0+

Syntax: `logfile <log-file-name>`

Type: string

Default value: `persistence.log`

## log-level

`log-level` specifies the severity of the errors and events that Transformer’s persistence module writes to its log file (see `logfile`).

Version: 6.2, 7.0+

Syntax: `log-level <log-level-name>`

Type: string

Default value: `INFO`

Values accepted:

Level Description

`DEBUG`

Reports all errors and events.

`INFO`

Reports events and information regarding normal operation of the persistence module, and all errors included in the `WARN`, `NOTIFY`, `ERROR` and `CRIT` log levels.

`WARN`

Reports minor errors and all errors included in the `NOTIFY`, `ERROR` and `CRIT` log levels.

`NOTIFY`

Reports errors regarding data corruptions and all errors included in the `ERROR` and `CRIT` log levels.

`ERROR`

Reports serious errors and all errors included in the `CRIT` log level.

`CRIT`

Reports critical errors that prevent the persistence module from running.

## persistence-classid

`persistence-classid` specifies the Java class ID of the implementation of the Java `Persistor` interface that provides this Transformer’s database persistence capability. There’s a basic JDBC implementation of `Persistor` that’s provided with, and used by, Transformer’s Persistence Config blade; it’s called `JdbcPersistorImpl`. (For more about `Persistor` and `JdbcPersistorImpl`, see the Transformer Persistence API for Java documentation.)

The class ID is conventionally the fully-qualified name of the implementation of `Persistor`, with periods (.) replaced by foward slashes (/).

Version: 6.2, 7.0+

Syntax: `persistence-classid <java-class-id>`

Type: string

Default value: (none; but `persistence-classid` is only required if `enable-file-database` is `FALSE`)

Example:

`persistence-classid com/caplin/transformer/persistence/JdbcPersistorImpl`

If you’ve created your own implementation of `Persistor`, you must also specify your implementation class in an `add-javaclass` configuration item. Set the `add-javaclass::class-id` option to the same value that you used for `persistence-classid`.