Search in sources :

Example 1 with UpdatePartitionEntriesRequest

use of voldemort.client.protocol.pb.VAdminProto.UpdatePartitionEntriesRequest in project voldemort by voldemort.

the class UpdatePartitionEntriesStreamRequestHandler method handleRequest.

@Override
public StreamRequestHandlerState handleRequest(DataInputStream inputStream, DataOutputStream outputStream) throws IOException {
    if (!metadataStore.getPartitionStreamingEnabledUnlocked()) {
        throw new VoldemortException("Partition streaming is disabled on node " + metadataStore.getNodeId() + " under " + metadataStore.getServerStateUnlocked() + " state.");
    }
    long startNs = System.nanoTime();
    if (request == null) {
        int size = 0;
        try {
            size = inputStream.readInt();
        } catch (EOFException e) {
            if (logger.isTraceEnabled())
                logger.trace("Incomplete read for message size");
            if (streamStats != null)
                streamStats.reportNetworkTime(Operation.UPDATE_ENTRIES, Utils.elapsedTimeNs(startNs, System.nanoTime()));
            return StreamRequestHandlerState.INCOMPLETE_READ;
        }
        if (size == -1) {
            long totalTime = (System.currentTimeMillis() - startTime) / 1000;
            logger.info(getHandlerName() + " successfully updated " + counter + " entries for store '" + storageEngine.getName() + "' in " + totalTime + " s");
            if (logger.isTraceEnabled())
                logger.trace("Message size -1, completed partition update");
            if (streamStats != null)
                streamStats.reportNetworkTime(Operation.UPDATE_ENTRIES, Utils.elapsedTimeNs(startNs, System.nanoTime()));
            return StreamRequestHandlerState.COMPLETE;
        }
        if (logger.isTraceEnabled())
            logger.trace("UpdatePartitionEntriesRequest message size: " + size);
        byte[] input = new byte[size];
        try {
            ByteUtils.read(inputStream, input);
        } catch (EOFException e) {
            if (logger.isTraceEnabled())
                logger.trace("Incomplete read for message");
            return StreamRequestHandlerState.INCOMPLETE_READ;
        } finally {
            if (streamStats != null)
                streamStats.reportNetworkTime(Operation.UPDATE_ENTRIES, Utils.elapsedTimeNs(startNs, System.nanoTime()));
        }
        VAdminProto.UpdatePartitionEntriesRequest.Builder builder = VAdminProto.UpdatePartitionEntriesRequest.newBuilder();
        builder.mergeFrom(input);
        request = builder.build();
    }
    VAdminProto.PartitionEntry partitionEntry = request.getPartitionEntry();
    ByteArray key = ProtoUtils.decodeBytes(partitionEntry.getKey());
    Versioned<byte[]> value = ProtoUtils.decodeVersioned(partitionEntry.getVersioned());
    if (filter.accept(key, value)) {
        startNs = System.nanoTime();
        try {
            processEntry(key, value);
            if (logger.isTraceEnabled())
                logger.trace(getHandlerName() + " (Streaming put) successful");
        } catch (ObsoleteVersionException e) {
            // log and ignore
            if (logger.isDebugEnabled())
                logger.debug(getHandlerName() + " (Streaming put) threw ObsoleteVersionException, Ignoring.");
        } finally {
            if (streamStats != null) {
                streamStats.reportStreamingPut(Operation.UPDATE_ENTRIES);
                streamStats.reportStorageTime(Operation.UPDATE_ENTRIES, Utils.elapsedTimeNs(startNs, System.nanoTime()));
            }
        }
        throttler.maybeThrottle(key.length() + AdminServiceRequestHandler.valueSize(value));
    }
    // log progress
    counter++;
    if (0 == counter % STAT_RECORDS_INTERVAL) {
        long totalTime = (System.currentTimeMillis() - startTime) / Time.MS_PER_SECOND;
        logger.info(getHandlerName() + " updated " + counter + " entries for store '" + storageEngine.getName() + "' in " + totalTime + " s");
    }
    request = null;
    return StreamRequestHandlerState.READING;
}
Also used : UpdatePartitionEntriesRequest(voldemort.client.protocol.pb.VAdminProto.UpdatePartitionEntriesRequest) ObsoleteVersionException(voldemort.versioning.ObsoleteVersionException) EOFException(java.io.EOFException) ByteArray(voldemort.utils.ByteArray) VAdminProto(voldemort.client.protocol.pb.VAdminProto) VoldemortException(voldemort.VoldemortException)

Aggregations

EOFException (java.io.EOFException)1 VoldemortException (voldemort.VoldemortException)1 VAdminProto (voldemort.client.protocol.pb.VAdminProto)1 UpdatePartitionEntriesRequest (voldemort.client.protocol.pb.VAdminProto.UpdatePartitionEntriesRequest)1 ByteArray (voldemort.utils.ByteArray)1 ObsoleteVersionException (voldemort.versioning.ObsoleteVersionException)1