private AbstractWriteHandler createWriterHandler(alluxio.grpc.WriteRequest request) { switch (request.getCommand().getType()) { case ALLUXIO_BLOCK: return new BlockWriteHandler(mWorkerProcess.getWorker(BlockWorker.class), mResponseObserver); case UFS_FILE: return new UfsFileWriteHandler(mWorkerProcess.getUfsManager(), mResponseObserver); case UFS_FALLBACK_BLOCK: return new UfsFallbackBlockWriteHandler( mWorkerProcess.getWorker(BlockWorker.class), mWorkerProcess.getUfsManager(), mResponseObserver); default: throw new IllegalArgumentException(String.format("Invalid request type %s", request.getCommand().getType().name())); } }
/** * Notifies the server UFS fallback endpoint to start writing a new block by resuming the given * number of bytes from block store. * * @param pos number of bytes already written to block store */ public void writeFallbackInitRequest(long pos) throws IOException { Preconditions.checkState(mPartialRequest.getType() == RequestType.UFS_FALLBACK_BLOCK); Protocol.CreateUfsBlockOptions ufsBlockOptions = mPartialRequest.getCreateUfsBlockOptions() .toBuilder().setBytesInBlockStore(pos).build(); WriteRequest writeRequest = WriteRequest.newBuilder().setCommand( mPartialRequest.toBuilder().setOffset(0).setCreateUfsBlockOptions(ufsBlockOptions)) .build(); mPosToQueue = pos; mStream.send(writeRequest, mDataTimeoutMs); }
public Builder mergeFrom(alluxio.grpc.WriteRequestCommand other) { if (other == alluxio.grpc.WriteRequestCommand.getDefaultInstance()) return this; if (other.hasType()) { setType(other.getType()); } if (other.hasId()) { setId(other.getId()); } if (other.hasOffset()) { setOffset(other.getOffset()); } if (other.hasTier()) { setTier(other.getTier()); } if (other.hasFlush()) { setFlush(other.getFlush()); } if (other.hasCreateUfsFileOptions()) { mergeCreateUfsFileOptions(other.getCreateUfsFileOptions()); } if (other.hasCreateUfsBlockOptions()) { mergeCreateUfsBlockOptions(other.getCreateUfsBlockOptions()); } this.mergeUnknownFields(other.unknownFields); onChanged(); return this; }
/** * Validates the read request sent. * * @param request the request * @param offset the offset */ private void validateWriteRequest(WriteRequest request, long offset) { if (request.hasCommand()) { assertEquals(RequestType.UFS_FALLBACK_BLOCK, request.getCommand().getType()); assertEquals(BLOCK_ID, request.getCommand().getId()); assertEquals(offset, request.getCommand().getOffset()); assertTrue(request.getCommand().hasCreateUfsBlockOptions()); assertEquals(MOUNT_ID, request.getCommand().getCreateUfsBlockOptions().getMountId()); } else { assertTrue(request.hasChunk()); } } }