Search in sources :

Example 11 with XceiverClientReply

use of org.apache.hadoop.hdds.scm.XceiverClientReply in project ozone by apache.

the class TestWatchForCommit method testWatchForCommitForRetryfailure.

@Test
public void testWatchForCommitForRetryfailure() throws Exception {
    XceiverClientManager clientManager = new XceiverClientManager(conf);
    ContainerWithPipeline container1 = storageContainerLocationClient.allocateContainer(HddsProtos.ReplicationType.RATIS, HddsProtos.ReplicationFactor.THREE, OzoneConsts.OZONE);
    XceiverClientSpi xceiverClient = clientManager.acquireClient(container1.getPipeline());
    Assert.assertEquals(1, xceiverClient.getRefcount());
    Assert.assertEquals(container1.getPipeline(), xceiverClient.getPipeline());
    Pipeline pipeline = xceiverClient.getPipeline();
    TestHelper.createPipelineOnDatanode(pipeline, cluster);
    XceiverClientReply reply = xceiverClient.sendCommandAsync(ContainerTestHelper.getCreateContainerRequest(container1.getContainerInfo().getContainerID(), xceiverClient.getPipeline()));
    reply.getResponse().get();
    long index = reply.getLogIndex();
    cluster.shutdownHddsDatanode(pipeline.getNodes().get(0));
    cluster.shutdownHddsDatanode(pipeline.getNodes().get(1));
    // again write data with more than max buffer limit. This wi
    try {
        // just watch for a log index which in not updated in the commitInfo Map
        // as well as there is no logIndex generate in Ratis.
        // The basic idea here is just to test if its throws an exception.
        xceiverClient.watchForCommit(index + new Random().nextInt(100) + 10);
        Assert.fail("expected exception not thrown");
    } catch (Exception e) {
        Assert.assertTrue(e instanceof ExecutionException);
        // since the timeout value is quite long, the watch request will either
        // fail with NotReplicated exceptio, RetryFailureException or
        // RuntimeException
        Assert.assertFalse(HddsClientUtils.checkForException(e) instanceof TimeoutException);
    }
    clientManager.releaseClient(xceiverClient, false);
}
Also used : XceiverClientReply(org.apache.hadoop.hdds.scm.XceiverClientReply) Random(java.util.Random) XceiverClientManager(org.apache.hadoop.hdds.scm.XceiverClientManager) XceiverClientSpi(org.apache.hadoop.hdds.scm.XceiverClientSpi) ExecutionException(java.util.concurrent.ExecutionException) ContainerWithPipeline(org.apache.hadoop.hdds.scm.container.common.helpers.ContainerWithPipeline) TimeoutException(java.util.concurrent.TimeoutException) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException) GroupMismatchException(org.apache.ratis.protocol.exceptions.GroupMismatchException) ContainerWithPipeline(org.apache.hadoop.hdds.scm.container.common.helpers.ContainerWithPipeline) Pipeline(org.apache.hadoop.hdds.scm.pipeline.Pipeline) TimeoutException(java.util.concurrent.TimeoutException) Test(org.junit.jupiter.api.Test)

Example 12 with XceiverClientReply

use of org.apache.hadoop.hdds.scm.XceiverClientReply in project ozone by apache.

the class TestWatchForCommit method testWatchForCommitForGroupMismatchException.

