use of voldemort.VoldemortException in project voldemort by voldemort.
the class RebalanceUtils method validateClusterPartitionState.
/**
* Confirm that all nodes shared between clusters host exact same partition
* IDs and that nodes only in the super set cluster have no partition IDs.
*
* @param subsetCluster
* @param supersetCluster
*/
public static void validateClusterPartitionState(final Cluster subsetCluster, final Cluster supersetCluster) {
if (!supersetCluster.getNodeIds().containsAll(subsetCluster.getNodeIds())) {
throw new VoldemortException("Superset cluster does not contain all nodes from subset cluster[ subset cluster node ids (" + subsetCluster.getNodeIds() + ") are not a subset of superset cluster node ids (" + supersetCluster.getNodeIds() + ") ]");
}
for (int nodeId : subsetCluster.getNodeIds()) {
Node supersetNode = supersetCluster.getNodeById(nodeId);
Node subsetNode = subsetCluster.getNodeById(nodeId);
if (!supersetNode.getPartitionIds().equals(subsetNode.getPartitionIds())) {
throw new VoldemortRebalancingException("Partition IDs do not match between clusters for nodes with id " + nodeId + " : subset cluster has " + subsetNode.getPartitionIds() + " and superset cluster has " + supersetNode.getPartitionIds());
}
}
Set<Integer> nodeIds = supersetCluster.getNodeIds();
nodeIds.removeAll(subsetCluster.getNodeIds());
for (int nodeId : nodeIds) {
Node supersetNode = supersetCluster.getNodeById(nodeId);
if (!supersetNode.getPartitionIds().isEmpty()) {
throw new VoldemortRebalancingException("New node " + nodeId + " in superset cluster already has partitions: " + supersetNode.getPartitionIds());
}
}
}
use of voldemort.VoldemortException in project voldemort by voldemort.
the class Utils method move.
/**
* Move the source file to the dest file name. If there is a file or
* directory at dest it will be overwritten. If the source file does not
* exist or cannot be copied and exception will be thrown exist
*
* @param source The file to copy from
* @param dest The file to copy to
*/
public static void move(File source, File dest) {
if (!source.exists())
throw new VoldemortException("File " + source.toString() + " does not exist.");
Utils.rm(dest);
boolean succeeded = source.renameTo(dest);
if (!succeeded)
throw new VoldemortException("Rename of " + source + " to " + dest + " failed.");
}
use of voldemort.VoldemortException in project voldemort by voldemort.
the class Utils method symlink.
/**
* Creates a symbolic link to an existing file. If the symlink already exists and
* already points to the intended destination, no changes are made to the file-system.
* If the symlink already exists but points to wrong destination, it is deleted first
* before being recreated.
*
* @param filePath Path of the file for whom to create the symbolic link
* @param symLinkPath Path of the symbolic link
*/
public static void symlink(String filePath, String symLinkPath) {
File file = new File(filePath);
File symLink = new File(symLinkPath);
if (!file.exists()) {
throw new VoldemortException("File " + filePath + " does not exist");
}
if (symLink.exists()) {
try {
if (symLink.getCanonicalFile().equals(file.getCanonicalFile())) {
// No need to do anything else, the symlink already points to the right destination
logger.info("Symlink '" + symLink.getParentFile().getName() + "/" + symLink.getName() + "' pointing to '" + file.getName() + "' already exists. Leaving it as is.");
return;
}
} catch (IOException e) {
throw new VoldemortException("Got an IOException while trying to read a symlink.", e);
}
}
symLink.delete();
Posix posix = (Posix) Native.loadLibrary("c", Posix.class);
int returnCode = posix.symlink(filePath, symLinkPath);
if (returnCode < 0)
throw new VoldemortException("Unable to create symbolic link for " + filePath + " (received return code " + returnCode + ")");
logger.info("Symlink '" + symLink.getParentFile().getName() + "/" + symLink.getName() + "' pointing to '" + file.getName() + "' has been created.");
}
use of voldemort.VoldemortException in project voldemort by voldemort.
the class AdminToolUtils method assertServerState.
/**
* Checks if nodes are in a given {@link VoldemortState}. Can also be
* used to ensure that nodes are NOT in a given {@link VoldemortState}.
*
* Either way, throws an exception if any node isn't as expected.
*
* @param adminClient An instance of AdminClient points to given cluster
* @param nodeIds List of node ids to be checked
* @param stateToCheck state to be verified
* @param serverMustBeInThisState - if true, function will throw if any
* server is NOT in the stateToCheck
* - if false, function will throw if any
* server IS in the stateToCheck
* @throws VoldemortException if any node doesn't conform to the required state
*/
private static void assertServerState(AdminClient adminClient, Collection<Integer> nodeIds, VoldemortState stateToCheck, boolean serverMustBeInThisState) {
for (Integer nodeId : nodeIds) {
String nodeName = adminClient.getAdminClientCluster().getNodeById(nodeId).briefToString();
try {
Versioned<String> versioned = adminClient.metadataMgmtOps.getRemoteMetadata(nodeId, MetadataStore.SERVER_STATE_KEY);
VoldemortState state = VoldemortState.valueOf(versioned.getValue());
if (state.equals(stateToCheck) != serverMustBeInThisState) {
throw new VoldemortException("Cannot execute admin operation: " + nodeName + " is " + (serverMustBeInThisState ? "not in " : "in ") + stateToCheck.name() + " state.");
}
} catch (UnreachableStoreException e) {
System.err.println("Cannot verify the server state of " + nodeName + " because it is unreachable. Skipping.");
}
}
}
use of voldemort.VoldemortException in project voldemort by voldemort.
the class ReadOnlyStorageEngineTest method createStoreFiles.
private void createStoreFiles(File dir, int indexBytes, int dataBytes, Node node, int numChunks) throws IOException, FileNotFoundException {
ReadOnlyStorageMetadata metadata = new ReadOnlyStorageMetadata();
metadata.add(ReadOnlyStorageMetadata.FORMAT, storageType.getCode());
File metadataFile = createFile(dir, ".metadata");
BufferedWriter writer = new BufferedWriter(new FileWriter(metadataFile));
writer.write(metadata.toJsonString());
writer.close();
switch(storageType) {
case READONLY_V0:
{
for (int chunk = 0; chunk < numChunks; chunk++) {
File index = createFile(dir, chunk + ".index");
File data = createFile(dir, chunk + ".data");
// write some random crap for index and data
FileOutputStream dataOs = new FileOutputStream(data);
for (int i = 0; i < dataBytes; i++) dataOs.write(i);
dataOs.close();
FileOutputStream indexOs = new FileOutputStream(index);
for (int i = 0; i < indexBytes; i++) indexOs.write(i);
indexOs.close();
}
}
break;
case READONLY_V1:
{
for (Integer partitionId : node.getPartitionIds()) {
for (int chunkId = 0; chunkId < numChunks; chunkId++) {
File index = createFile(dir, Integer.toString(partitionId) + "_" + Integer.toString(chunkId) + ".index");
File data = createFile(dir, Integer.toString(partitionId) + "_" + Integer.toString(chunkId) + ".data");
// write some random crap for index and data
FileOutputStream dataOs = new FileOutputStream(data);
for (int i = 0; i < dataBytes; i++) dataOs.write(i);
dataOs.close();
FileOutputStream indexOs = new FileOutputStream(index);
for (int i = 0; i < indexBytes; i++) indexOs.write(i);
indexOs.close();
}
}
}
break;
case READONLY_V2:
{
// store with replication factor of 1
for (Integer partitionId : node.getPartitionIds()) {
for (int chunkId = 0; chunkId < numChunks; chunkId++) {
File index = createFile(dir, Integer.toString(partitionId) + "_0_" + Integer.toString(chunkId) + ".index");
File data = createFile(dir, Integer.toString(partitionId) + "_0_" + Integer.toString(chunkId) + ".data");
// write some random crap for index and data
FileOutputStream dataOs = new FileOutputStream(data);
for (int i = 0; i < dataBytes; i++) dataOs.write(i);
dataOs.close();
FileOutputStream indexOs = new FileOutputStream(index);
for (int i = 0; i < indexBytes; i++) indexOs.write(i);
indexOs.close();
}
}
}
break;
default:
throw new VoldemortException("Do not support storage type " + storageType);
}
}
Aggregations