Search in sources :

Example 1 with StorageInitializationException

use of voldemort.store.StorageInitializationException in project voldemort by voldemort.

the class RocksDbStorageConfiguration method getStore.

@Override
public StorageEngine<ByteArray, byte[], byte[]> getStore(StoreDefinition storeDef, RoutingStrategy strategy) {
    String storeName = storeDef.getName();
    if (!stores.containsKey(storeName)) {
        String dataDir = this.voldemortconfig.getRdbDataDirectory() + "/" + storeName;
        new File(dataDir).mkdirs();
        Properties dbProperties = parseProperties(VoldemortConfig.ROCKSDB_DB_OPTIONS);
        DBOptions dbOptions = (dbProperties.size() > 0) ? DBOptions.getDBOptionsFromProps(dbProperties) : new DBOptions();
        if (dbOptions == null) {
            throw new StorageInitializationException("Unable to parse Data Base Options.");
        }
        dbOptions.setCreateIfMissing(true);
        dbOptions.setCreateMissingColumnFamilies(true);
        dbOptions.createStatistics();
        Properties cfProperties = parseProperties(VoldemortConfig.ROCKSDB_CF_OPTIONS);
        if (this.voldemortconfig.getRocksdbPrefixKeysWithPartitionId()) {
            cfProperties.setProperty("prefix_extractor", "fixed:" + StoreBinaryFormat.PARTITIONID_PREFIX_SIZE);
        }
        ColumnFamilyOptions cfOptions = (cfProperties.size() > 0) ? ColumnFamilyOptions.getColumnFamilyOptionsFromProps(cfProperties) : new ColumnFamilyOptions();
        if (cfOptions == null) {
            throw new StorageInitializationException("Unable to parse Column Family Options.");
        }
        // Create a non default Column Family tp hold the store data.
        List<ColumnFamilyDescriptor> descriptors = new ArrayList<ColumnFamilyDescriptor>();
        descriptors.add(new ColumnFamilyDescriptor(RocksDB.DEFAULT_COLUMN_FAMILY, cfOptions));
        descriptors.add(new ColumnFamilyDescriptor(storeName.getBytes(), cfOptions));
        List<ColumnFamilyHandle> handles = new ArrayList<ColumnFamilyHandle>();
        try {
            RocksDB rdbStore = RocksDB.open(dbOptions, dataDir, descriptors, handles);
            // Dispose of the default Column Family immediately.  We don't use it and if it has not been disposed
            // by the time the DB is closed then the RocksDB code can terminate abnormally (if the RocksDB code is
            // built with assertions enabled). The handle will go out of scope on its own and the Java finalizer
            // will (eventually) do this for us, but, that is not fast enough for the unit tests.
            handles.get(0).dispose();
            ColumnFamilyHandle storeHandle = handles.get(1);
            RocksDbStorageEngine rdbStorageEngine;
            if (this.voldemortconfig.getRocksdbPrefixKeysWithPartitionId()) {
                rdbStorageEngine = new PartitionPrefixedRocksDbStorageEngine(storeName, rdbStore, storeHandle, cfOptions, lockStripes, strategy, voldemortconfig.isRocksdbEnableReadLocks());
            } else {
                rdbStorageEngine = new RocksDbStorageEngine(storeName, rdbStore, storeHandle, cfOptions, lockStripes, voldemortconfig.isRocksdbEnableReadLocks());
            }
            stores.put(storeName, rdbStorageEngine);
        } catch (Exception e) {
            throw new StorageInitializationException(e);
        }
    }
    return stores.get(storeName);
}
Also used : RocksDB(org.rocksdb.RocksDB) StorageInitializationException(voldemort.store.StorageInitializationException) ArrayList(java.util.ArrayList) Properties(java.util.Properties) ColumnFamilyDescriptor(org.rocksdb.ColumnFamilyDescriptor) ColumnFamilyHandle(org.rocksdb.ColumnFamilyHandle) StorageInitializationException(voldemort.store.StorageInitializationException) ColumnFamilyOptions(org.rocksdb.ColumnFamilyOptions) DBOptions(org.rocksdb.DBOptions) File(java.io.File)

Example 2 with StorageInitializationException

use of voldemort.store.StorageInitializationException in project voldemort by voldemort.

the class BdbStorageConfiguration method update.

/**
     * Detect what has changed in the store definition and rewire BDB
     * environments accordingly.
     * 
     * @param storeDef updated store definition
     */