@Test
public void testWatchForCommitForGroupMismatchException() throws Exception {
    XceiverClientManager clientManager = new XceiverClientManager(conf);
    ContainerWithPipeline container1 = storageContainerLocationClient.allocateContainer(HddsProtos.ReplicationType.RATIS, HddsProtos.ReplicationFactor.THREE, OzoneConsts.OZONE);
    XceiverClientSpi xceiverClient = clientManager.acquireClient(container1.getPipeline());
    Assert.assertEquals(1, xceiverClient.getRefcount());
    Assert.assertEquals(container1.getPipeline(), xceiverClient.getPipeline());
    Pipeline pipeline = xceiverClient.getPipeline();
    XceiverClientRatis ratisClient = (XceiverClientRatis) xceiverClient;
    long containerId = container1.getContainerInfo().getContainerID();
    XceiverClientReply reply = xceiverClient.sendCommandAsync(ContainerTestHelper.getCreateContainerRequest(containerId, xceiverClient.getPipeline()));
    reply.getResponse().get();
    Assert.assertEquals(3, ratisClient.getCommitInfoMap().size());
    List<Pipeline> pipelineList = new ArrayList<>();
    pipelineList.add(pipeline);
    TestHelper.waitForPipelineClose(pipelineList, cluster);
    try {
        // just watch for a log index which in not updated in the commitInfo Map
        // as well as there is no logIndex generate in Ratis.
        // The basic idea here is just to test if its throws an exception.
        xceiverClient.watchForCommit(reply.getLogIndex() + new Random().nextInt(100) + 10);
        Assert.fail("Expected exception not thrown");
    } catch (Exception e) {
        Assert.assertTrue(HddsClientUtils.checkForException(e) instanceof GroupMismatchException);
    }
    clientManager.releaseClient(xceiverClient, false);
}
Also used : XceiverClientReply(org.apache.hadoop.hdds.scm.XceiverClientReply) Random(java.util.Random) ArrayList(java.util.ArrayList) GroupMismatchException(org.apache.ratis.protocol.exceptions.GroupMismatchException) XceiverClientRatis(org.apache.hadoop.hdds.scm.XceiverClientRatis) XceiverClientManager(org.apache.hadoop.hdds.scm.XceiverClientManager) XceiverClientSpi(org.apache.hadoop.hdds.scm.XceiverClientSpi) ContainerWithPipeline(org.apache.hadoop.hdds.scm.container.common.helpers.ContainerWithPipeline) TimeoutException(java.util.concurrent.TimeoutException) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException) GroupMismatchException(org.apache.ratis.protocol.exceptions.GroupMismatchException) ContainerWithPipeline(org.apache.hadoop.hdds.scm.container.common.helpers.ContainerWithPipeline) Pipeline(org.apache.hadoop.hdds.scm.pipeline.Pipeline) Test(org.junit.jupiter.api.Test)

Example 13 with XceiverClientReply

use of org.apache.hadoop.hdds.scm.XceiverClientReply in project ozone by apache.

the class BlockOutputStream method executePutBlock.

/**
 * @param close whether putBlock is happening as part of closing the stream
 * @param force true if no data was written since most recent putBlock and
 *            stream is being closed
 */
