Search in sources :

Example 26 with Version

use of voldemort.versioning.Version in project voldemort by voldemort.

the class VoldemortNativeClientRequestFormat method readGetVersionResponse.

public List<Version> readGetVersionResponse(DataInputStream stream) throws IOException {
    checkException(stream);
    int resultSize = stream.readInt();
    List<Version> results = new ArrayList<Version>(resultSize);
    for (int i = 0; i < resultSize; i++) {
        int versionSize = stream.readInt();
        byte[] bytes = new byte[versionSize];
        ByteUtils.read(stream, bytes);
        VectorClock clock = new VectorClock(bytes);
        results.add(clock);
    }
    return results;
}
Also used : Version(voldemort.versioning.Version) VectorClock(voldemort.versioning.VectorClock) ArrayList(java.util.ArrayList)

Example 27 with Version

use of voldemort.versioning.Version in project voldemort by voldemort.

the class SystemStoreClient method putSysStore.

public Version putSysStore(K key, V value) {
    Version version = null;
    try {
        if (logger.isDebugEnabled()) {
            logger.debug("Invoking Put for key : " + key + " on store name : " + this.storeName);
        }
        Versioned<V> versioned = getSysStore(key);
        if (versioned == null)
            versioned = Versioned.value(value, new VectorClock());
        else
            versioned.setObject(value);
        this.sysStore.put(key, versioned, null);
        version = versioned.getVersion();
    } catch (Exception e) {
        if (logger.isDebugEnabled()) {
            logger.debug("Exception caught during putSysStore: " + e);
        }
    }
    return version;
}
Also used : Version(voldemort.versioning.Version) VectorClock(voldemort.versioning.VectorClock) InconsistentDataException(voldemort.versioning.InconsistentDataException) InvalidMetadataException(voldemort.store.InvalidMetadataException) VoldemortException(voldemort.VoldemortException)

Example 28 with Version

use of voldemort.versioning.Version in project voldemort by voldemort.

the class GetVersionResponseSender method sendResponse.

@Override
public void sendResponse(StoreStats performanceStats, boolean isFromLocalZone, long startTimeInMs) throws Exception {
    String base64Key = RestUtils.encodeVoldemortKey(key.get());
    String contentLocationKey = "/" + this.storeName + "/" + base64Key;
    List<VectorClock> vectorClocks = new ArrayList<VectorClock>();
    for (Version versionedValue : versionedValues) {
        VectorClock vectorClock = (VectorClock) versionedValue;
        vectorClocks.add(vectorClock);
        numVectorClockEntries += vectorClock.getVersionMap().size();
    }
    String eTags = RestUtils.getSerializedVectorClocks(vectorClocks);
    byte[] responseContent = eTags.getBytes();
    ChannelBuffer responseContentBuffer = ChannelBuffers.dynamicBuffer(responseContent.length);
    responseContentBuffer.writeBytes(responseContent);
    // Create the Response object
    HttpResponse response = new DefaultHttpResponse(HTTP_1_1, OK);
    // Set the right headers
    response.setHeader(CONTENT_TYPE, "binary");
    response.setHeader(CONTENT_TRANSFER_ENCODING, "binary");
    response.setHeader(CONTENT_LOCATION, contentLocationKey);
    // Copy the data into the payload
    response.setContent(responseContentBuffer);
    response.setHeader(CONTENT_LENGTH, response.getContent().readableBytes());
    // Write the response to the Netty Channel
    this.messageEvent.getChannel().write(response);
}
Also used : Version(voldemort.versioning.Version) DefaultHttpResponse(org.jboss.netty.handler.codec.http.DefaultHttpResponse) VectorClock(voldemort.versioning.VectorClock) ArrayList(java.util.ArrayList) DefaultHttpResponse(org.jboss.netty.handler.codec.http.DefaultHttpResponse) HttpResponse(org.jboss.netty.handler.codec.http.HttpResponse) ChannelBuffer(org.jboss.netty.buffer.ChannelBuffer)

Example 29 with Version

use of voldemort.versioning.Version in project voldemort by voldemort.

the class ReadRepairer method singleKeyGetRepairs.

