Support and Documentation

Database configuration

Database-specific configuration parameters are prefixed with the dari/database/{databaseName}/ namespace, where databaseName is a unique string. Multiple databases can be configured with different databaseName values. You can also set a default database, where data is stored when a database is not specified in an API call.

The following example from a Tomcat context.xml file shows how a namespace is used to identify configuration of a H2 database. In this case, the configuration is identified as tutorial.local; all configuration options for this database share the same namespace.

<!-- Database -->
<Environment name="dari/defaultDatabase" type="java.lang.String" value="tutorial.local"/>
<Environment name="dari/database/tutorial.local/class" type="java.lang.String" value="com.psddev.dari.h2.H2Database"/>
<Environment name="dari/database/tutorial.local/dataSource/class" type="java.lang.String" value="org.h2.jdbcx.JdbcDataSource"/>
<Environment name="dari/database/tutorial.local/dataSource/url" type="java.lang.String" value="jdbc:h2:/Users/rl/brightspot-tutorial/.h2"/>
<Environment name="dari/database/tutorial.local/dataSource/user" type="java.lang.String" value="root"/>
<Environment name="dari/database/tutorial.local/dataSource/password" type="java.lang.String" value=""/>

Dari database classes implement com.psddev.dari.db.Database. Most of the implementations are subclasses of AbstractDatabase. Another implementation, AggregateDatabase, provides the capability to use multiple databases. That is, the class aggregates multiple databases to appear as one database to your application.

Configuration options for frequently used databases are described below. For other supported databases, you can find their configuration options in the Dari Javadoc.

Dari provides the Database Bootstrap tool to migrate database objects from one Brightspot project to another. The tool must be configured to identify export and import databases. For more information, see Exporting and importing between databases.

General database configuration

The following table lists the configuration values for all supported databases.

Key

Type

Description

dari/defaultDatabase

java.lang.String

Name of the default database.

dari/database/{databaseName}/class

java.lang.String

Class name of a com.psddev.dari.db.Database implementation.

dari/database/{databaseName}/readTimeout

java.lang.Double

Sets the read timeout for this database. The default is 3 seconds.

dari/databaseWriteRetryLimit

java.lang.Integer

Number of times to retry a transient failure. The default value is 10.

dari/databaseWriteRetryInitialPause

java.lang.Integer

Initial amount of time in milliseconds to wait before retrying a transient failure. The default value is 10ms.

dari/databaseWriteRetryFinalPause

java.lang.Integer

Maximum amount of time in milliseconds to wait before retrying a transient failure. The default value is 1000ms.

dari/databaseWriteRetryPauseJitter

java.lang.Double

Amount of time to adjust the pause between retries so that multiple threads retrying at the same time will stagger. This helps break deadlocks in certain databases such as MySQL. The default value is 0.5.

The pause value is calculated as initialPause + (finalPause - initialPause) * i / (limit - 1). This is then jittered + or - pauseJitter percent. For example, if dari/databaseWriteRetryLimit is 10, dari/databaseWriteRetryFinalPause is 1000ms, and dari/databaseWriteRetryPauseJitter is 0.5, then on the first retry, Dari will wait between 5ms and 15ms. On the second try, Dari will wait between 60ms and 180ms, continuing until the 10th and final try, which will wait between 500ms and 1500ms.

Configuring an SQL database

The following table lists the configuration values for SqlDatabase.

Key

Type

Description

dari/database/{databaseName}/class

java.lang.String

Set to com.psddev.dari.db.SqlDatabase for all SQL databases.

dari/isCompressSqlData

java.lang.Boolean

Enable or disable compression of Dari object data in the database. Dari uses the Snappy compression library for compression. The default is false. For best performance, enable compression only if your dataset is over 50GB.

To enable compression, you must include Snappy in your pom.xml file as follows:

<dependency>
    <groupId>org.iq80.snappy</groupId>
    <artifactId>snappy</artifactId>
    <version>0.2</version>
</dependency>

