Library Version 11.2.5.3

Reverse BTree Splits
Prev | Chapter 4. Concurrency | Next

## Reverse BTree Splits

If your application is using the Btree access method, and your application is repeatedly deleting then adding records to your database, then you might be able to reduce lock contention by turning off reverse Btree splits.

As pages are emptied in a database, DB attempts to delete empty pages in order to keep the database as small as possible and minimize search time. Moreover, when a page in the database fills up, DB, of course, adds additional pages to make room for more data.

Adding and deleting pages in the database requires that the writing thread lock the parent page. Consequently, as the number of pages in your database diminishes, your application will see increasingly more lock contention; the maximum level of concurrency in a database of two pages is far smaller than that in a database of 100 pages, because there are fewer pages that can be locked.

Therefore, if you prevent the database from being reduced to a minimum number of pages, you can improve your application's concurrency throughput. Note, however, that you should do so only if your application tends to delete and then add the same data. If this is not the case, then preventing reverse Btree splits can harm your database search time.

To turn off reverse Btree splits, set `DatabaseConfig.setReverseSplitOff()`. to `true`.

For example:

    package db.txn;

    import com.sleepycat.db.Database;
    import com.sleepycat.db.DatabaseType;
    import com.sleepycat.db.DatabaseConfig;
    import com.sleepycat.db.DatabaseException;
    import com.sleepycat.db.Environment;
    import com.sleepycat.db.EnvironmentConfig;

    import java.io.File;
    import java.io.FileNotFoundException;

    ...

    Database myDatabase = null;
    Environment myEnv = null;
    try {
        EnvironmentConfig myEnvConfig = new EnvironmentConfig();
        myEnvConfig.setInitializeCache(true);
        myEnvConfig.setInitializeLocking(true);
        myEnvConfig.setInitializeLogging(true);
        myEnvConfig.setTransactional(true);

        myEnv = new Environment(new File("/my/env/home"),
                                  myEnvConfig);

        // Open the database.
        DatabaseConfig dbConfig = new DatabaseConfig();
        dbConfig.setTransactional(true);
        dbConfig.setType(DatabaseType.BTREE);

        // Set BTree reverse split to off
        dbConfig.setReverseSplitOff(true);

        myDatabase = myEnv.openDatabase(null,               // txn handle
                                        "sampleDatabase",   // db file name
                                        "null",             // db name
                                        dbConfig);
    } catch (DatabaseException de) {
        // Exception handling goes here
    } catch (FileNotFoundException fnfe) {
        // Exception handling goes here
    }

Or, if you are using the DPL:

    package db.txn;

    import com.sleepycat.db.Database;
    import com.sleepycat.db.DatabaseType;
    import com.sleepycat.db.DatabaseConfig;
    import com.sleepycat.db.DatabaseException;
    import com.sleepycat.db.Environment;
    import com.sleepycat.db.EnvironmentConfig;

    import java.io.File;
    import java.io.FileNotFoundException;

    ...

    EntityStore myStore = null;
    Environment myEnv = null;
    try {
        EnvironmentConfig myEnvConfig = new EnvironmentConfig();
        myEnvConfig.setInitializeCache(true);
        myEnvConfig.setInitializeLocking(true);
        myEnvConfig.setInitializeLogging(true);
        myEnvConfig.setTransactional(true);

        myEnv = new Environment(new File("/my/env/home"),
                                  myEnvConfig);

        // Configure the store.
        StoreConfig myStoreConfig = new StoreConfig();
        myStoreConfig.setAllowCreate(true);
        myStoreConfig.setTransactional(true);

        // Configure the underlying database.
        DatabaseConfig dbConfig = new DatabaseConfig();
        dbConfig.setTransactional(true);
        dbConfig.setAllowCreate(true);
        dbConfig.setType(DatabaseType.BTREE);

        // Set BTree reverse split to off
        dbConfig.setReverseSplitOff(true);

        // Instantiate the store
        myStore = new EntityStore(myEnv, "store_name", myStoreConfig);

        // Set the DatabaseConfig object, so that the underlying
        // database is configured for uncommitted reads.
        myStore.setPrimaryConfig(SomeEntityClass.class, dbConfig);

    } catch (DatabaseException de) {
        // Exception handling goes here
    } catch (FileNotFoundException fnfe) {
        // Exception handling goes here
    }

Prev | Up | Next
No Wait on Blocks | Home | Chapter 5. Managing DB Files