use of voldemort.annotations.jmx.JmxOperation in project voldemort by voldemort.
the class ReadOnlyStorageEngine method swapFiles.
/**
* Swap the current version folder for a new one
*
* @param newStoreDirectory The path to the new version directory
*/
@JmxOperation(description = "swapFiles changes this store to use the new data directory")
public void swapFiles(String newStoreDirectory) {
logger.info("Swapping files for store '" + getName() + "' to " + newStoreDirectory);
File newVersionDir = new File(newStoreDirectory);
if (!newVersionDir.exists())
throw new VoldemortException("File " + newVersionDir.getAbsolutePath() + " does not exist.");
if (!(newVersionDir.getParentFile().compareTo(storeDir.getAbsoluteFile()) == 0 && ReadOnlyUtils.checkVersionDirName(newVersionDir)))
throw new VoldemortException("Invalid version folder name '" + newVersionDir + "'. Either parent directory is incorrect or format(version-n) is incorrect");
// retrieve previous version for (a) check if last write is winning
// (b) if failure, rollback use
File previousVersionDir = ReadOnlyUtils.getCurrentVersion(storeDir);
if (previousVersionDir == null)
throw new VoldemortException("Could not find any latest directory to swap with in store '" + getName() + "'");
long newVersionId = ReadOnlyUtils.getVersionId(newVersionDir);
long previousVersionId = ReadOnlyUtils.getVersionId(previousVersionDir);
if (newVersionId == -1 || previousVersionId == -1)
throw new VoldemortException("Unable to parse folder names (" + newVersionDir.getName() + "," + previousVersionDir.getName() + ") since format(version-n) is incorrect");
// check if we're greater than latest since we want last write to win
if (previousVersionId > newVersionId) {
logger.info("No swap required since current latest version " + previousVersionId + " is greater than swap version " + newVersionId);
deleteBackups();
return;
}
logger.info("Acquiring write lock on '" + getName() + "':");
fileModificationLock.writeLock().lock();
boolean success = false;
try {
close();
logger.info("Opening primary files for store '" + getName() + "' at " + newStoreDirectory);
// open the latest store
open(newVersionDir);
success = true;
} finally {
try {
// we failed to do the swap, attempt a rollback to last version
if (!success)
rollback(previousVersionDir);
} finally {
fileModificationLock.writeLock().unlock();
if (success)
logger.info("Swap operation completed successfully on store " + getName() + ", releasing lock.");
else
logger.error("Swap operation failed.");
}
}
// okay we have released the lock and the store is now open again, it is
// safe to do a potentially slow delete if we have one too many backups
deleteBackups();
}
use of voldemort.annotations.jmx.JmxOperation in project voldemort by voldemort.
the class StorageService method forceCleanupOldData.
@JmxOperation(description = "Force cleanup of old data based on retention policy, allows override of throttle-rate", impact = MBeanOperationInfo.ACTION)
public void forceCleanupOldData(String storeName) {
StoreDefinition storeDef = getMetadataStore().getStoreDef(storeName);
int throttleRate = storeDef.hasRetentionScanThrottleRate() ? storeDef.getRetentionScanThrottleRate() : Integer.MAX_VALUE;
forceCleanupOldDataThrottled(storeName, throttleRate);
}
use of voldemort.annotations.jmx.JmxOperation in project voldemort by voldemort.
the class StorageService method forceCleanupOldDataThrottled.
@JmxOperation(description = "Force cleanup of old data based on retention policy.", impact = MBeanOperationInfo.ACTION)
public void forceCleanupOldDataThrottled(String storeName, int entryScanThrottleRate) {
logger.info("forceCleanupOldData() called for store " + storeName + " with retention scan throttle rate:" + entryScanThrottleRate + " Entries/second.");
try {
StoreDefinition storeDef = getMetadataStore().getStoreDef(storeName);
StorageEngine<ByteArray, byte[], byte[]> engine = storeRepository.getStorageEngine(storeName);
if (null != engine) {
if (storeDef.hasRetentionPeriod()) {
ExecutorService executor = Executors.newFixedThreadPool(1);
try {
if (scanPermitWrapper.availablePermits() >= 1) {
executor.execute(new DataCleanupJob<ByteArray, byte[], byte[]>(engine, scanPermitWrapper, storeName, SystemTime.INSTANCE, metadata));
} else {
logger.error("forceCleanupOldData() No permit available to run cleanJob already running multiple instance." + engine.getName());
}
} finally {
executor.shutdown();
}
} else {
logger.error("forceCleanupOldData() No retention policy found for " + storeName);
}
}
} catch (Exception e) {
logger.error("Error while running forceCleanupOldData()", e);
throw new VoldemortException(e);
}
}
use of voldemort.annotations.jmx.JmxOperation in project voldemort by voldemort.
the class BdbStorageConfiguration method checkPointAllEnvironments.
/**
* Forceful checkpointing
*/
@JmxOperation(description = "Forcefully checkpoint all the environments")
public void checkPointAllEnvironments() {
synchronized (lock) {
try {
for (Environment environment : environments.values()) {
CheckpointConfig checkPointConfig = new CheckpointConfig();
checkPointConfig.setForce(true);
environment.checkpoint(checkPointConfig);
}
} catch (DatabaseException e) {
throw new VoldemortException(e);
}
}
}
use of voldemort.annotations.jmx.JmxOperation in project voldemort by voldemort.
the class JmxUtils method extractOperationInfo.
/**
* Extract all operations and attributes from the given object that have
* been annotated with the Jmx annotation. Operations are all methods that
* are marked with the JmxOperation annotation.
*
* @param object The object to process
* @return An array of operations taken from the object
*/
public static ModelMBeanOperationInfo[] extractOperationInfo(Object object) {
ArrayList<ModelMBeanOperationInfo> infos = new ArrayList<ModelMBeanOperationInfo>();
for (Method m : object.getClass().getMethods()) {
JmxOperation jmxOperation = m.getAnnotation(JmxOperation.class);
JmxGetter jmxGetter = m.getAnnotation(JmxGetter.class);
JmxSetter jmxSetter = m.getAnnotation(JmxSetter.class);
if (jmxOperation != null || jmxGetter != null || jmxSetter != null) {
String description = "";
int visibility = 1;
int impact = MBeanOperationInfo.UNKNOWN;
if (jmxOperation != null) {
description = jmxOperation.description();
impact = jmxOperation.impact();
} else if (jmxGetter != null) {
description = jmxGetter.description();
impact = MBeanOperationInfo.INFO;
visibility = 4;
} else if (jmxSetter != null) {
description = jmxSetter.description();
impact = MBeanOperationInfo.ACTION;
visibility = 4;
}
ModelMBeanOperationInfo info = new ModelMBeanOperationInfo(m.getName(), description, extractParameterInfo(m), m.getReturnType().getName(), impact);
info.getDescriptor().setField("visibility", Integer.toString(visibility));
infos.add(info);
}
}
return infos.toArray(new ModelMBeanOperationInfo[infos.size()]);
}
Aggregations