use of voldemort.store.StoreOperationFailureException 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.store.StoreOperationFailureException in project voldemort by voldemort.
the class AdminServiceRequestHandler method handleReserveMemory.
public VAdminProto.ReserveMemoryResponse handleReserveMemory(VAdminProto.ReserveMemoryRequest request) {
VAdminProto.ReserveMemoryResponse.Builder response = VAdminProto.ReserveMemoryResponse.newBuilder();
try {
String storeName = request.getStoreName();
long reserveMB = request.getSizeInMb();
synchronized (lock) {
if (storeRepository.hasLocalStore(storeName)) {
logger.info("Setting memory foot print of store '" + storeName + "' to " + reserveMB + " MB");
// update store's metadata (this also has the effect of
// updating the stores.xml file)
List<StoreDefinition> storeDefList = metadataStore.getStoreDefList();
for (int i = 0; i < storeDefList.size(); i++) {
StoreDefinition storeDef = storeDefList.get(i);
if (!storeDef.isView() && storeDef.getName().equals(storeName)) {
StoreDefinition newStoreDef = new StoreDefinitionBuilder().setName(storeDef.getName()).setType(storeDef.getType()).setDescription(storeDef.getDescription()).setOwners(storeDef.getOwners()).setKeySerializer(storeDef.getKeySerializer()).setValueSerializer(storeDef.getValueSerializer()).setRoutingPolicy(storeDef.getRoutingPolicy()).setRoutingStrategyType(storeDef.getRoutingStrategyType()).setReplicationFactor(storeDef.getReplicationFactor()).setPreferredReads(storeDef.getPreferredReads()).setRequiredReads(storeDef.getRequiredReads()).setPreferredWrites(storeDef.getPreferredWrites()).setRequiredWrites(storeDef.getRequiredWrites()).setRetentionPeriodDays(storeDef.getRetentionDays()).setRetentionScanThrottleRate(storeDef.getRetentionScanThrottleRate()).setZoneReplicationFactor(storeDef.getZoneReplicationFactor()).setZoneCountReads(storeDef.getZoneCountReads()).setZoneCountWrites(storeDef.getZoneCountWrites()).setHintedHandoffStrategy(storeDef.getHintedHandoffStrategyType()).setHintPrefListSize(storeDef.getHintPrefListSize()).setMemoryFootprintMB(reserveMB).build();
storeDefList.set(i, newStoreDef);
storageService.updateStore(newStoreDef);
break;
}
}
// save the changes
try {
metadataStore.put(MetadataStore.STORES_KEY, storeDefList);
} catch (Exception e) {
throw new VoldemortException(e);
}
} else {
logger.error("Failure to reserve memory. Store '" + storeName + "' does not exist");
throw new StoreOperationFailureException(String.format("Store '%s' does not exist on this server", storeName));
}
}
} catch (VoldemortException e) {
response.setError(ProtoUtils.encodeError(errorCodeMapper, e));
logger.error("handleReserveMemory failed for request(" + request.toString() + ")", e);
}
return response.build();
}
use of voldemort.store.StoreOperationFailureException in project voldemort by voldemort.
the class AdminServiceRequestHandler method handleDeleteStore.
public VAdminProto.DeleteStoreResponse handleDeleteStore(VAdminProto.DeleteStoreRequest request) {
VAdminProto.DeleteStoreResponse.Builder response = VAdminProto.DeleteStoreResponse.newBuilder();
// don't try to delete a store in the middle of rebalancing
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();
}
try {
String storeName = request.getStoreName();
synchronized (lock) {
if (storeRepository.hasLocalStore(storeName)) {
if (storeName.compareTo(SlopStorageEngine.SLOP_STORE_NAME) == 0) {
storageService.removeEngine(storeRepository.getStorageEngine(storeName), false, "slop", true);
} else {
List<StoreDefinition> oldStoreDefList = metadataStore.getStoreDefList();
for (StoreDefinition storeDef : oldStoreDefList) {
boolean isReadOnly = storeDef.getType().compareTo(ReadOnlyStorageConfiguration.TYPE_NAME) == 0;
if (storeDef.isView()) {
if (storeDef.getViewTargetStoreName().compareTo(storeName) == 0) {
logger.info("Deleting view '" + storeDef.getName() + "'");
storageService.removeEngine(storeRepository.getStorageEngine(storeDef.getName()), isReadOnly, storeDef.getType(), false);
logger.info("Successfully deleted view '" + storeDef.getName() + "'");
}
} else {
if (storeDef.getName().compareTo(storeName) == 0) {
logger.info("Deleting store '" + storeDef.getName() + "'");
storageService.removeEngine(storeRepository.getStorageEngine(storeDef.getName()), isReadOnly, storeDef.getType(), true);
logger.info("Successfully deleted store '" + storeDef.getName() + "'");
}
}
}
try {
// Update the metadata
metadataStore.deleteStoreDefinition(storeName);
} catch (Exception e) {
throw new VoldemortException(e);
}
}
} else {
throw new StoreOperationFailureException(String.format("Store '%s' does not exist on this server", storeName));
}
}
} catch (VoldemortException e) {
response.setError(ProtoUtils.encodeError(errorCodeMapper, e));
logger.error("handleDeleteStore failed for request(" + request.toString() + ")", e);
}
return response.build();
}
Aggregations