CompletableFuture<ContainerProtos.ContainerCommandResponseProto> executePutBlock(boolean close, boolean force) throws IOException {
    checkOpen();
    long flushPos = totalDataFlushedLength;
    final List<ChunkBuffer> byteBufferList;
    if (!force) {
        Preconditions.checkNotNull(bufferList);
        byteBufferList = bufferList;
        bufferList = null;
        Preconditions.checkNotNull(byteBufferList);
    } else {
        byteBufferList = null;
    }
    CompletableFuture<ContainerProtos.ContainerCommandResponseProto> flushFuture = null;
    try {
        BlockData blockData = containerBlockData.build();
        XceiverClientReply asyncReply = putBlockAsync(xceiverClient, blockData, close, token);
        CompletableFuture<ContainerProtos.ContainerCommandResponseProto> future = asyncReply.getResponse();
        flushFuture = future.thenApplyAsync(e -> {
            try {
                validateResponse(e);
            } catch (IOException sce) {
                throw new CompletionException(sce);
            }
            // if the ioException is not set, putBlock is successful
            if (getIoException() == null && !force) {
                BlockID responseBlockID = BlockID.getFromProtobuf(e.getPutBlock().getCommittedBlockLength().getBlockID());
                Preconditions.checkState(blockID.get().getContainerBlockID().equals(responseBlockID.getContainerBlockID()));
                // updates the bcsId of the block
                blockID.set(responseBlockID);
                if (LOG.isDebugEnabled()) {
                    LOG.debug("Adding index " + asyncReply.getLogIndex() + " flushLength " + flushPos + " numBuffers " + byteBufferList.size() + " blockID " + blockID + " bufferPool size" + bufferPool.getSize() + " currentBufferIndex " + bufferPool.getCurrentBufferIndex());
                }
                // for standalone protocol, logIndex will always be 0.
                updateCommitInfo(asyncReply, byteBufferList);
            }
            return e;
        }, responseExecutor).exceptionally(e -> {
            if (LOG.isDebugEnabled()) {
                LOG.debug("putBlock failed for blockID {} with exception {}", blockID, e.getLocalizedMessage());
            }
            CompletionException ce = new CompletionException(e);
            setIoException(ce);
            throw ce;
        });
    } catch (IOException | ExecutionException e) {
        throw new IOException(EXCEPTION_MSG + e.toString(), e);
    } catch (InterruptedException ex) {
        Thread.currentThread().interrupt();
        handleInterruptedException(ex, false);
    }
    putFlushFuture(flushPos, flushFuture);
    return flushFuture;
}
Also used : BlockID(org.apache.hadoop.hdds.client.BlockID) OzoneChecksumException(org.apache.hadoop.ozone.common.OzoneChecksumException) ContainerCommandResponseProto(org.apache.hadoop.hdds.protocol.datanode.proto.ContainerProtos.ContainerCommandResponseProto) ContainerProtocolCalls.writeChunkAsync(org.apache.hadoop.hdds.scm.storage.ContainerProtocolCalls.writeChunkAsync) LoggerFactory(org.slf4j.LoggerFactory) CompletableFuture(java.util.concurrent.CompletableFuture) KeyValue(org.apache.hadoop.hdds.protocol.datanode.proto.ContainerProtos.KeyValue) ChecksumData(org.apache.hadoop.ozone.common.ChecksumData) ContainerProtos(org.apache.hadoop.hdds.protocol.datanode.proto.ContainerProtos) AtomicReference(java.util.concurrent.atomic.AtomicReference) OzoneClientConfig(org.apache.hadoop.hdds.scm.OzoneClientConfig) ArrayList(java.util.ArrayList) TokenIdentifier(org.apache.hadoop.security.token.TokenIdentifier) ByteString(org.apache.ratis.thirdparty.com.google.protobuf.ByteString) Checksum(org.apache.hadoop.ozone.common.Checksum) ExecutorService(java.util.concurrent.ExecutorService) OutputStream(java.io.OutputStream) XceiverClientFactory(org.apache.hadoop.hdds.scm.XceiverClientFactory) BlockData(org.apache.hadoop.hdds.protocol.datanode.proto.ContainerProtos.BlockData) Logger(org.slf4j.Logger) DatanodeDetails(org.apache.hadoop.hdds.protocol.DatanodeDetails) IOException(java.io.IOException) CompletionException(java.util.concurrent.CompletionException) ChunkInfo(org.apache.hadoop.hdds.protocol.datanode.proto.ContainerProtos.ChunkInfo) Pipeline(org.apache.hadoop.hdds.scm.pipeline.Pipeline) Token(org.apache.hadoop.security.token.Token) ContainerProtocolCalls.putBlockAsync(org.apache.hadoop.hdds.scm.storage.ContainerProtocolCalls.putBlockAsync) Executors(java.util.concurrent.Executors) XceiverClientReply(org.apache.hadoop.hdds.scm.XceiverClientReply) ExecutionException(java.util.concurrent.ExecutionException) AtomicLong(java.util.concurrent.atomic.AtomicLong) List(java.util.List) XceiverClientSpi(org.apache.hadoop.hdds.scm.XceiverClientSpi) StorageContainerException(org.apache.hadoop.hdds.scm.container.common.helpers.StorageContainerException) ChunkBuffer(org.apache.hadoop.ozone.common.ChunkBuffer) Preconditions(com.google.common.base.Preconditions) VisibleForTesting(com.google.common.annotations.VisibleForTesting) IOException(java.io.IOException) ContainerCommandResponseProto(org.apache.hadoop.hdds.protocol.datanode.proto.ContainerProtos.ContainerCommandResponseProto) XceiverClientReply(org.apache.hadoop.hdds.scm.XceiverClientReply) CompletionException(java.util.concurrent.CompletionException) ChunkBuffer(org.apache.hadoop.ozone.common.ChunkBuffer) BlockID(org.apache.hadoop.hdds.client.BlockID) BlockData(org.apache.hadoop.hdds.protocol.datanode.proto.ContainerProtos.BlockData) ExecutionException(java.util.concurrent.ExecutionException)

Example 14 with XceiverClientReply

use of org.apache.hadoop.hdds.scm.XceiverClientReply in project ozone by apache.

