Version 2.5.3
Configuration Strings in Java

Introduction

Methods in WiredTiger take a configuration string to provide optional arguments and configure non-standard behaviors. These strings are simple comma-separated lists of "<key>=<value>" pairs, and all have the same format:

    [key['='value]][','[key['='value]]]*

Keys and values and values that consist of alphanumeric characters can be specified directly. More precisely, keys or values that match this regular expression do not require quotes:

    [-_0-9A-Za-z./][^\t\r\n :=,\])}]*

Configuration strings are case-sensitive (for example, "true" is a valid boolean value, but "True" is not).

More complex keys and values can be specified by quoting them with double quotes.

For example, a configuration string is used when opening a connection to a database to specify if the database should be created and to set the cache size:

conn = wiredtiger.open(home, "create,cache_size=500M");

Configuration strings are also used to configure the table schema. For example, to create a table that uses C language strings for keys and values:

ret = session.create("table:mytable", "key_format=S,value_format=S");

To handle more complex schema configuration, such as specifying multiple columns in a table, values are nested using parentheses. For example:

/*
* Create a table with columns: keys are record numbers, values are
* (string, signed 32-bit integer, unsigned 16-bit integer).
*/
ret = session.create("table:mytable",
"key_format=r,value_format=SiH," +
"columns=(id,department,salary,year-started)");

All types of parentheses are treated equivalently by the parser.

When an integer values is expected, the value may have multiplier characters appended, as follows:

CharacterMeaningChange to value
B or b byteno change
K or k kilobytemultiply by 2^10
M or m megabytemultiply by 2^20
G or g gigabytemultiply by 2^30
T or t terabytemultiply by 2^40
P or p petabytemultiply by 2^50

For example, the value 500B is the same as entering the number 500, the value 500K is the same as 512000 and the string 500GB is the same as 536870912000.

Values of type of "boolean" can be set to any of false, true, 0 or 1. If no value is specified for a key, the value 1 is implied. For example, all of the following forms of the overwrite configuration string are identical:

cursor = session.open_cursor("table:mytable", null, "overwrite");
cursor = session.open_cursor("table:mytable", null, "overwrite=true");
cursor = session.open_cursor("table:mytable", null, "overwrite=1");

Configuration strings are processed in order from left to right, with later settings overriding earlier ones (unless multiple settings for a key are supported by the method).

Superfluous commas and whitespace in the configuration string are ignored (including at the beginning and end of the string), so it is always safe to combine two configuration strings by concatenating them with a comma in between.

Empty configuration strings may be represented in Java by passing null.

JavaScript Object Notation (JSON) compatibility

WiredTiger configuration strings are compatible with JavaScript Object Notation (JSON), and will accept additional formatting as follows:

  • parentheses may be round or square brackets or curly braces: '()', '[]' or '{}'
  • the whole configuration string may optionally be wrapped in parentheses
  • the key/value separator can be a colon: ':'
  • keys and values may be in double quotes: "key" = "value"
  • quoted strings are interpreted as UTF-8 values

The result of this relaxed parsing is that applications may pass strings representing valid JSON objects wherever configuration strings are required.

For example, in Python, code might look as follows:

import json
config = json.dumps({
"key_format" : "r",
"value_format" : "5sHQ",
"columns" : ("id", "country", "year", "population"),
"colgroup.population" : ["population"],
"index.country_year" : ["country", "year"]
})

Because JSON compatibility allows colons to be used as key/value separators, WiredTiger URIs may require quoting. For example, the following Session.checkpoint call specifies a set of URIs as checkpoint targets, using double-quote characters to keep the parser from treating the colon characters as JSON name/value separators:

/*
* Checkpoint a list of objects.
* JSON parsing requires quoting the list of target URIs.
*/
ret = session.
checkpoint("target=(\"table:table1\",\"table:table2\")");