Search in sources :

Example 91 with VoldemortException

use of voldemort.VoldemortException in project voldemort by voldemort.

the class JmxUtils method extractAttributeInfo.

/**
     * Extract all operations from the given object that have been annotated
     * with the Jmx annotation. Operations are all methods that are marked with
     * the JMX annotation and are not getters and setters (which are extracted
     * as attributes).
     * 
     * @param object The object to process
     * @return An array of attributes taken from the object
     */
public static ModelMBeanAttributeInfo[] extractAttributeInfo(Object object) {
    Map<String, Method> getters = new HashMap<String, Method>();
    Map<String, Method> setters = new HashMap<String, Method>();
    Map<String, String> descriptions = new HashMap<String, String>();
    for (Method m : object.getClass().getMethods()) {
        JmxGetter getter = m.getAnnotation(JmxGetter.class);
        if (getter != null) {
            getters.put(getter.name(), m);
            descriptions.put(getter.name(), getter.description());
        }
        JmxSetter setter = m.getAnnotation(JmxSetter.class);
        if (setter != null) {
            setters.put(setter.name(), m);
            descriptions.put(setter.name(), setter.description());
        }
    }
    Set<String> attributes = new HashSet<String>(getters.keySet());
    attributes.addAll(setters.keySet());
    List<ModelMBeanAttributeInfo> infos = new ArrayList<ModelMBeanAttributeInfo>();
    for (String name : attributes) {
        try {
            Method getter = getters.get(name);
            Method setter = setters.get(name);
            ModelMBeanAttributeInfo info = new ModelMBeanAttributeInfo(name, descriptions.get(name), getter, setter);
            Descriptor descriptor = info.getDescriptor();
            if (getter != null)
                descriptor.setField("getMethod", getter.getName());
            if (setter != null)
                descriptor.setField("setMethod", setter.getName());
            info.setDescriptor(descriptor);
            infos.add(info);
        } catch (IntrospectionException e) {
            throw new VoldemortException(e);
        }
    }
    return infos.toArray(new ModelMBeanAttributeInfo[infos.size()]);
}
Also used : JmxGetter(voldemort.annotations.jmx.JmxGetter) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) IntrospectionException(javax.management.IntrospectionException) Method(java.lang.reflect.Method) VoldemortException(voldemort.VoldemortException) JmxSetter(voldemort.annotations.jmx.JmxSetter) ModelMBeanAttributeInfo(javax.management.modelmbean.ModelMBeanAttributeInfo) Descriptor(javax.management.Descriptor) HashSet(java.util.HashSet)

Example 92 with VoldemortException

use of voldemort.VoldemortException in project voldemort by voldemort.

the class AdminCommandStream method readEntriesBinary.

private static Iterator<Pair<ByteArray, Versioned<byte[]>>> readEntriesBinary(File inputDir, String storeName) throws IOException {
    File inputFile = new File(inputDir, storeName + ".entries");
    if (!inputFile.exists()) {
        throw new FileNotFoundException("File " + inputFile.getAbsolutePath() + " does not exist!");
    }
    final DataInputStream dis = new DataInputStream(new BufferedInputStream(new FileInputStream(inputFile)));
    return new AbstractIterator<Pair<ByteArray, Versioned<byte[]>>>() {

        @Override
        protected Pair<ByteArray, Versioned<byte[]>> computeNext() {
            try {
                int length = dis.readInt();
                byte[] keyBytes = new byte[length];
                ByteUtils.read(dis, keyBytes);
                length = dis.readInt();
                byte[] versionBytes = new byte[length];
                ByteUtils.read(dis, versionBytes);
                length = dis.readInt();
                byte[] valueBytes = new byte[length];
                ByteUtils.read(dis, valueBytes);
                ByteArray key = new ByteArray(keyBytes);
                VectorClock version = new VectorClock(versionBytes);
                Versioned<byte[]> value = new Versioned<byte[]>(valueBytes, version);
                return new Pair<ByteArray, Versioned<byte[]>>(key, value);
            } catch (EOFException e) {
                try {
                    dis.close();
                } catch (IOException ie) {
                    ie.printStackTrace();
                }
                return endOfData();
            } catch (IOException e) {
                try {
                    dis.close();
                } catch (IOException ie) {
                    ie.printStackTrace();
                }
                throw new VoldemortException("Error reading from input file ", e);
            }
        }
    };
}
Also used : Versioned(voldemort.versioning.Versioned) VectorClock(voldemort.versioning.VectorClock) FileNotFoundException(java.io.FileNotFoundException) IOException(java.io.IOException) DataInputStream(java.io.DataInputStream) VoldemortException(voldemort.VoldemortException) FileInputStream(java.io.FileInputStream) BufferedInputStream(java.io.BufferedInputStream) EOFException(java.io.EOFException) ByteArray(voldemort.utils.ByteArray) AbstractIterator(com.google.common.collect.AbstractIterator) File(java.io.File) Pair(voldemort.utils.Pair)

Example 93 with VoldemortException

use of voldemort.VoldemortException in project voldemort by voldemort.

the class AbstractConsistencyFixer method doReads.

/**
     * 
     * @param nodeIdList
     * @param keyInBytes
     * @param keyInHexFormat
     * @return
     */
