Search in sources :

Example 76 with VoldemortException

use of voldemort.VoldemortException 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 77 with VoldemortException

use of voldemort.VoldemortException in project voldemort by voldemort.

the class BdbStorageEngine method getStats.

public DatabaseStats getStats(boolean setFast) {
    try {
        StatsConfig config = new StatsConfig();
        config.setFast(setFast);
        return this.getBdbDatabase().getStats(config);
    } catch (DatabaseException e) {
        this.bdbEnvironmentStats.reportException(e);
        logger.error(e);
        throw new VoldemortException(e);
    }
}
Also used : StatsConfig(com.sleepycat.je.StatsConfig) DatabaseException(com.sleepycat.je.DatabaseException) VoldemortException(voldemort.VoldemortException)

Example 78 with VoldemortException

use of voldemort.VoldemortException in project voldemort by voldemort.

the class BdbStorageEngine method truncate.

@Override
public void truncate() {
    if (isTruncating.compareAndSet(false, true)) {
        Transaction transaction = null;
        boolean succeeded = false;
        try {
            transaction = this.environment.beginTransaction(null, null);
            // close current bdbDatabase first
            bdbDatabase.close();
            // truncate the database
            environment.truncateDatabase(transaction, this.getName(), false);
            succeeded = true;
        } catch (DatabaseException e) {
            this.bdbEnvironmentStats.reportException(e);
            logger.error(e);
            throw new VoldemortException("Failed to truncate Bdb store " + getName(), e);
        } finally {
            commitOrAbort(succeeded, transaction);
            // reopen the bdb database for future queries.
            if (reopenBdbDatabase()) {
                isTruncating.compareAndSet(true, false);
            } else {
                throw new VoldemortException("Failed to reopen Bdb Database after truncation, All request will fail on store " + getName());
            }
        }
    } else {
        throw new VoldemortException("Store " + getName() + " is already truncating, cannot start another one.");
    }
}
Also used : Transaction(com.sleepycat.je.Transaction) DatabaseException(com.sleepycat.je.DatabaseException) VoldemortException(voldemort.VoldemortException)

Example 79 with VoldemortException

use of voldemort.VoldemortException in project voldemort by voldemort.

the class VersionedPutPruneJob method operate.

@Override
public void operate() throws Exception {
    StoreDefinition storeDef = StoreDefinitionUtils.getStoreDefinitionWithName(metadataStore.getStoreDefList(), storeName);
    if (storeDef == null) {
        throw new VoldemortException("Unknown store " + storeName);
    }
    if (isWritableStore(storeDef)) {
        // Lets generate routing strategy for this storage engine
        StoreRoutingPlan routingPlan = new StoreRoutingPlan(metadataStore.getCluster(), storeDef);
        logger.info("Pruning store " + storeDef.getName());
        StorageEngine<ByteArray, byte[], byte[]> engine = storeRepo.getStorageEngine(storeDef.getName());
        iterator = engine.keys();
        long itemsScanned = 0;
        long numPrunedKeys = 0;
        while (iterator.hasNext()) {
            ByteArray key = iterator.next();
            KeyLockHandle<byte[]> lockHandle = null;
            try {
                lockHandle = engine.getAndLock(key);
                List<Versioned<byte[]>> vals = lockHandle.getValues();
                List<Integer> keyReplicas = routingPlan.getReplicationNodeList(routingPlan.getMasterPartitionId(key.get()));
                MutableBoolean didPrune = new MutableBoolean(false);
                List<Versioned<byte[]>> prunedVals = pruneNonReplicaEntries(vals, keyReplicas, didPrune);
                // happened. Optimization to reduce load on storage
                if (didPrune.booleanValue()) {
                    List<Versioned<byte[]>> resolvedVals = VectorClockUtils.resolveVersions(prunedVals);
                    // TODO this is only implemented for BDB for now
                    lockHandle.setValues(resolvedVals);
                    engine.putAndUnlock(key, lockHandle);
                    numPrunedKeys = this.numKeysUpdatedThisRun.incrementAndGet();
                } else {
                    // if we did not prune, still need to let go of the lock
                    engine.releaseLock(lockHandle);
                }
                itemsScanned = this.numKeysScannedThisRun.incrementAndGet();
                throttler.maybeThrottle(1);
                if (itemsScanned % STAT_RECORDS_INTERVAL == 0) {
                    logger.info("#Scanned:" + itemsScanned + " #Pruned:" + numPrunedKeys);
                }
            } catch (Exception e) {
                throw e;
            } finally {
                if (lockHandle != null && !lockHandle.isClosed()) {
                    engine.releaseLock(lockHandle);
                }
            }
        }
        logger.info("Completed store " + storeDef.getName() + " #Scanned:" + itemsScanned + " #Pruned:" + numPrunedKeys);
    }
}
Also used : StoreRoutingPlan(voldemort.routing.StoreRoutingPlan) Versioned(voldemort.versioning.Versioned) MutableBoolean(org.apache.commons.lang.mutable.MutableBoolean) VoldemortException(voldemort.VoldemortException) VoldemortException(voldemort.VoldemortException) StoreDefinition(voldemort.store.StoreDefinition) ByteArray(voldemort.utils.ByteArray)

