use of voldemort.VoldemortException in project voldemort by voldemort.
the class AdminServiceRequestHandler method handleUpdateStoreDefinitions.
public VAdminProto.UpdateMetadataResponse handleUpdateStoreDefinitions(VAdminProto.UpdateMetadataRequest request) {
VAdminProto.UpdateMetadataResponse.Builder response = VAdminProto.UpdateMetadataResponse.newBuilder();
try {
ByteArray key = ProtoUtils.decodeBytes(request.getKey());
String keyString = ByteUtils.getString(key.get(), "UTF-8");
if (MetadataStore.METADATA_KEYS.contains(keyString)) {
Versioned<byte[]> versionedValue = ProtoUtils.decodeVersioned(request.getVersioned());
// corresponding put
if (keyString.equals(MetadataStore.STORES_KEY)) {
metadataStore.updateStoreDefinitions(versionedValue);
}
logger.info("Successfully updated metadata for key '" + keyString + "'");
}
} catch (VoldemortException e) {
response.setError(ProtoUtils.encodeError(errorCodeMapper, e));
logger.error("handleUpdateMetadata failed for request(" + request.toString() + ")", e);
}
return response.build();
}
use of voldemort.VoldemortException in project voldemort by voldemort.
the class AdminServiceRequestHandler method handleAddStore.
public VAdminProto.AddStoreResponse handleAddStore(VAdminProto.AddStoreRequest request) {
VAdminProto.AddStoreResponse.Builder response = VAdminProto.AddStoreResponse.newBuilder();
// don't try to add a store when not in normal or offline state
if (!metadataStore.getServerStateUnlocked().equals(MetadataStore.VoldemortState.NORMAL_SERVER) && !metadataStore.getServerStateUnlocked().equals(MetadataStore.VoldemortState.OFFLINE_SERVER)) {
response.setError(ProtoUtils.encodeError(errorCodeMapper, new VoldemortException("Voldemort server is neither in normal state nor in offline state")));
return response.build();
}
AdminClient adminClient = null;
try {
// adding a store requires decoding the passed in store string
StoreDefinitionsMapper mapper = new StoreDefinitionsMapper();
StoreDefinition def = mapper.readStore(new StringReader(request.getStoreDefinition()));
adminClient = new AdminClient(metadataStore.getCluster());
synchronized (lock) {
if (!storeRepository.hasLocalStore(def.getName())) {
if (def.getReplicationFactor() > metadataStore.getCluster().getNumberOfNodes()) {
throw new StoreOperationFailureException("Cannot add a store whose replication factor ( " + def.getReplicationFactor() + " ) is greater than the number of nodes ( " + metadataStore.getCluster().getNumberOfNodes() + " )");
}
logger.info("Adding new store '" + def.getName() + "'");
// open the store
StorageEngine<ByteArray, byte[], byte[]> engine = storageService.openStore(def);
// effect of updating the stores.xml file)
try {
metadataStore.addStoreDefinition(def);
long defaultQuota = voldemortConfig.getDefaultStorageSpaceQuotaInKB();
QuotaUtils.setQuota(def.getName(), QuotaType.STORAGE_SPACE, storeRepository, metadataStore.getCluster().getNodeIds(), defaultQuota);
} catch (Exception e) {
// rollback open store operation
boolean isReadOnly = ReadOnlyStorageConfiguration.TYPE_NAME.equals(def.getType());
storageService.removeEngine(engine, isReadOnly, def.getType(), true);
throw new VoldemortException(e);
}
logger.info("Successfully added new store '" + def.getName() + "'");
} else {
logger.error("Failure to add a store with the same name '" + def.getName() + "'");
throw new StoreOperationFailureException(String.format("Store '%s' already exists on this server", def.getName()));
}
}
} catch (VoldemortException e) {
response.setError(ProtoUtils.encodeError(errorCodeMapper, e));
logger.error("handleAddStore failed for request(" + request.toString() + ")", e);
} finally {
if (adminClient != null) {
IOUtils.closeQuietly(adminClient);
}
}
return response.build();
}
use of voldemort.VoldemortException in project voldemort by voldemort.
the class AdminServiceRequestHandler method handleRollbackStore.
public VAdminProto.RollbackStoreResponse handleRollbackStore(VAdminProto.RollbackStoreRequest request) {
final String storeName = request.getStoreName();
final long pushVersion = request.getPushVersion();
VAdminProto.RollbackStoreResponse.Builder response = VAdminProto.RollbackStoreResponse.newBuilder();
try {
ReadOnlyStorageEngine store = getReadOnlyStorageEngine(metadataStore, storeRepository, storeName);
File rollbackVersionDir = new File(store.getStoreDirPath(), "version-" + pushVersion);
logger.info("Rolling back data for RO store '" + storeName + "' to version directory '" + rollbackVersionDir + "'");
store.rollback(rollbackVersionDir);
logger.info("Successfully rolled back data for RO store '" + storeName + "' to version directory '" + rollbackVersionDir + "'");
} catch (VoldemortException e) {
response.setError(ProtoUtils.encodeError(errorCodeMapper, e));
logger.error("handleRollbackStore failed for request(" + request.toString() + ")", e);
}
return response.build();
}
use of voldemort.VoldemortException in project voldemort by voldemort.
the class AdminServiceRequestHandler method handleRebalanceStateChange.
public VAdminProto.RebalanceStateChangeResponse handleRebalanceStateChange(VAdminProto.RebalanceStateChangeRequest request) {
VAdminProto.RebalanceStateChangeResponse.Builder response = VAdminProto.RebalanceStateChangeResponse.newBuilder();
synchronized (rebalancer) {
try {
// Retrieve all values first
List<RebalanceTaskInfo> rebalanceTaskInfo = Lists.newArrayList();
for (RebalanceTaskInfoMap map : request.getRebalanceTaskListList()) {
rebalanceTaskInfo.add(ProtoUtils.decodeRebalanceTaskInfoMap(map));
}
Cluster cluster = new ClusterMapper().readCluster(new StringReader(request.getClusterString()));
List<StoreDefinition> storeDefs = new StoreDefinitionsMapper().readStoreList(new StringReader(request.getStoresString()));
boolean swapRO = request.getSwapRo();
boolean changeClusterMetadata = request.getChangeClusterMetadata();
boolean changeRebalanceState = request.getChangeRebalanceState();
boolean rollback = request.getRollback();
rebalancer.rebalanceStateChange(cluster, storeDefs, rebalanceTaskInfo, swapRO, changeClusterMetadata, changeRebalanceState, rollback);
} catch (VoldemortException e) {
response.setError(ProtoUtils.encodeError(errorCodeMapper, e));
logger.error("handleRebalanceStateChange failed for request(" + request.toString() + ")", e);
}
}
return response.build();
}
use of voldemort.VoldemortException in project voldemort by voldemort.
the class AdminServiceRequestHandler method handleSetOfflineState.
public VAdminProto.SetOfflineStateResponse handleSetOfflineState(VAdminProto.SetOfflineStateRequest request) {
VAdminProto.SetOfflineStateResponse.Builder response = VAdminProto.SetOfflineStateResponse.newBuilder();
try {
Boolean setToOffline = request.getOfflineMode();
logger.info("Setting OFFLINE_SERVER state to " + setToOffline.toString());
if (setToOffline) {
server.goOffline();
} else {
server.goOnline();
}
// TODO: deal with slop pushing here
} catch (VoldemortException e) {
response.setError(ProtoUtils.encodeError(errorCodeMapper, e));
logger.error("handleSetOfflineState failed for request(" + request.toString() + ")", e);
}
return response.build();
}
Aggregations