Search in sources :

Example 91 with StoreDefinition

use of voldemort.store.StoreDefinition in project voldemort by voldemort.

the class StoreDefinitionMapperTest method testNoVersionStore.

public void testNoVersionStore() {
    StoreDefinitionsMapper mapper = new StoreDefinitionsMapper();
    List<StoreDefinition> storeDefs = mapper.readStoreList(new StringReader(VoldemortTestConstants.getNoVersionStoreDefinitionsXml()));
    String written = mapper.writeStoreList(storeDefs);
    assertEquals(storeDefs, mapper.readStoreList(new StringReader(written)));
}
Also used : StoreDefinition(voldemort.store.StoreDefinition) StringReader(java.io.StringReader)

Example 92 with StoreDefinition

use of voldemort.store.StoreDefinition in project voldemort by voldemort.

the class StoreDefinitionMapperTest method testSingleStore.

public void testSingleStore() {
    StoreDefinitionsMapper mapper = new StoreDefinitionsMapper();
    List<StoreDefinition> storeDefs = mapper.readStoreList(new StringReader(VoldemortTestConstants.getSingleStoreDefinitionsXml()));
    String written = mapper.writeStoreList(storeDefs);
    assertEquals(storeDefs, mapper.readStoreList(new StringReader(written)));
}
Also used : StoreDefinition(voldemort.store.StoreDefinition) StringReader(java.io.StringReader)

Example 93 with StoreDefinition

use of voldemort.store.StoreDefinition in project voldemort by voldemort.

the class StoreDefinitionMapperTest method testRetentionStore.

public void testRetentionStore() {
    StoreDefinitionsMapper mapper = new StoreDefinitionsMapper();
    List<StoreDefinition> storeDefs = mapper.readStoreList(new StringReader(VoldemortTestConstants.getStoreDefinitionsWithRetentionXml()));
    String written = mapper.writeStoreList(storeDefs);
    assertEquals(storeDefs, mapper.readStoreList(new StringReader(written)));
}
Also used : StoreDefinition(voldemort.store.StoreDefinition) StringReader(java.io.StringReader)

Example 94 with StoreDefinition

use of voldemort.store.StoreDefinition in project voldemort by voldemort.

the class StoreDefinitionMapperTest method testParsing.

public void testParsing() {
    StoreDefinitionsMapper mapper = new StoreDefinitionsMapper();
    List<StoreDefinition> storeDefs = mapper.readStoreList(new StringReader(VoldemortTestConstants.getSimpleStoreDefinitionsXml()));
    String output = mapper.writeStoreList(storeDefs);
    List<StoreDefinition> found = mapper.readStoreList(new StringReader(output));
    checkEquals(storeDefs, found);
    for (StoreDefinition def : storeDefs) {
        String xml = mapper.writeStore(def);
        StoreDefinition newDef = mapper.readStore(new StringReader(xml));
        assertEquals(def, newDef);
    }
}
Also used : StoreDefinition(voldemort.store.StoreDefinition) StringReader(java.io.StringReader)

Example 95 with StoreDefinition

use of voldemort.store.StoreDefinition in project voldemort by voldemort.

the class AdminServiceRequestHandler method handleFetchFailure.

