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");
}
}
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);
}
}
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.");
}
}
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);
}
}
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);
}
}
Aggregations