public void update(StoreDefinition storeDef) {
    if (!useOneEnvPerStore)
        throw new VoldemortException("Memory foot print can be set only when using different environments per store");
    String storeName = storeDef.getName();
    Environment environment = environments.get(storeName);
    // change reservation amount of reserved store
    if (!unreservedStores.contains(environment) && storeDef.hasMemoryFootprint()) {
        EnvironmentMutableConfig mConfig = environment.getMutableConfig();
        long currentCacheSize = mConfig.getCacheSize();
        long newCacheSize = storeDef.getMemoryFootprintMB() * ByteUtils.BYTES_PER_MB;
        if (currentCacheSize != newCacheSize) {
            long newReservedCacheSize = this.reservedCacheSize - currentCacheSize + newCacheSize;
            // check that we leave a 'minimum' shared cache
            if ((voldemortConfig.getBdbCacheSize() - newReservedCacheSize) < voldemortConfig.getBdbMinimumSharedCache()) {
                throw new StorageInitializationException("Reservation of " + storeDef.getMemoryFootprintMB() + " MB for store " + storeName + " violates minimum shared cache size of " + voldemortConfig.getBdbMinimumSharedCache());
            }
            this.reservedCacheSize = newReservedCacheSize;
            adjustCacheSizes();
            mConfig.setCacheSize(newCacheSize);
            environment.setMutableConfig(mConfig);
            logger.info("Setting private cache for store " + storeDef.getName() + " to " + newCacheSize);
        }
    } else {
        // versa since the sharedCache param is not mutable
        throw new VoldemortException("Cannot switch between shared and private cache dynamically");
    }
}
Also used : StorageInitializationException(voldemort.store.StorageInitializationException) EnvironmentMutableConfig(com.sleepycat.je.EnvironmentMutableConfig) Environment(com.sleepycat.je.Environment) VoldemortException(voldemort.VoldemortException)

Example 3 with StorageInitializationException

use of voldemort.store.StorageInitializationException in project voldemort by voldemort.

the class BdbStorageConfiguration method getStore.

public StorageEngine<ByteArray, byte[], byte[]> getStore(StoreDefinition storeDef, RoutingStrategy strategy) {
    synchronized (lock) {
        try {
            String storeName = storeDef.getName();
            Environment environment = getEnvironment(storeDef);
            Database db = environment.openDatabase(null, storeName, databaseConfig);
            BdbRuntimeConfig runtimeConfig = new BdbRuntimeConfig(voldemortConfig);
            BdbStorageEngine engine = null;
            if (voldemortConfig.getBdbPrefixKeysWithPartitionId()) {
                engine = new PartitionPrefixedBdbStorageEngine(storeName, environment, db, runtimeConfig, strategy);
            } else {
                engine = new BdbStorageEngine(storeName, environment, db, runtimeConfig);
            }
            if (voldemortConfig.isJmxEnabled()) {
                // register the environment stats mbean
                JmxUtils.registerMbean(storeName, engine.getBdbEnvironmentStats());
                // aggregated stats
                if (useOneEnvPerStore) {
                    aggBdbStats.trackEnvironment(engine.getBdbEnvironmentStats());
                }
            }
            return engine;
        } catch (DatabaseException d) {
            throw new StorageInitializationException(d);
        }
    }
}
Also used : StorageInitializationException(voldemort.store.StorageInitializationException) Database(com.sleepycat.je.Database) Environment(com.sleepycat.je.Environment) DatabaseException(com.sleepycat.je.DatabaseException)

Example 4 with StorageInitializationException

use of voldemort.store.StorageInitializationException in project voldemort by voldemort.

the class BdbStorageConfiguration method getEnvironment.

public Environment getEnvironment(StoreDefinition storeDef) throws DatabaseException {
    String storeName = storeDef.getName();
    synchronized (lock) {
        if (useOneEnvPerStore) {
            // reference
            if (environments.containsKey(storeName))
                return environments.get(storeName);
            // otherwise create a new environment
            File bdbDir = new File(bdbMasterDir, storeName);
            createBdbDirIfNecessary(bdbDir);
            // configure the BDB cache
            if (storeDef.hasMemoryFootprint()) {
                // make room for the reservation, by adjusting other stores
                long reservedBytes = storeDef.getMemoryFootprintMB() * ByteUtils.BYTES_PER_MB;
                long newReservedCacheSize = this.reservedCacheSize + reservedBytes;
                // check that we leave a 'minimum' shared cache
                if ((voldemortConfig.getBdbCacheSize() - newReservedCacheSize) < voldemortConfig.getBdbMinimumSharedCache()) {
                    throw new StorageInitializationException("Reservation of " + storeDef.getMemoryFootprintMB() + " MB for store " + storeName + " violates minimum shared cache size of " + voldemortConfig.getBdbMinimumSharedCache());
                }
                this.reservedCacheSize = newReservedCacheSize;
                adjustCacheSizes();
                environmentConfig.setSharedCache(false);
                environmentConfig.setCacheSize(reservedBytes);
            } else {
                environmentConfig.setSharedCache(true);
                environmentConfig.setCacheSize(voldemortConfig.getBdbCacheSize() - this.reservedCacheSize);
            }
            Environment environment = new Environment(bdbDir, environmentConfig);
            logger.info("Creating environment for " + storeName + ": ");
            logEnvironmentConfig(environment.getConfig());
            environments.put(storeName, environment);
            // save this up so we can adjust later if needed
            if (!storeDef.hasMemoryFootprint())
                this.unreservedStores.add(environment);
            return environment;
        } else {
            if (!environments.isEmpty())
                return environments.get(SHARED_ENV_KEY);
            File bdbDir = new File(bdbMasterDir);
            createBdbDirIfNecessary(bdbDir);
            Environment environment = new Environment(bdbDir, environmentConfig);
            logger.info("Creating shared BDB environment: ");
            logEnvironmentConfig(environment.getConfig());
            environments.put(SHARED_ENV_KEY, environment);
            return environment;
        }
    }
}
Also used : StorageInitializationException(voldemort.store.StorageInitializationException) Environment(com.sleepycat.je.Environment) File(java.io.File)

