Search in sources :

Example 26 with Environment

use of com.sleepycat.je.Environment in project voldemort by voldemort.

the class BdbStorageEngineTest method setUp.

@Override
@Before
public void setUp() throws Exception {
    super.setUp();
    this.envConfig = new EnvironmentConfig();
    this.envConfig.setDurability(Durability.COMMIT_NO_SYNC);
    this.envConfig.setAllowCreate(true);
    this.envConfig.setTransactional(true);
    this.tempDir = TestUtils.createTempDir();
    this.environment = new Environment(this.tempDir, envConfig);
    this.databaseConfig = new DatabaseConfig();
    databaseConfig.setAllowCreate(true);
    databaseConfig.setTransactional(true);
    databaseConfig.setSortedDuplicates(false);
    this.database = environment.openDatabase(null, "test", databaseConfig);
    this.runtimeConfig = new BdbRuntimeConfig();
    runtimeConfig.setLockMode(LOCK_MODE);
    this.store = makeBdbStorageEngine("test", this.environment, this.database, runtimeConfig, this.prefixPartitionId);
}
Also used : EnvironmentConfig(com.sleepycat.je.EnvironmentConfig) Environment(com.sleepycat.je.Environment) DatabaseConfig(com.sleepycat.je.DatabaseConfig) Before(org.junit.Before)

Example 27 with Environment

use of com.sleepycat.je.Environment in project qpid-broker-j by apache.

the class UpgradeFrom5To6Test method testPerformXidUpgrade.

@Test
public void testPerformXidUpgrade() throws Exception {
    File storeLocation = new File(TMP_FOLDER, getTestName());
    storeLocation.mkdirs();
    Environment environment = createEnvironment(storeLocation);
    try {
        populateOldXidEntries(environment);
        UpgradeFrom5To6 upgrade = new UpgradeFrom5To6();
        upgrade.performUpgrade(environment, UpgradeInteractionHandler.DEFAULT_HANDLER, getVirtualHost());
        assertXidEntries(environment);
    } finally {
        try {
            environment.close();
        } finally {
            deleteDirectoryIfExists(storeLocation);
        }
    }
}
Also used : Environment(com.sleepycat.je.Environment) File(java.io.File) Test(org.junit.Test)

Example 28 with Environment

use of com.sleepycat.je.Environment in project qpid-broker-j by apache.

the class UpgraderTest method testEmptyDatabaseUpgradeDoesNothing.

@Test
public void testEmptyDatabaseUpgradeDoesNothing() throws Exception {
    File nonExistentStoreLocation = new File(TMP_FOLDER, getTestName());
    deleteDirectoryIfExists(nonExistentStoreLocation);
    nonExistentStoreLocation.mkdir();
    Environment emptyEnvironment = createEnvironment(nonExistentStoreLocation);
    try {
        _upgrader = new Upgrader(emptyEnvironment, getVirtualHost());
        _upgrader.upgradeIfNecessary();
        List<String> databaseNames = emptyEnvironment.getDatabaseNames();
        List<String> expectedDatabases = new ArrayList<String>();
        expectedDatabases.add(Upgrader.VERSION_DB_NAME);
        assertEquals("Expectedonly VERSION table in initially empty store after upgrade: ", expectedDatabases, databaseNames);
        assertEquals("Unexpected store version", BDBConfigurationStore.VERSION, getStoreVersion(emptyEnvironment));
    } finally {
        emptyEnvironment.close();
        nonExistentStoreLocation.delete();
    }
}
Also used : ArrayList(java.util.ArrayList) Environment(com.sleepycat.je.Environment) File(java.io.File) Test(org.junit.Test)

Example 29 with Environment

use of com.sleepycat.je.Environment in project qpid-broker-j by apache.

the class BDBPreferenceStoreTest method populateTestData.

