1.4.3 - Adding your own partition resp. suffix

This section describes how to add your own data partition.

What are partitions?

In ApacheDS entries are stored in partitions. Each partition contains a complete entry tree, also referred to as a DIT. Multiple partitions may exist and the entry trees they contain are disconnected from each other, meaning that changes to entries in partition A would never affect entries in partition B. The entries in a particular partition are stored below some naming context called the partition suffix.

The default implementation of partitions is based on JDBM B+Trees (but it's possible to add custom partition implementations). The ApacheDS default configuration contains a a data partition with the suffix "dc=example,dc=com". The image below shows the suffixes of a freshly installed ApacheDS within Apache Directory Studio.

Partition in studio after installation

The schema subsystem and ApacheDS itself store their information in special partitions, "ou=schema", "ou=config" and "ou=system" respectively.

Minimal partition definition

For the examples in the following sections, we want to add a partition with the suffix "o=sevenSeas". This requires editing of the configuration, and injecting a first entry, associated with the root of this partition (here, "o=sevenseas"). This can be done using Apache Directory Studio. Open the server configuration :

Studio Apacheds Configuration

and select the Partitions tab :

Studio Apacheds Partitions Configuration

Add another jdbmPartition element for the sevenSeas partition, just below the example partition:

SevenSeas Partition Creation

As you can see, we have modified the ID and the Suffix, all the other parameters remaining to their default values.

Save the configuration now, and restart the server.

The server has a new suffix now, but no context entry has been created for it. If you connect with an LDAP Browser (Apache Directory Studio for instance), the partition is only visible in the Root DSE. Below the Entry Editor of Directory Studio for the Root DSE after connecting to an ApacheDS instance configured like above.

RootDSE

Before using the partition (e.g. adding entries), you have to add a context entry. If you plan to load LDIF data to your partition anyway, simply provide the context entry (the "root" of your partition) as a first data set. In our example it might look like this:

dn: o=sevenSeas
o: sevenSeas
objectClass: top
objectClass: organization
description: The context entry for suffix o=sevenSeas

It is also possible to import a file to ApacheDS which only contains such an entry, of cause. Here is an example on how to procede for the seven seas :

In the LDAP Browser of Directory Studio, right click on the DIT entry and select "Import -> LDIF Import...". A file selections dialog appears. Browse to the LDIF file and click Finish. The entry (or entries, if you provide more of them) will be added to to partition.

The following image depicts the partitions after reconnecting with Apache Directory Studio (LDAP Browser view).

Partition in Studio after addition

Adding a partition programmatically

The same o=sevenseas partition can be created through the application code using the Partition and DirectoryService API

Here is the sample code to create a new partition o=sevenseas and its context entry programmatically

// Get the SchemaManager, we need it for this addition
SchemaManager schemaManager = directoryService.getSchemaManager();

// Create the partition
JdbmPartition sevenseasPartition = new JdbmPartition( schemaManager );
sevenseasPartition.setId("sevenseas");
Dn suffixDn = new Dn( schemaManager, "o=sevenseas" );
sevenseasPartition.setSuffix( suffixDn );
sevenseasPartition.setCacheSize(1000);
sevenseasPartition.init(directoryService);
sevenseasPartition.setPartitionPath( <a path on your disk> );

// Create some indices (optional)
sevenseasPartition.addindex( new JdbmIndex( "objectClass", false ) );
sevenseasPartition.addindex( new JdbmIndex( "o", false ) );

// Initialize the partition
sevenseasPartition.initialize();

// create the context entry
Entry contextEntry = new DefaultEntry( schemaManager, "o=sevenseas",
    "objectClass: top", 
    "objectClass: organization",
    "o: sevenseas" );

// add the context entry
sevenseasPartition.add( new AddOperationContext( null, entry ) );

// We are done !

More configuration options for a JDBM partition

Here is a list of the used attributes, their default values and meaning :

Property Description Default Value Required
ads-partitionId Uniquely identifies the partition N/A yes
ads-partitionSuffix A DN ("o=sevenseas"), for instance N/A yes
ads-contextEntry The context entry Will be automatically deduced if no value is provided no
ads-optimizerEnabled Tells the server to turn on the optimizer true no
ads-partitionCacheSize The cache size (only for JDBM partitions) -1 (no cache) no
ads-partitionSyncOnWrite Syncs disks on every write operation true no