private List<NodeValue<K, V>> singleKeyGetRepairs(List<NodeValue<K, V>> nodeValues) {
    int size = nodeValues.size();
    if (size <= 1)
        return Collections.emptyList();
    // 1. Create a multi-map of nodes to their existing Versions
    Multimap<Integer, NodeValue<K, V>> nodeVersionsMap = HashMultimap.create();
    for (NodeValue<K, V> nodeValue : nodeValues) {
        nodeVersionsMap.put(nodeValue.getNodeId(), nodeValue);
    }
    // 2. Create a map of the final set of versions (for this key)
    Map<Version, NodeValue<K, V>> mostCurrentVersionsMap = new HashMap<Version, NodeValue<K, V>>();
    // Initialize with the first element from the input
    mostCurrentVersionsMap.put(nodeValues.get(0).getVersion(), nodeValues.get(0));
    // check each value against the current set of most current versions
    for (int i = 1; i < nodeValues.size(); i++) {
        NodeValue<K, V> curr = nodeValues.get(i);
        boolean concurrentToAll = true;
        /*
             * Make a copy for the traversal. This is because the original map
             * can be modified during this traversal
             */
        Set<Version> knownGoodVersions = new HashSet<Version>(mostCurrentVersionsMap.keySet());
        for (Version currentGoodversion : knownGoodVersions) {
            // If the version already exists, do nothing
            if (curr.getVersion().equals(currentGoodversion)) {
                concurrentToAll = false;
                if (logger.isDebugEnabled()) {
                    logger.debug("Version already exists in the most current set: " + curr);
                }
                break;
            }
            // Check the ordering of the current value
            Occurred occurred = curr.getVersion().compare(currentGoodversion);
            if (occurred == Occurred.BEFORE) {
                // This value is obsolete! Break from the loop
                if (logger.isDebugEnabled()) {
                    logger.debug("Version is obsolete : " + curr);
                }
                concurrentToAll = false;
                break;
            } else if (occurred == Occurred.AFTER) {
                // This concurrent value is obsolete and the current value
                // should replace it
                mostCurrentVersionsMap.remove(currentGoodversion);
                concurrentToAll = false;
                mostCurrentVersionsMap.put(curr.getVersion(), curr);
                if (logger.isDebugEnabled()) {
                    logger.debug("Updating the current best - adding : " + curr);
                }
            }
        }
        // to the concurrent set
        if (concurrentToAll) {
            mostCurrentVersionsMap.put(curr.getVersion(), curr);
            if (logger.isDebugEnabled()) {
                logger.debug("Value is concurrent to all ! : " + curr);
            }
        }
    }
    // 3. Compare 1 and 2 and create the repair list
    List<NodeValue<K, V>> repairs = new ArrayList<NodeValue<K, V>>(3);
    for (int nodeId : nodeVersionsMap.keySet()) {
        Set<Version> finalVersions = new HashSet<Version>(mostCurrentVersionsMap.keySet());
        if (logger.isDebugEnabled()) {
            logger.debug("Set of final versions = " + finalVersions);
        }
        // Calculate the set difference between final Versions and
        // the versions currently existing for nodeId
        Set<Version> currentNodeVersions = new HashSet<Version>();
        for (NodeValue<K, V> nodeValue : nodeVersionsMap.get(nodeId)) {
            currentNodeVersions.add(nodeValue.getVersion());
        }
        finalVersions.removeAll(currentNodeVersions);
        if (logger.isDebugEnabled()) {
            logger.debug("Remaining versions to be repaired for this node after the set difference = " + finalVersions);
        }
        // Repair nodeId with the remaining Versioned values
        for (Version remainingVersion : finalVersions) {
            NodeValue<K, V> repair = new NodeValue<K, V>(nodeId, mostCurrentVersionsMap.get(remainingVersion).getKey(), mostCurrentVersionsMap.get(remainingVersion).getVersioned());
            if (logger.isDebugEnabled()) {
                logger.debug("Node value marked to be repaired : " + repair);
            }
            repairs.add(repair);
        }
    }
    return repairs;
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Version(voldemort.versioning.Version) Occurred(voldemort.versioning.Occurred) HashSet(java.util.HashSet)

Example 30 with Version

use of voldemort.versioning.Version in project voldemort by voldemort.

the class PerformPutHintedHandoff method execute.

@Override
public void execute(Pipeline pipeline) {
    Versioned<byte[]> versionedCopy = pipelineData.getVersionedCopy();
    for (Node slopFinalDestinationNode : pipelineData.getSynchronizer().getDelegatedSlopDestinations()) {
        int failedNodeId = slopFinalDestinationNode.getId();
        if (versionedCopy == null) {
            VectorClock clock = (VectorClock) versioned.getVersion();
            versionedCopy = new Versioned<byte[]>(versioned.getValue(), clock.incremented(failedNodeId, time.getMilliseconds()));
        }
        Version version = versionedCopy.getVersion();
        if (logger.isTraceEnabled())
            logger.trace("Performing parallel hinted handoff for node " + slopFinalDestinationNode + ", store " + pipelineData.getStoreName() + " key " + key + ", version " + version);
        Slop slop = new Slop(pipelineData.getStoreName(), Slop.Operation.PUT, key, versionedCopy.getValue(), transforms, failedNodeId, new Date());
        hintedHandoff.sendHintParallel(slopFinalDestinationNode, version, slop);
    }
    pipeline.addEvent(completeEvent);
}
Also used : Version(voldemort.versioning.Version) Node(voldemort.cluster.Node) VectorClock(voldemort.versioning.VectorClock) Slop(voldemort.store.slop.Slop) Date(java.util.Date)

Aggregations

Version (voldemort.versioning.Version)35 VectorClock (voldemort.versioning.VectorClock)16 Versioned (voldemort.versioning.Versioned)13 Test (org.junit.Test)11 ByteArray (voldemort.utils.ByteArray)10 VoldemortException (voldemort.VoldemortException)7 ArrayList (java.util.ArrayList)6 AbstractByteArrayStoreTest (voldemort.store.AbstractByteArrayStoreTest)5 HashMap (java.util.HashMap)4 IOException (java.io.IOException)3 List (java.util.List)3 ByteString (com.linkedin.data.ByteString)2 HashSet (java.util.HashSet)2 Map (java.util.Map)2 InvalidMetadataException (voldemort.store.InvalidMetadataException)2 Pair (voldemort.utils.Pair)2 ObsoleteVersionException (voldemort.versioning.ObsoleteVersionException)2 ImmutableList (com.google.common.collect.ImmutableList)1 RestException (com.linkedin.r2.message.rest.RestException)1 RestRequestBuilder (com.linkedin.r2.message.rest.RestRequestBuilder)1