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 Export/Import.

General

The following named values apply to all supported databases.

Key: dari/defaultDatabase Type: java.lang.String
The name of the default database.
Key: dari/database/{databaseName}/class Type: java.lang.String
The class name of a com.psddev.dari.db.Database implementation.
Key: dari/database/{databaseName}/readTimeout Type: java.lang.Double
Sets the read timeout for this database. The default is 3 seconds.
Key: dari/databaseWriteRetryLimit Type: java.lang.Integer
The number of times to retry a transient failure. The default value is 10.
Key: dari/databaseWriteRetryInitialPause Type: java.lang.Integer
The initial amount of time in milliseconds to wait before retrying a transient failure. The default value is 10ms.
Key: dari/databaseWriteRetryFinalPause Type: java.lang.Integer
The maximum amount of time in milliseconds to wait before retrying a transient failure. The default value is 1000ms.
Key: dari/databaseWriteRetryPauseJitter Type: java.lang.Double

The 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 like 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.

SQL Database

The following named values apply to SqlDatabase.

Key: dari/database/{databaseName}/class Type: java.lang.String
Set to com.psddev.dari.db.SqlDatabase for all SQL databases.
Key: dari/isCompressSqlData Type: java.lang.Boolean

Enable or disable compression of Dari object data in the database. Dari uses the Snappy compression library for compression. To enable compression, you must include Snappy in your pom.xml file as follows: org.iq80.snappy snappy 0.2.

The default is false. We recommend only enabling compression if your dataset is over 50GB.

Key: dari/database/{databaseName}/dataSource Type: Resource
The database resource. All writes will go the database configured by dataSource.
Key: dari/database/{databaseName}/readDataSource Type: Resource
Optional. To have reads go to a slave, configure readDataSource.
Key: dari/database/{databaseName}/jdbcUrl Type: java.lang.String
The database JDBC URL. All writes will go the database configured by jdbcUrl.
Key: dari/database/{databaseName}/readJdbcUrl Type: java.lang.String
Optional. To have reads to go to a slave, configure readJdbcUrl.
Key: dari/database/{databaseName}/jdbcUser Type: java.lang.String
The database user name. All writes will go the database configured by jdbcUser.
Key: dari/database/{databaseName}/readJdbcUser Type: java.lang.String
Optional. To have reads go to a slave, configure readJdbcUser.
Key: dari/database/{databaseName}/jdbcPassword Type: java.lang.String
The database password. All writes will go the database configured by jdbcPassword.
Key: dari/database/{databaseName}/readJdbcPassword Type: 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.

Aggregate Database

AggregateDatabase is an implementation of com.psddev.dari.db.Database that allows objects to be written to and read from multiple database backends. 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: dari/database/{databaseName}/defaultDelegate Type: java.lang.String
This is the name of the 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 backends.

Example Configuration

This is an example configuration from a Tomcat context.xml file. 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

Solr Database

The following named values apply to SolrDatabase.

Key: dari/database/{databaseName}/class Type: java.lang.String
Set to com.psddev.dari.db.SolrDatabase for Solr databases.
Key: dari/database/{databaseName}/serverUrl Type: java.lang.String
The URL to the master Solr server.
Key: dari/database/{databaseName}/readServerUrl Type: java.lang.String (Optional)
The URL to slave Solr server.
Key: dari/database/{databaseName}/commitWithin Type: java.lang.Integer
The maximum amount of time in seconds to wait before committing to Solr.
Key: dari/database/{databaseName}/saveData Type: 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.
Key: dari/subQueryResolveLimit Type: java.lang.Integer
Since 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.

Export/Import

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.