private Map<Integer, QueryKeyResult> doReads(final List<Integer> nodeIdList, final byte[] keyInBytes, final String keyInHexFormat) {
    Map<Integer, QueryKeyResult> nodeIdToKeyValues = new HashMap<Integer, QueryKeyResult>();
    ByteArray key = new ByteArray(keyInBytes);
    for (int nodeId : nodeIdList) {
        List<Versioned<byte[]>> values = null;
        try {
            values = this.adminClient.storeOps.getNodeKey(this.storeInstance.getStoreDefinition().getName(), nodeId, key);
            nodeIdToKeyValues.put(nodeId, new QueryKeyResult(key, values));
        } catch (VoldemortException ve) {
            nodeIdToKeyValues.put(nodeId, new QueryKeyResult(key, ve));
        }
    }
    return nodeIdToKeyValues;
}
Also used : Versioned(voldemort.versioning.Versioned) HashMap(java.util.HashMap) VoldemortException(voldemort.VoldemortException) QueryKeyResult(voldemort.client.protocol.admin.QueryKeyResult)

Example 94 with VoldemortException

use of voldemort.VoldemortException in project voldemort by voldemort.

the class RebalanceUtils method dropZone.

/**
     * Similar to {@link RebalanceUtils#vacateZone(Cluster, int)}, takes the
     * current store definitions in the cluster and creates store definitions
     * with the specified zone effectively dropped.
     * 
     * In order to drop a zone, we adjust the total replication factor and
     * remove zone replication factor for the dropped zone
     * 
     * 
     * @param currentStoreDefs
     * @param dropZoneId
     * @return the adjusted list of store definitions
     */
public static List<StoreDefinition> dropZone(List<StoreDefinition> currentStoreDefs, int dropZoneId) {
    List<StoreDefinition> adjustedStoreDefList = new ArrayList<StoreDefinition>();
    for (StoreDefinition storeDef : currentStoreDefs) {
        HashMap<Integer, Integer> zoneRepFactorMap = storeDef.getZoneReplicationFactor();
        if (!zoneRepFactorMap.containsKey(dropZoneId)) {
            throw new VoldemortException("Store " + storeDef.getName() + " does not have replication factor for zone " + dropZoneId);
        }
        StoreDefinitionBuilder adjustedStoreDefBuilder = StoreDefinitionUtils.getBuilderForStoreDef(storeDef);
        if (!storeDef.hasPreferredReads()) {
            adjustedStoreDefBuilder.setPreferredReads(null);
        }
        if (!storeDef.hasPreferredWrites()) {
            adjustedStoreDefBuilder.setPreferredWrites(null);
        }
        // Copy all zone replication factor entries except for dropped zone
        HashMap<Integer, Integer> adjustedZoneRepFactorMap = new HashMap<Integer, Integer>();
        for (Integer zoneId : zoneRepFactorMap.keySet()) {
            if (zoneId != dropZoneId) {
                adjustedZoneRepFactorMap.put(zoneId, zoneRepFactorMap.get(zoneId));
            }
        }
        adjustedStoreDefBuilder.setZoneReplicationFactor(adjustedZoneRepFactorMap);
        // adjust the replication factor
        int zoneRepFactor = zoneRepFactorMap.get(dropZoneId);
        adjustedStoreDefBuilder.setReplicationFactor(adjustedStoreDefBuilder.getReplicationFactor() - zoneRepFactor);
        adjustedStoreDefList.add(adjustedStoreDefBuilder.build());
    }
    return adjustedStoreDefList;
}
Also used : StoreDefinitionBuilder(voldemort.store.StoreDefinitionBuilder) HashMap(java.util.HashMap) StoreDefinition(voldemort.store.StoreDefinition) ArrayList(java.util.ArrayList) VoldemortException(voldemort.VoldemortException)

Example 95 with VoldemortException

use of voldemort.VoldemortException in project voldemort by voldemort.

the class RebalanceUtils method validateClusterZonesSame.

/**
     * Confirms that both clusters have the same set of zones defined.
     * 
     * @param lhs
     * @param rhs
     */
public static void validateClusterZonesSame(final Cluster lhs, final Cluster rhs) {
    Set<Zone> lhsSet = new HashSet<Zone>(lhs.getZones());
    Set<Zone> rhsSet = new HashSet<Zone>(rhs.getZones());
    if (!lhsSet.equals(rhsSet))
        throw new VoldemortException("Zones are not the same [ lhs cluster zones (" + lhs.getZones() + ") not equal to rhs cluster zones (" + rhs.getZones() + ") ]");
}
Also used : Zone(voldemort.cluster.Zone) VoldemortException(voldemort.VoldemortException) HashSet(java.util.HashSet)

Aggregations

VoldemortException (voldemort.VoldemortException)247 IOException (java.io.IOException)63 ByteArray (voldemort.utils.ByteArray)52 File (java.io.File)46 Node (voldemort.cluster.Node)42 StoreDefinition (voldemort.store.StoreDefinition)39 Versioned (voldemort.versioning.Versioned)38 ArrayList (java.util.ArrayList)34 Test (org.junit.Test)30 ObsoleteVersionException (voldemort.versioning.ObsoleteVersionException)26 List (java.util.List)21 HashMap (java.util.HashMap)20 Cluster (voldemort.cluster.Cluster)20 VectorClock (voldemort.versioning.VectorClock)16 NoSuchCapabilityException (voldemort.store.NoSuchCapabilityException)15 ReadOnlyStorageEngine (voldemort.store.readonly.ReadOnlyStorageEngine)14 ExecutionException (java.util.concurrent.ExecutionException)13 StoreDefinitionsMapper (voldemort.xml.StoreDefinitionsMapper)13 Map (java.util.Map)12 Path (org.apache.hadoop.fs.Path)12