private void populateTestData(final List<PreferenceRecord> records, final String modelVersion) {
    EnvironmentConfig envConfig = new EnvironmentConfig();
    envConfig.setAllowCreate(true);
    envConfig.setTransactional(false);
    try (Environment environment = new Environment(_storeFile, envConfig)) {
        DatabaseConfig dbConfig = new DatabaseConfig();
        dbConfig.setAllowCreate(true);
        try (Database versionDb = environment.openDatabase(null, "USER_PREFERENCES_VERSION", dbConfig);
            Database preferencesDb = environment.openDatabase(null, "USER_PREFERENCES", dbConfig)) {
            DatabaseEntry key = new DatabaseEntry();
            DatabaseEntry value = new DatabaseEntry();
            UUIDTupleBinding keyBinding = UUIDTupleBinding.getInstance();
            MapBinding valueBinding = MapBinding.getInstance();
            for (PreferenceRecord record : records) {
                keyBinding.objectToEntry(record.getId(), key);
                valueBinding.objectToEntry(record.getAttributes(), value);
                preferencesDb.put(null, key, value);
            }
            ByteBinding.byteToEntry((byte) 0, value);
            StringBinding.stringToEntry(modelVersion, key);
            versionDb.put(null, key, value);
        }
    }
}
Also used : MapBinding(org.apache.qpid.server.store.berkeleydb.tuple.MapBinding) EnvironmentConfig(com.sleepycat.je.EnvironmentConfig) Database(com.sleepycat.je.Database) PreferenceRecord(org.apache.qpid.server.store.preferences.PreferenceRecord) Environment(com.sleepycat.je.Environment) UUIDTupleBinding(org.apache.qpid.server.store.berkeleydb.tuple.UUIDTupleBinding) DatabaseEntry(com.sleepycat.je.DatabaseEntry) DatabaseConfig(com.sleepycat.je.DatabaseConfig)

Example 30 with Environment

use of com.sleepycat.je.Environment in project qpid-broker-j by apache.

the class OrphanConfigurationRecordPurger method purge.

private void purge() throws Exception {
    EnvironmentConfig config = EnvironmentConfig.DEFAULT;
    config.setAllowCreate(false);
    config.setTransactional(true);
    try (Environment env = createEnvironment(config)) {
        final int version = getVersion(env, READ_ONLY_DB_CONFIG);
        if (!ALLOWED_VERSIONS.contains(version)) {
            throw new IllegalStateException(String.format("Store has unexpected version. Found %d expected %s", version, ALLOWED_VERSIONS));
        }
        final Transaction tx = env.beginTransaction(null, TransactionConfig.DEFAULT);
        boolean success = false;
        try {
            purgeOrphans(env, tx);
            success = true;
        } finally {
            if (!success) {
                System.out.println("No config or config hierarchy records purged.");
                tx.abort();
            } else if (_dryRun) {
                System.out.println("No config or config hierarchy records purged - -dryRun flag specified.");
                tx.abort();
            } else {
                tx.commit();
                System.out.format("Config records(s) and associated hierarchy records purged.");
            }
        }
    }
}
Also used : Transaction(com.sleepycat.je.Transaction) EnvironmentConfig(com.sleepycat.je.EnvironmentConfig) Environment(com.sleepycat.je.Environment) ReplicatedEnvironment(com.sleepycat.je.rep.ReplicatedEnvironment)

Aggregations

Environment (com.sleepycat.je.Environment)38 EnvironmentConfig (com.sleepycat.je.EnvironmentConfig)20 DatabaseConfig (com.sleepycat.je.DatabaseConfig)18 File (java.io.File)15 Database (com.sleepycat.je.Database)10 DatabaseException (com.sleepycat.je.DatabaseException)9 DatabaseEntry (com.sleepycat.je.DatabaseEntry)5 Transaction (com.sleepycat.je.Transaction)5 IOException (java.io.IOException)5 Cursor (com.sleepycat.je.Cursor)3 EnvironmentMutableConfig (com.sleepycat.je.EnvironmentMutableConfig)3 ArrayList (java.util.ArrayList)3 Test (org.junit.Test)3 VoldemortException (voldemort.VoldemortException)3 CheckpointConfig (com.sleepycat.je.CheckpointConfig)2 StatsConfig (com.sleepycat.je.StatsConfig)2 ReplicatedEnvironment (com.sleepycat.je.rep.ReplicatedEnvironment)2 RuntimeIOException (htsjdk.samtools.util.RuntimeIOException)2 LineIterator (htsjdk.tribble.readers.LineIterator)2 BdbDbCreationException (nl.knaw.huygens.timbuctoo.v5.berkeleydb.exceptions.BdbDbCreationException)2