dari/database/{databaseName}/dataSource

Resource

Database resource. All writes will go the database configured by dataSource.

dari/database/{databaseName}/readDataSource

Resource

Optional. To have reads go to a slave, configure readDataSource.

dari/database/{databaseName}/jdbcUrl

java.lang.String

Database JDBC URL. All writes will go the database configured by jdbcUrl.

dari/database/{databaseName}/readJdbcUrl

java.lang.String

Optional. To have reads to go to a slave, configure readJdbcUrl.

dari/database/{databaseName}/jdbcUser

java.lang.String

Database user name. All writes will go the database configured by jdbcUser.

dari/database/{databaseName}/readJdbcUser

java.lang.String

Optional. To have reads go to a slave, configure readJdbcUser.

dari/database/{databaseName}/jdbcPassword

java.lang.String

Database password. All writes will go the database configured by jdbcPassword.

dari/database/{databaseName}/readJdbcPassword

java.lang.String

Optional. To have reads go to a slave, configure readJdbcPassword.

Note

To use Tomcat connection pooling, define a JNDI Resource in context.xml with the name dari/database/{databaseName}/dataSource.

Configuring aggregated databases

AggregateDatabase is an implementation of com.psddev.dari.db.Database that allows objects to be written to and read from multiple database back ends. Typically this is used to read and write to both MySQL and Solr. This allows normal reads to go to MySQL and full-text search to use Solr.

Key

Type

Description

dari/database/{databaseName}/defaultDelegate

java.lang.String

Name of primary database. It will be written to first and should be considered the source of record for all objects. This is usually one of the SQL back ends.

The following snippet mimics an aggregate-database configuration in a Tomcat context.xml file. In this example, AggregateDatabase is configured to read from a MySQL slave and write to a MySQL master. Solr is configured to read and write to the same host.

# Aggregate Database Configuration
dari/defaultDatabase = production
dari/database/production/defaultDelegate = sql
dari/database/production/class = com.psddev.dari.db.AggregateDatabase
dari/database/production/delegate/sql/class = com.psddev.dari.db.SqlDatabase

# Master Configuration
dari/database/production/delegate/sql/jdbcUser = username
dari/database/production/delegate/sql/jdbcPassword = password
dari/database/production/delegate/sql/jdbcUrl = jdbc:msyql://master.mycompany.com:3306/dari

# Slave Configuration
dari/database/production/delegate/sql/readJdbcUser = username
dari/database/production/delegate/sql/readJdbcPassword = password
dari/database/production/delegate/sql/readJdbcUrl = jdbc:msyql://slave.mycompany.com:3306/dari

# Solr Configuration
dari/database/production/delegate/solr/class = com.psddev.dari.db.SolrDatabase
dari/database/production/delegate/solr/serverUrl = http://solr.mycompany.com/solr
Configuring a Solr database

The following table lists the configuration values for SolrDatabase.

Key

Type

Description

dari/database/{databaseName}/class

java.lang.String

Set to com.psddev.dari.db.SolrDatabase for Solr databases.

dari/database/{databaseName}/serverUrl

java.lang.String

URL to the master Solr server.

dari/database/{databaseName}/readServerUrl

java.lang.String

Optional. URL to slave Solr server.

dari/database/{databaseName}/commitWithin

java.lang.Integer

Maximum amount of time in seconds to wait before committing to Solr.

dari/database/{databaseName}/saveData

java.lang.Boolean

Determines if Dari record data (JSON blob) is saved to Solr. Disabling this will reduce the size of the Solr index at the cost of extra reads from the MySQL database. Only enable this if you have another database configured as the primary.

dari/subQueryResolveLimit

java.lang.Integer

Because Solr does not currently support joins, Dari will execute subqueries separately. This limits the size of the results to prevent generating too large of a query.

Exporting and importing between databases

You can migrate database objects from one Brightspot environment to another with Dari's Database Bootstrap tool. The tool must be configured with a source, export database and a destination, import database.