Search in sources :

Example 81 with ByteArray

use of voldemort.utils.ByteArray in project voldemort by voldemort.

the class RestServerRequestHandler method registerRequest.

/**
     * Constructs a valid request and passes it on to the next handler. It also
     * creates the 'Store' object corresponding to the store name specified in
     * the REST request.
     * 
     * @param requestValidator The Validator object used to construct the
     *        request object
     * @param ctx Context of the Netty channel
     * @param messageEvent Message Event used to write the response / exception
     */
@Override
protected void registerRequest(RestRequestValidator requestValidator, ChannelHandlerContext ctx, MessageEvent messageEvent) {
    // At this point we know the request is valid and we have a
    // error handler. So we construct the composite Voldemort
    // request object.
    CompositeVoldemortRequest<ByteArray, byte[]> requestObject = requestValidator.constructCompositeVoldemortRequestObject();
    if (requestObject != null) {
        // Dropping dead requests from going to next handler
        long now = System.currentTimeMillis();
        if (requestObject.getRequestOriginTimeInMs() + requestObject.getRoutingTimeoutInMs() <= now) {
            RestErrorHandler.writeErrorResponse(messageEvent, HttpResponseStatus.REQUEST_TIMEOUT, "current time: " + now + "\torigin time: " + requestObject.getRequestOriginTimeInMs() + "\ttimeout in ms: " + requestObject.getRoutingTimeoutInMs());
            return;
        } else {
            Store store = getStore(requestValidator.getStoreName(), requestValidator.getParsedRoutingType());
            if (store != null) {
                VoldemortStoreRequest voldemortStoreRequest = new VoldemortStoreRequest(requestObject, store, parseZoneId());
                Channels.fireMessageReceived(ctx, voldemortStoreRequest);
            } else {
                logger.error("Error when getting store. Non Existing store name.");
                RestErrorHandler.writeErrorResponse(messageEvent, HttpResponseStatus.BAD_REQUEST, "Non Existing store name. Critical error.");
                return;
            }
        }
    }
}
Also used : ByteArray(voldemort.utils.ByteArray) Store(voldemort.store.Store)

Example 82 with ByteArray

use of voldemort.utils.ByteArray in project voldemort by voldemort.

the class StoreRepository method addNodeStore.

public void addNodeStore(int nodeId, Store<ByteArray, byte[], byte[]> store) {
    Pair<String, Integer> key = Pair.create(store.getName(), nodeId);
    Store<ByteArray, byte[], byte[]> found = this.nodeStores.putIfAbsent(key, store);
    if (found != null)
        throw new VoldemortException("Store '" + store.getName() + "' for node " + nodeId + " has already been initialized.");
}
Also used : ByteArray(voldemort.utils.ByteArray) VoldemortException(voldemort.VoldemortException)

Example 83 with ByteArray

use of voldemort.utils.ByteArray in project voldemort by voldemort.

the class SlopSerializer method toBytes.

public byte[] toBytes(Slop slop) {
    ByteArrayOutputStream byteOutput = new ByteArrayOutputStream();
    DataOutputStream data = new DataOutputStream(byteOutput);
    try {
        VSlopProto.Slop.Builder builder = VSlopProto.Slop.newBuilder().setStore(slop.getStoreName()).setOperation(slop.getOperation().toString()).setKey(ProtoUtils.encodeBytes(slop.getKey())).setNodeId(slop.getNodeId()).setArrived(slop.getArrived().getTime());
        if (slop.getValue() != null)
            builder.setValue(ProtoUtils.encodeBytes(new ByteArray(slop.getValue())));
        ProtoUtils.writeMessage(data, builder.build());
        return byteOutput.toByteArray();
    } catch (IOException e) {
        throw new SerializationException(e);
    }
}
Also used : DataOutputStream(java.io.DataOutputStream) ByteArray(voldemort.utils.ByteArray) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) Slop(voldemort.store.slop.Slop)

Example 84 with ByteArray

use of voldemort.utils.ByteArray in project voldemort by voldemort.

the class ServerTestUtils method waitForServerStart.

/**
     * Test if socket connection is available on the node
     *
     *
     * @param socketStoreFactory
     * @param node
     */
public static void waitForServerStart(SocketStoreFactory socketStoreFactory, Node node) {
    boolean success = false;
    UnreachableStoreException exception = null;
    int retries = 10;
    Store<ByteArray, ?, ?> store = null;
    while (retries-- > 0 && !success) {
        store = ServerTestUtils.getSocketStore(socketStoreFactory, MetadataStore.METADATA_STORE_NAME, node.getSocketPort());
        try {
            store.get(new ByteArray(MetadataStore.CLUSTER_KEY.getBytes()), null);
            success = true;
        } catch (UnreachableStoreException e) {
            System.out.println("UnreachableSocketStore sleeping will try again " + retries + " times.");
            exception = e;
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e1) {
            // ignore
            }
        } finally {
            store.close();
            store = null;
        }
    }
    if (!success)
        throw exception;
}
Also used : ByteArray(voldemort.utils.ByteArray) UnreachableStoreException(voldemort.store.UnreachableStoreException)

Example 85 with ByteArray

use of voldemort.utils.ByteArray 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)

Aggregations

ByteArray (voldemort.utils.ByteArray)309 Versioned (voldemort.versioning.Versioned)130 Test (org.junit.Test)125 VoldemortException (voldemort.VoldemortException)67 VectorClock (voldemort.versioning.VectorClock)65 ArrayList (java.util.ArrayList)61 Node (voldemort.cluster.Node)61 List (java.util.List)58 HashMap (java.util.HashMap)53 StoreDefinition (voldemort.store.StoreDefinition)49 Cluster (voldemort.cluster.Cluster)33 AbstractByteArrayStoreTest (voldemort.store.AbstractByteArrayStoreTest)31 Store (voldemort.store.Store)31 ObsoleteVersionException (voldemort.versioning.ObsoleteVersionException)31 IOException (java.io.IOException)30 Slop (voldemort.store.slop.Slop)29 Map (java.util.Map)28 Pair (voldemort.utils.Pair)28 UnreachableStoreException (voldemort.store.UnreachableStoreException)26 StatTrackingStore (voldemort.store.stats.StatTrackingStore)25