private Message handleFetchFailure(VAdminProto.HandleFetchFailureRequest handleFetchFailure) {
    String storeName = handleFetchFailure.getStoreName();
    long pushVersion = handleFetchFailure.getPushVersion();
    String extraInfo = handleFetchFailure.getInfo();
    Properties extraInfoProperties = new Properties();
    try {
        extraInfoProperties.load(new StringReader(extraInfo));
    } catch (IOException e) {
        logger.error("Got IOException while trying to decipher a HandleFetchFailureRequest's info.", e);
    }
    logger.info("Received HandleFetchFailureRequest:\n" + "\tstore_name: " + storeName + "\n" + "\tpush_version: " + pushVersion + "\n" + "\tinfo: " + extraInfoProperties.toString());
    VAdminProto.HandleFetchFailureResponse.Builder response = VAdminProto.HandleFetchFailureResponse.newBuilder();
    AdminClient adminClient = AdminClient.createTempAdminClient(voldemortConfig, metadataStore.getCluster(), 1);
    try {
        // Get replica.factor for current store
        StoreDefinition storeDef = adminClient.metadataMgmtOps.getStoreDefinition(storeName);
        if (null == storeDef) {
            throw new StoreNotFoundException(storeName);
        }
        int replicaFactor = storeDef.getReplicationFactor();
        int maxNodeFailure = voldemortConfig.getHighAvailabilityPushMaxNodeFailures();
        // Considering replicaFactor could be smaller than maxNodeFailure configured in cluster level,
        // we need to compare the node failure number with the smaller number of (RF - 1, maxNodeFailure)
        // to make sure there is at least one replica running.
        maxNodeFailure = Math.min(maxNodeFailure, replicaFactor - 1);
        Set<Integer> nodesFailedInThisFetch = Sets.newHashSet(handleFetchFailure.getFailedNodesList());
        int failureCount = nodesFailedInThisFetch.size();
        boolean swapIsPossible = false;
        String responseMessage = "";
        if (failureCount > maxNodeFailure) {
            // Too many nodes failed to tolerate this strategy... let's bail out.
            responseMessage = "We cannot use pushHighAvailability because there is more than " + maxNodeFailure + " nodes that failed their fetches and build.replica.factor is " + replicaFactor + "...";
            logger.error(responseMessage);
        } else {
            FailedFetchLock distributedLock = null;
            try {
                distributedLock = FailedFetchLock.getLock(voldemortConfig, new Props(extraInfoProperties));
                distributedLock.acquireLock();
                Set<Integer> alreadyDisabledNodes = distributedLock.getDisabledNodes();
                Set<Integer> allNodesToBeDisabled = Sets.newHashSet();
                allNodesToBeDisabled.addAll(alreadyDisabledNodes);
                allNodesToBeDisabled.addAll(nodesFailedInThisFetch);
                int disabledNodeSize = allNodesToBeDisabled.size();
                if (disabledNodeSize > maxNodeFailure) {
                    // Too many exceptions to tolerate this strategy... let's bail out.
                    StringBuilder stringBuilder = new StringBuilder();
                    stringBuilder.append("We cannot use pushHighAvailability because it would bring the total ");
                    stringBuilder.append("number of nodes with disabled stores to more than ");
                    stringBuilder.append(maxNodeFailure);
                    stringBuilder.append("... alreadyDisabledNodes: [");
                    boolean firstItem = true;
                    for (Integer nodeId : alreadyDisabledNodes) {
                        if (firstItem) {
                            firstItem = false;
                        } else {
                            stringBuilder.append(", ");
                        }
                        stringBuilder.append(nodeId);
                    }
                    stringBuilder.append("], nodesFailedInThisFetch: [");
                    firstItem = true;
                    for (Integer nodeId : nodesFailedInThisFetch) {
                        if (firstItem) {
                            firstItem = false;
                        } else {
                            stringBuilder.append(", ");
                        }
                        stringBuilder.append(nodeId);
                    }
                    stringBuilder.append("]");
                    stringBuilder.append(", and build.replica.factor is ").append(replicaFactor);
                    responseMessage = stringBuilder.toString();
                    logger.error(responseMessage);
                } else {
                    String nodesString = "node";
                    if (nodesFailedInThisFetch.size() > 1) {
                        // Good grammar is important son
                        nodesString += "s";
                    }
                    nodesString += " [";
                    boolean firstNode = true;
                    for (Integer nodeId : nodesFailedInThisFetch) {
                        logger.warn("Will disable store '" + storeName + "' on node " + nodeId);
                        distributedLock.addDisabledNode(nodeId, storeName, pushVersion);
                        logger.warn("Store '" + storeName + "' is disabled on node " + nodeId);
                        if (firstNode) {
                            firstNode = false;
                        } else {
                            nodesString += ", ";
                        }
                        nodesString += nodeId;
                        response.addDisableStoreResponses(adminClient.readonlyOps.disableStoreVersion(nodeId, storeName, pushVersion, extraInfo));
                    }
                    nodesString += "]";
                    swapIsPossible = true;
                    responseMessage = "Swap will be possible even though " + nodesString + " failed to fetch.";
                    logger.info(responseMessage);
                }
            } catch (ClassNotFoundException e) {
                String logMessage = "Failed to find requested FailedFetchLock implementation while setting up pushHighAvailability. ";
                logger.error(responseMessage, e);
                responseMessage = logMessage + "\n" + ExceptionUtils.stackTraceToString(e);
            } catch (Exception e) {
                String logMessage = "Got exception while trying to execute pushHighAvailability. ";
                logger.error(responseMessage, e);
                responseMessage = logMessage + "\n" + ExceptionUtils.stackTraceToString(e);
            } finally {
                if (distributedLock != null) {
                    try {
                        distributedLock.releaseLock();
                    } catch (Exception e) {
                        logger.error("Error while trying to release the shared lock used for pushHighAvailability!", e);
                    } finally {
                        try {
                            distributedLock.close();
                        } catch (Exception inception) {
                            logger.error("Error while trying to close the shared lock used for pushHighAvailability!", inception);
                        }
                    }
                }
            }
        }
        response.setSwapIsPossible(swapIsPossible);
        response.setInfo(responseMessage);
    } finally {
        adminClient.close();
    }
    return response.build();
}
Also used : IOException(java.io.IOException) Properties(java.util.Properties) Props(voldemort.utils.Props) NoSuchCapabilityException(voldemort.store.NoSuchCapabilityException) ConfigurationException(voldemort.utils.ConfigurationException) ObsoleteVersionException(voldemort.versioning.ObsoleteVersionException) StoreOperationFailureException(voldemort.store.StoreOperationFailureException) VoldemortException(voldemort.VoldemortException) IOException(java.io.IOException) PersistenceFailureException(voldemort.store.PersistenceFailureException) StoreNotFoundException(voldemort.store.StoreNotFoundException) StoreNotFoundException(voldemort.store.StoreNotFoundException) StoreDefinition(voldemort.store.StoreDefinition) StringReader(java.io.StringReader) FailedFetchLock(voldemort.store.readonly.swapper.FailedFetchLock) AdminClient(voldemort.client.protocol.admin.AdminClient)

Aggregations

StoreDefinition (voldemort.store.StoreDefinition)215 Cluster (voldemort.cluster.Cluster)74 Test (org.junit.Test)67 ArrayList (java.util.ArrayList)56 HashMap (java.util.HashMap)50 StoreDefinitionsMapper (voldemort.xml.StoreDefinitionsMapper)50 VoldemortException (voldemort.VoldemortException)49 ByteArray (voldemort.utils.ByteArray)49 Node (voldemort.cluster.Node)43 StoreDefinitionBuilder (voldemort.store.StoreDefinitionBuilder)42 SerializerDefinition (voldemort.serialization.SerializerDefinition)38 File (java.io.File)34 StringReader (java.io.StringReader)34 Versioned (voldemort.versioning.Versioned)29 IOException (java.io.IOException)24 List (java.util.List)23 Store (voldemort.store.Store)21 AdminClient (voldemort.client.protocol.admin.AdminClient)19 RoutingStrategyFactory (voldemort.routing.RoutingStrategyFactory)19 ClusterMapper (voldemort.xml.ClusterMapper)18