the class BlockOutputStream method writeChunkToContainer.

/**
 * Writes buffered data as a new chunk to the container and saves chunk
 * information to be used later in putKey call.
 *
 * @throws IOException if there is an I/O error while performing the call
 * @throws OzoneChecksumException if there is an error while computing
 * checksum
 * @return
 */
CompletableFuture<ContainerCommandResponseProto> writeChunkToContainer(ChunkBuffer chunk) throws IOException {
    int effectiveChunkSize = chunk.remaining();
    final long offset = chunkOffset.getAndAdd(effectiveChunkSize);
    final ByteString data = chunk.toByteString(bufferPool.byteStringConversion());
    ChecksumData checksumData = checksum.computeChecksum(chunk);
    ChunkInfo chunkInfo = ChunkInfo.newBuilder().setChunkName(blockID.get().getLocalID() + "_chunk_" + ++chunkIndex).setOffset(offset).setLen(effectiveChunkSize).setChecksumData(checksumData.getProtoBufMessage()).build();
    if (LOG.isDebugEnabled()) {
        LOG.debug("Writing chunk {} length {} at offset {}", chunkInfo.getChunkName(), effectiveChunkSize, offset);
    }
    try {
        XceiverClientReply asyncReply = writeChunkAsync(xceiverClient, chunkInfo, blockID.get(), data, token, replicationIndex);
        CompletableFuture<ContainerProtos.ContainerCommandResponseProto> respFuture = asyncReply.getResponse();
        CompletableFuture<ContainerProtos.ContainerCommandResponseProto> validateFuture = respFuture.thenApplyAsync(e -> {
            try {
                validateResponse(e);
            } catch (IOException sce) {
                respFuture.completeExceptionally(sce);
            }
            return e;
        }, responseExecutor).exceptionally(e -> {
            String msg = "Failed to write chunk " + chunkInfo.getChunkName() + " into block " + blockID;
            LOG.debug("{}, exception: {}", msg, e.getLocalizedMessage());
            CompletionException ce = new CompletionException(msg, e);
            setIoException(ce);
            throw ce;
        });
        containerBlockData.addChunks(chunkInfo);
        return validateFuture;
    } catch (IOException | ExecutionException e) {
        throw new IOException(EXCEPTION_MSG + e.toString(), e);
    } catch (InterruptedException ex) {
        Thread.currentThread().interrupt();
        handleInterruptedException(ex, false);
    }
    return null;
}
Also used : BlockID(org.apache.hadoop.hdds.client.BlockID) OzoneChecksumException(org.apache.hadoop.ozone.common.OzoneChecksumException) ContainerCommandResponseProto(org.apache.hadoop.hdds.protocol.datanode.proto.ContainerProtos.ContainerCommandResponseProto) ContainerProtocolCalls.writeChunkAsync(org.apache.hadoop.hdds.scm.storage.ContainerProtocolCalls.writeChunkAsync) LoggerFactory(org.slf4j.LoggerFactory) CompletableFuture(java.util.concurrent.CompletableFuture) KeyValue(org.apache.hadoop.hdds.protocol.datanode.proto.ContainerProtos.KeyValue) ChecksumData(org.apache.hadoop.ozone.common.ChecksumData) ContainerProtos(org.apache.hadoop.hdds.protocol.datanode.proto.ContainerProtos) AtomicReference(java.util.concurrent.atomic.AtomicReference) OzoneClientConfig(org.apache.hadoop.hdds.scm.OzoneClientConfig) ArrayList(java.util.ArrayList) TokenIdentifier(org.apache.hadoop.security.token.TokenIdentifier) ByteString(org.apache.ratis.thirdparty.com.google.protobuf.ByteString) Checksum(org.apache.hadoop.ozone.common.Checksum) ExecutorService(java.util.concurrent.ExecutorService) OutputStream(java.io.OutputStream) XceiverClientFactory(org.apache.hadoop.hdds.scm.XceiverClientFactory) BlockData(org.apache.hadoop.hdds.protocol.datanode.proto.ContainerProtos.BlockData) Logger(org.slf4j.Logger) DatanodeDetails(org.apache.hadoop.hdds.protocol.DatanodeDetails) IOException(java.io.IOException) CompletionException(java.util.concurrent.CompletionException) ChunkInfo(org.apache.hadoop.hdds.protocol.datanode.proto.ContainerProtos.ChunkInfo) Pipeline(org.apache.hadoop.hdds.scm.pipeline.Pipeline) Token(org.apache.hadoop.security.token.Token) ContainerProtocolCalls.putBlockAsync(org.apache.hadoop.hdds.scm.storage.ContainerProtocolCalls.putBlockAsync) Executors(java.util.concurrent.Executors) XceiverClientReply(org.apache.hadoop.hdds.scm.XceiverClientReply) ExecutionException(java.util.concurrent.ExecutionException) AtomicLong(java.util.concurrent.atomic.AtomicLong) List(java.util.List) XceiverClientSpi(org.apache.hadoop.hdds.scm.XceiverClientSpi) StorageContainerException(org.apache.hadoop.hdds.scm.container.common.helpers.StorageContainerException) ChunkBuffer(org.apache.hadoop.ozone.common.ChunkBuffer) Preconditions(com.google.common.base.Preconditions) VisibleForTesting(com.google.common.annotations.VisibleForTesting) ChunkInfo(org.apache.hadoop.hdds.protocol.datanode.proto.ContainerProtos.ChunkInfo) ChecksumData(org.apache.hadoop.ozone.common.ChecksumData) ByteString(org.apache.ratis.thirdparty.com.google.protobuf.ByteString) IOException(java.io.IOException) ByteString(org.apache.ratis.thirdparty.com.google.protobuf.ByteString) ContainerCommandResponseProto(org.apache.hadoop.hdds.protocol.datanode.proto.ContainerProtos.ContainerCommandResponseProto) XceiverClientReply(org.apache.hadoop.hdds.scm.XceiverClientReply) CompletionException(java.util.concurrent.CompletionException) ExecutionException(java.util.concurrent.ExecutionException)

