use of voldemort.VoldemortApplicationException in project voldemort by voldemort.
the class NodeIdUtils method findNodeId.
public static int findNodeId(Cluster cluster, HostMatcher matcher) {
logger.info(" Using Matcher " + matcher.getDebugInfo());
if (isSingleLocalCluster(cluster, matcher)) {
int nodeId = cluster.getNodeIds().iterator().next();
logger.info(" Cluster is a single local node cluster. Node Id " + nodeId);
return nodeId;
}
List<Node> matches = Lists.newArrayList();
for (Node node : cluster.getNodes()) {
if (matcher.match(node)) {
logger.info(node.briefToString() + " matched the current cluster ");
matches.add(node);
}
}
if (matches.isEmpty()) {
throw new VoldemortApplicationException(" No nodes in the cluster matched the current node " + Arrays.toString(cluster.getNodes().toArray()));
} else if (matches.size() > 1) {
String errorMessage = " More than one node matched " + Arrays.toString(matches.toArray());
logger.error(errorMessage);
throw new VoldemortApplicationException(errorMessage);
} else {
logger.info(" computed node Id match successfully " + matches.get(0).briefToString());
return matches.get(0).getId();
}
}
use of voldemort.VoldemortApplicationException in project voldemort by voldemort.
the class NodeIdUtils method validateNodeId.
public static void validateNodeId(Cluster cluster, HostMatcher matcher, int nodeId) {
logger.info(" Using Matcher " + matcher.getDebugInfo());
// Make sure nodeId exists.
cluster.getNodeById(nodeId);
if (isSingleLocalCluster(cluster, matcher)) {
return;
}
List<String> errors = Lists.newArrayList();
for (Node node : cluster.getNodes()) {
if (nodeId == node.getId()) {
if (!matcher.match(node)) {
errors.add(node.briefToString() + " selected as current node " + nodeId + " failed to match");
}
} else {
if (matcher.match(node)) {
errors.add(node.briefToString() + " matched, though the expected node is " + nodeId);
}
}
}
if (!errors.isEmpty()) {
String errorMessage = " Number of Validation failures " + errors.size() + ". Details : " + Arrays.toString(errors.toArray());
logger.error(errorMessage);
if (errors.size() == 1) {
throw new VoldemortApplicationException(errors.get(0));
} else {
throw new VoldemortApplicationException(errorMessage);
}
} else {
logger.info("Node Id Validation succeeded. Node Id " + nodeId);
}
}
use of voldemort.VoldemortApplicationException in project voldemort by voldemort.
the class HostMatcher method isLocalAddress.
public boolean isLocalAddress(Node node) {
String host = node.getHost();
InetAddress hostAddress;
try {
hostAddress = InetAddress.getByName(host);
} catch (UnknownHostException ex) {
throw new VoldemortApplicationException("Error retrieving InetAddress for host " + host, ex);
}
return hostAddress.isAnyLocalAddress() || hostAddress.isLoopbackAddress();
}
use of voldemort.VoldemortApplicationException in project voldemort by voldemort.
the class ClusterForkLiftTool method checkStoresOnBothSides.
private HashMap<String, StoreDefinition> checkStoresOnBothSides(boolean ignoreSchemaMismatch) {
List<StoreDefinition> srcStoreDefs = getStoreDefinitions(srcAdminClient);
HashMap<String, StoreDefinition> srcStoreDefMap = StoreUtils.getStoreDefsAsMap(srcStoreDefs);
List<StoreDefinition> dstStoreDefs = getStoreDefinitions(dstStreamingClient.getAdminClient());
HashMap<String, StoreDefinition> dstStoreDefMap = StoreUtils.getStoreDefsAsMap(dstStoreDefs);
Set<String> storesToSkip = new HashSet<String>();
for (String store : storesList) {
if (!srcStoreDefMap.containsKey(store)) {
String message = "Store " + store + " does not exist in source cluster ";
logger.warn(message);
throw new VoldemortApplicationException(message);
}
StoreDefinition srcStoreDef = srcStoreDefMap.get(store);
if (!dstStoreDefMap.containsKey(store)) {
String message = "Store " + store + " does not exist in destination cluster ";
logger.warn(message);
throw new VoldemortApplicationException(message);
}
StoreDefinition dstStoreDef = dstStoreDefMap.get(store);
if (!ignoreSchemaMismatch) {
SerializerDefinition srcKeySerializer = srcStoreDef.getKeySerializer();
SerializerDefinition dstKeySerializer = dstStoreDef.getKeySerializer();
if (srcKeySerializer.semanticEquals(dstKeySerializer) == false) {
String message = "Store " + store + " Key schema does not match between Source and destination \n";
message += "Source : " + srcKeySerializer.getFormattedString() + "\n";
message += "Destination : " + dstKeySerializer.getFormattedString() + "\n";
logger.warn(message);
throw new VoldemortApplicationException(message);
}
SerializerDefinition srcValueSerializer = srcStoreDef.getValueSerializer();
SerializerDefinition dstValueSerializer = dstStoreDef.getValueSerializer();
if (srcValueSerializer.semanticEquals(dstValueSerializer) == false) {
String message = "Store " + store + " Value schema does not match between Source and destination \n";
message += "Source : " + srcValueSerializer.getFormattedString() + "\n";
message += "Destination : " + dstValueSerializer.getFormattedString() + "\n";
logger.warn(message);
throw new VoldemortApplicationException(message);
}
}
}
return srcStoreDefMap;
}
use of voldemort.VoldemortApplicationException in project voldemort by voldemort.
the class ThreadPoolRoutedStore method put.
@Override
public void put(final ByteArray key, final Versioned<byte[]> versioned, final byte[] transforms) throws VoldemortException {
long startNs = System.nanoTime();
StoreUtils.assertValidKey(key);
final List<Node> nodes = availableNodes(routingStrategy.routeRequest(key.get()));
// quickly fail if there aren't enough nodes to meet the requirement
final int numNodes = nodes.size();
if (numNodes < this.storeDef.getRequiredWrites())
throw new InsufficientOperationalNodesException("Only " + numNodes + " nodes in preference list, but " + this.storeDef.getRequiredWrites() + " writes required.");
// A count of the number of successful operations
final AtomicInteger successes = new AtomicInteger(0);
// A list of thrown exceptions, indicating the number of failures
final List<Exception> failures = new CopyOnWriteArrayList<Exception>();
// If requiredWrites > 0 then do a single blocking write to the first
// live node in the preference list if this node throws an
// ObsoleteVersionException allow it to propagate
Node master = null;
int currentNode = 0;
Versioned<byte[]> versionedCopy = null;
for (; currentNode < numNodes; currentNode++) {
Node current = nodes.get(currentNode);
long startNsLocal = System.nanoTime();
try {
versionedCopy = incremented(versioned, current.getId());
innerStores.get(current.getId()).put(key, versionedCopy, transforms);
successes.getAndIncrement();
recordSuccess(current, startNsLocal);
master = current;
break;
} catch (UnreachableStoreException e) {
recordException(current, startNsLocal, e);
failures.add(e);
} catch (VoldemortApplicationException e) {
throw e;
} catch (Exception e) {
failures.add(e);
}
}
if (successes.get() < 1)
throw new InsufficientOperationalNodesException("No master node succeeded!", failures);
else
currentNode++;
// A semaphore indicating the number of completed operations
// Once inititialized all permits are acquired, after that
// permits are released when an operation is completed.
// semaphore.acquire(n) waits for n operations to complete
final Versioned<byte[]> finalVersionedCopy = versionedCopy;
final Semaphore semaphore = new Semaphore(0, false);
// Add the operations to the pool
int attempts = 0;
for (; currentNode < numNodes; currentNode++) {
attempts++;
final Node node = nodes.get(currentNode);
this.executor.execute(new Runnable() {
@Override
public void run() {
long startNsLocal = System.nanoTime();
try {
innerStores.get(node.getId()).put(key, finalVersionedCopy, transforms);
successes.incrementAndGet();
recordSuccess(node, startNsLocal);
} catch (UnreachableStoreException e) {
recordException(node, startNsLocal, e);
failures.add(e);
} catch (ObsoleteVersionException e) {
// ignore this completely here
// this means that a higher version was able
// to write on this node and should be termed as clean
// success.
} catch (VoldemortApplicationException e) {
throw e;
} catch (Exception e) {
logger.warn("Error in PUT on node " + node.getId() + "(" + node.getHost() + ")", e);
failures.add(e);
} finally {
// signal that the operation is complete
semaphore.release();
}
}
});
}
// Block until we get enough completions
int blockCount = Math.min(storeDef.getPreferredWrites() - 1, attempts);
boolean noTimeout = blockOnPut(startNs, semaphore, 0, blockCount, successes, storeDef.getPreferredWrites());
if (successes.get() < storeDef.getRequiredWrites()) {
/*
* We don't have enough required writes, but we haven't timed out
* yet, so block a little more if there are healthy nodes that can
* help us achieve our target.
*/
if (noTimeout) {
int startingIndex = blockCount - 1;
blockCount = Math.max(storeDef.getPreferredWrites() - 1, attempts);
blockOnPut(startNs, semaphore, startingIndex, blockCount, successes, storeDef.getRequiredWrites());
}
if (successes.get() < storeDef.getRequiredWrites())
throw new InsufficientOperationalNodesException(successes.get() + " writes succeeded, but " + this.storeDef.getRequiredWrites() + " are required.", failures);
}
// Okay looks like it worked, increment the version for the caller
VectorClock versionedClock = (VectorClock) versioned.getVersion();
versionedClock.incrementVersion(master.getId(), time.getMilliseconds());
}
Aggregations