Search in sources :

Example 11 with VoldemortApplicationException

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();
    }
}
Also used : VoldemortApplicationException(voldemort.VoldemortApplicationException) Node(voldemort.cluster.Node)

Example 12 with VoldemortApplicationException

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);
    }
}
Also used : VoldemortApplicationException(voldemort.VoldemortApplicationException) Node(voldemort.cluster.Node)

Example 13 with VoldemortApplicationException

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();
}
Also used : UnknownHostException(java.net.UnknownHostException) VoldemortApplicationException(voldemort.VoldemortApplicationException) InetAddress(java.net.InetAddress)

Example 14 with VoldemortApplicationException

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;
}
Also used : VoldemortApplicationException(voldemort.VoldemortApplicationException) StoreDefinition(voldemort.store.StoreDefinition) SerializerDefinition(voldemort.serialization.SerializerDefinition) HashSet(java.util.HashSet)

Example 15 with VoldemortApplicationException

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());
}
Also used : VoldemortApplicationException(voldemort.VoldemortApplicationException) Node(voldemort.cluster.Node) VectorClock(voldemort.versioning.VectorClock) Semaphore(java.util.concurrent.Semaphore) ObsoleteVersionException(voldemort.versioning.ObsoleteVersionException) InsufficientOperationalNodesException(voldemort.store.InsufficientOperationalNodesException) VoldemortException(voldemort.VoldemortException) VoldemortApplicationException(voldemort.VoldemortApplicationException) UnreachableStoreException(voldemort.store.UnreachableStoreException) ExecutionException(java.util.concurrent.ExecutionException) ObsoleteVersionException(voldemort.versioning.ObsoleteVersionException) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) InsufficientOperationalNodesException(voldemort.store.InsufficientOperationalNodesException) UnreachableStoreException(voldemort.store.UnreachableStoreException) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList)

Aggregations

VoldemortApplicationException (voldemort.VoldemortApplicationException)19 Node (voldemort.cluster.Node)10 UnreachableStoreException (voldemort.store.UnreachableStoreException)6 CopyOnWriteArrayList (java.util.concurrent.CopyOnWriteArrayList)4 ExecutionException (java.util.concurrent.ExecutionException)4 OptionException (joptsimple.OptionException)4 VoldemortException (voldemort.VoldemortException)4 InsufficientOperationalNodesException (voldemort.store.InsufficientOperationalNodesException)4 ObsoleteVersionException (voldemort.versioning.ObsoleteVersionException)4 HashMap (java.util.HashMap)3 Map (java.util.Map)3 Cluster (voldemort.cluster.Cluster)3 StoreDefinition (voldemort.store.StoreDefinition)3 StringReader (java.io.StringReader)2 ArrayList (java.util.ArrayList)2 HashSet (java.util.HashSet)2 Callable (java.util.concurrent.Callable)2 Future (java.util.concurrent.Future)2 Semaphore (java.util.concurrent.Semaphore)2 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2