Example 5 with StorageInitializationException

use of voldemort.store.StorageInitializationException in project voldemort by voldemort.

the class BdbCachePartitioningTest method testMinimumSharedCache.

/**
     * Tests that any reservation that will not violate minimum shared cache
     * will fail, during server startup and dynamic updation
     */
@Test
public void testMinimumSharedCache() {
    // total cache size
    int totalCache = 20 * ByteUtils.BYTES_PER_MB;
    // A reserves 10MB
    int shareA = 10 * ByteUtils.BYTES_PER_MB;
    // lets use all the default values.
    Props props = new Props();
    props.put("node.id", 1);
    props.put("voldemort.home", "test/common/voldemort/config");
    VoldemortConfig voldemortConfig = new VoldemortConfig(props);
    voldemortConfig.setBdbCacheSize(totalCache);
    voldemortConfig.setBdbOneEnvPerStore(true);
    voldemortConfig.setBdbDataDirectory(bdbMasterDir.toURI().getPath());
    voldemortConfig.setBdbMinimumSharedCache(15 * ByteUtils.BYTES_PER_MB);
    voldemortConfig.setBdbPrefixKeysWithPartitionId(prefixPartitionId);
    BdbStorageEngine storeA = null;
    bdbStorage = new BdbStorageConfiguration(voldemortConfig);
    assertEquals("Reserved cache size not zero", 0, bdbStorage.getReservedCacheSize());
    try {
        StoreDefinition defA = TestUtils.makeStoreDefinition("storeA", shareA / ByteUtils.BYTES_PER_MB);
        storeA = (BdbStorageEngine) bdbStorage.getStore(defA, TestUtils.makeSingleNodeRoutingStrategy());
        fail("Should have thrown exception since minSharedCache will be violated");
    } catch (StorageInitializationException sie) {
    // should come here.
    }
    // failing operations should not alter reserved cache size
    assertEquals("failure somehow altered the reservedCacheSize", 0, bdbStorage.getReservedCacheSize());
    voldemortConfig.setBdbMinimumSharedCache(10 * ByteUtils.BYTES_PER_MB);
    bdbStorage = new BdbStorageConfiguration(voldemortConfig);
    try {
        StoreDefinition defA = TestUtils.makeStoreDefinition("storeA", shareA / ByteUtils.BYTES_PER_MB);
        storeA = (BdbStorageEngine) bdbStorage.getStore(defA, TestUtils.makeSingleNodeRoutingStrategy());
    } catch (StorageInitializationException sie) {
        // should not come here.
        fail("minSharedCache should n't have been violated");
    }
    assertEquals("store A's share does not match up with reserved cache size", shareA, bdbStorage.getReservedCacheSize());
    long reserveCacheSize = bdbStorage.getReservedCacheSize();
    // now, try increasing the reservation dynamically and it should fail
    try {
        StoreDefinition defA = TestUtils.makeStoreDefinition("storeA", 15);
        bdbStorage.update(defA);
        fail("Should have thrown exception since minSharedCache will be violated");
    } catch (StorageInitializationException sie) {
    // should come here.
    }
    assertEquals("failure somehow altered the reservedCacheSize", reserveCacheSize, bdbStorage.getReservedCacheSize());
    if (storeA != null)
        storeA.close();
    bdbStorage.close();
}
Also used : StorageInitializationException(voldemort.store.StorageInitializationException) StoreDefinition(voldemort.store.StoreDefinition) Props(voldemort.utils.Props) VoldemortConfig(voldemort.server.VoldemortConfig) Test(org.junit.Test)

Aggregations

StorageInitializationException (voldemort.store.StorageInitializationException)5 Environment (com.sleepycat.je.Environment)3 File (java.io.File)2 Database (com.sleepycat.je.Database)1 DatabaseException (com.sleepycat.je.DatabaseException)1 EnvironmentMutableConfig (com.sleepycat.je.EnvironmentMutableConfig)1 ArrayList (java.util.ArrayList)1 Properties (java.util.Properties)1 Test (org.junit.Test)1 ColumnFamilyDescriptor (org.rocksdb.ColumnFamilyDescriptor)1 ColumnFamilyHandle (org.rocksdb.ColumnFamilyHandle)1 ColumnFamilyOptions (org.rocksdb.ColumnFamilyOptions)1 DBOptions (org.rocksdb.DBOptions)1 RocksDB (org.rocksdb.RocksDB)1 VoldemortException (voldemort.VoldemortException)1 VoldemortConfig (voldemort.server.VoldemortConfig)1 StoreDefinition (voldemort.store.StoreDefinition)1 Props (voldemort.utils.Props)1