Example 15 with XceiverClientReply

use of org.apache.hadoop.hdds.scm.XceiverClientReply in project ozone by apache.

the class MockXceiverClientSpi method result.

private XceiverClientReply result(ContainerCommandRequestProto request, Function<ContainerCommandResponseProto.Builder, ContainerCommandResponseProto.Builder> function) {
    Builder builder = ContainerCommandResponseProto.newBuilder().setResult(Result.SUCCESS).setCmdType(request.getCmdType());
    builder = function.apply(builder);
    XceiverClientReply reply = new XceiverClientReply(CompletableFuture.completedFuture(builder.build()));
    return reply;
}
Also used : XceiverClientReply(org.apache.hadoop.hdds.scm.XceiverClientReply) Builder(org.apache.hadoop.hdds.protocol.datanode.proto.ContainerProtos.ContainerCommandResponseProto.Builder)

Aggregations

XceiverClientReply (org.apache.hadoop.hdds.scm.XceiverClientReply)15 Pipeline (org.apache.hadoop.hdds.scm.pipeline.Pipeline)11 IOException (java.io.IOException)8 XceiverClientSpi (org.apache.hadoop.hdds.scm.XceiverClientSpi)8 DatanodeDetails (org.apache.hadoop.hdds.protocol.DatanodeDetails)7 ArrayList (java.util.ArrayList)6 CompletableFuture (java.util.concurrent.CompletableFuture)6 ExecutionException (java.util.concurrent.ExecutionException)6 ContainerProtos (org.apache.hadoop.hdds.protocol.datanode.proto.ContainerProtos)6 XceiverClientManager (org.apache.hadoop.hdds.scm.XceiverClientManager)6 XceiverClientRatis (org.apache.hadoop.hdds.scm.XceiverClientRatis)6 ContainerWithPipeline (org.apache.hadoop.hdds.scm.container.common.helpers.ContainerWithPipeline)6 BlockID (org.apache.hadoop.hdds.client.BlockID)5 ChunkBuffer (org.apache.hadoop.ozone.common.ChunkBuffer)5 ByteString (org.apache.ratis.thirdparty.com.google.protobuf.ByteString)5 List (java.util.List)4 Preconditions (com.google.common.base.Preconditions)3 Random (java.util.Random)3 CompletionException (java.util.concurrent.CompletionException)3 TimeoutException (java.util.concurrent.TimeoutException)3