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;
}
}
}
}
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.");
}
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);
}
}
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;
}
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);
}
}
};
}
Aggregations