// stores.xml file out otherwise. (see
// ConfigurationStorageEngine.put for details)
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);
// update stores list in metadata store (this also has the
// effect of updating the stores.xml file)
try {
metadataStore.addStoreDefinition(def);
} 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));