use of com.github.ambry.protocol.PutRequest in project ambry by linkedin.
the class DirectSender method run.
@Override
public void run() {
try {
for (int i = 0; i < blobIds.size(); i++) {
PutRequest putRequest = new PutRequest(1, "client1", blobIds.get(i), blobProperties, ByteBuffer.wrap(usermetadata), Unpooled.wrappedBuffer(data), blobProperties.getBlobSize(), BlobType.DataBlob, encryptionKey != null ? ByteBuffer.wrap(encryptionKey) : null);
DataInputStream putResponseStream = channel.sendAndReceive(putRequest).getInputStream();
PutResponse response = PutResponse.readFrom(putResponseStream);
if (putResponseStream instanceof NettyByteBufDataInputStream) {
// Release the underlying netty buf if the stream is NettyByteBuf based.
// The ByteBuf should also be released if exception happens, but we ignore it since this is test and exception is not expected.
((NettyByteBufDataInputStream) putResponseStream).getBuffer().release();
}
Assert.assertEquals(response.getError(), ServerErrorCode.No_Error);
}
} catch (Exception e) {
Assert.assertTrue(false);
} finally {
endLatch.countDown();
}
}
use of com.github.ambry.protocol.PutRequest in project ambry by linkedin.
the class DirectoryUploader method writeToAmbryReplica.
/**
* Adding a blob to a particular server.
* @param stream stream containing the actual blob
* @param blobId blob id generated by ambry
* @param replicaId replica to which the blob has to be added
* @param correlationId coorelation id to uniquely identify the call
* @return true if write succeeds, else false
* @throws Exception
*/
private boolean writeToAmbryReplica(BlobProperties blobProperties, ByteBuffer userMetaData, InputStream stream, BlobId blobId, ReplicaId replicaId, AtomicInteger correlationId, boolean enableVerboseLogging) throws Exception {
ArrayList<BlobId> blobIds = new ArrayList<BlobId>();
blobIds.add(blobId);
ConnectedChannel blockingChannel = null;
try {
blockingChannel = connectionPool.checkOutConnection(replicaId.getDataNodeId().getHostname(), new Port(replicaId.getDataNodeId().getPort(), PortType.PLAINTEXT), 100000);
int size = (int) blobProperties.getBlobSize();
ByteBufferInputStream blobStream = new ByteBufferInputStream(stream, size);
PutRequest putRequest = new PutRequest(correlationId.incrementAndGet(), "consumerThread", blobId, blobProperties, userMetaData, Unpooled.wrappedBuffer(blobStream.getByteBuffer()), size, BlobType.DataBlob, null);
if (enableVerboseLogging) {
System.out.println("Put Request to a replica : " + putRequest + " for blobId " + blobId);
}
PutResponse putResponse = getPutResponseFromStream(blockingChannel, putRequest, connectionPool);
if (putResponse == null) {
System.out.println("PutResponse to a replica " + replicaId + " failed with null Response for blobId " + blobId);
blockingChannel = null;
return false;
} else {
if (putResponse.getError() != ServerErrorCode.No_Error && putResponse.getError() != ServerErrorCode.Blob_Already_Exists) {
System.out.println("PutResponse to a replica " + replicaId + " failed with Error code " + putResponse.getError() + " for blobId " + blobId);
return false;
}
return true;
}
} finally {
if (stream != null) {
stream.close();
}
if (blockingChannel != null) {
connectionPool.checkInConnection(blockingChannel);
}
}
}
Aggregations