Example 80 with VoldemortException

use of voldemort.VoldemortException in project voldemort by voldemort.

the class BdbNativeBackup method backupFiles.

private void backupFiles(String[] filesForBackup, File backupDir, AsyncOperationStatus status) {
    // Determine size of backup
    long size = 0;
    for (String name : filesForBackup) {
        size += new File(databaseDir, name).length();
    }
    status.setStatus(String.format("Backing up %d files with a total of %.1fMB", filesForBackup.length, mb(size)));
    // Ensure files are sorted in order, so that if we fail part way
    // through, we don't lose stuff
    Arrays.sort(filesForBackup, new Comparator<String>() {

        public int compare(String o1, String o2) {
            long result = fileNameToNumber(o1) - fileNameToNumber(o2);
            if (result < 0) {
                return -1;
            } else if (result > 0) {
                return 1;
            }
            return 0;
        }
    });
    long total = 0;
    for (String name : filesForBackup) {
        File source = new File(databaseDir, name);
        File dest = new File(backupDir, name);
        status.setStatus(String.format("% 3d%% Copying %s", total * 100 / size, name));
        try {
            if (verifyFiles) {
                verifiedCopyFile(source, dest);
            } else {
                copyFile(source, dest);
            }
        } catch (IOException e) {
            // If the destination file exists, delete it
            if (dest.exists()) {
                dest.delete();
            }
            throw new VoldemortException("Error occurred while copying " + name + ". Deleting to ensure we don't have a corrupt backup.", e);
        }
        total += source.length();
    }
    if (isIncremental) {
        try {
            recordBackupSet(backupDir);
        } catch (IOException e) {
            throw new VoldemortException("Error attempting to write backup records for ", e);
        }
    } else {
        cleanStaleFiles(backupDir, status);
    }
}
Also used : IOException(java.io.IOException) File(java.io.File) VoldemortException(voldemort.VoldemortException)

Aggregations

VoldemortException (voldemort.VoldemortException)247 IOException (java.io.IOException)63 ByteArray (voldemort.utils.ByteArray)52 File (java.io.File)46 Node (voldemort.cluster.Node)42 StoreDefinition (voldemort.store.StoreDefinition)39 Versioned (voldemort.versioning.Versioned)38 ArrayList (java.util.ArrayList)34 Test (org.junit.Test)30 ObsoleteVersionException (voldemort.versioning.ObsoleteVersionException)26 List (java.util.List)21 HashMap (java.util.HashMap)20 Cluster (voldemort.cluster.Cluster)20 VectorClock (voldemort.versioning.VectorClock)16 NoSuchCapabilityException (voldemort.store.NoSuchCapabilityException)15 ReadOnlyStorageEngine (voldemort.store.readonly.ReadOnlyStorageEngine)14 ExecutionException (java.util.concurrent.ExecutionException)13 StoreDefinitionsMapper (voldemort.xml.StoreDefinitionsMapper)13 Map (java.util.Map)12 Path (org.apache.hadoop.fs.Path)12