1/********************************************************************
2 * Copyright (c) 2013 - 2014, Pivotal Inc.
3 * All rights reserved.
4 *
5 * Author: Zhanwei Wang
6 ********************************************************************/
7/********************************************************************
8 * 2014 -
9 * open source under Apache License Version 2.0
10 ********************************************************************/
11/**
12 * Licensed to the Apache Software Foundation (ASF) under one
13 * or more contributor license agreements. See the NOTICE file
14 * distributed with this work for additional information
15 * regarding copyright ownership. The ASF licenses this file
16 * to you under the Apache License, Version 2.0 (the
17 * "License"); you may not use this file except in compliance
18 * with the License. You may obtain a copy of the License at
19 *
20 * http://www.apache.org/licenses/LICENSE-2.0
21 *
22 * Unless required by applicable law or agreed to in writing, software
23 * distributed under the License is distributed on an "AS IS" BASIS,
24 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
25 * See the License for the specific language governing permissions and
26 * limitations under the License.
27 */
28#ifndef _HDFS_LIBHDFS_3_CLIENT_DATATRANSFERPROTOCOLSENDER_H_
29#define _HDFS_LIBHDFS_3_CLIENT_DATATRANSFERPROTOCOLSENDER_H_
30
31#include "DataTransferProtocol.h"
32#include "network/Socket.h"
33
34/**
35 * Version 28:
36 * Declare methods in DataTransferProtocol interface.
37 */
38#define DATA_TRANSFER_VERSION 28
39
40namespace Hdfs {
41namespace Internal {
42
43enum DataTransferOp {
44 WRITE_BLOCK = 80,
45 READ_BLOCK = 81,
46 READ_METADATA = 82,
47 REPLACE_BLOCK = 83,
48 COPY_BLOCK = 84,
49 BLOCK_CHECKSUM = 85,
50 TRANSFER_BLOCK = 86,
51 REQUEST_SHORT_CIRCUIT_FDS = 87,
52 RELEASE_SHORT_CIRCUIT_FDS = 88
53};
54
55/**
56 * Transfer data to/from datanode using a streaming protocol.
57 */
58class DataTransferProtocolSender: public DataTransferProtocol {
59public:
60 DataTransferProtocolSender(Socket & sock, int writeTimeout,
61 const std::string & datanodeAddr);
62
63 virtual ~DataTransferProtocolSender();
64
65 /**
66 * Read a block.
67 *
68 * @param blk the block being read.
69 * @param blockToken security token for accessing the block.
70 * @param clientName client's name.
71 * @param blockOffset offset of the block.
72 * @param length maximum number of bytes for this read.
73 */
74 virtual void readBlock(const ExtendedBlock & blk, const Token & blockToken,
75 const char * clientName, int64_t blockOffset, int64_t length);
76
77 /**
78 * Write a block to a datanode pipeline.
79 *
80 * @param blk the block being written.
81 * @param blockToken security token for accessing the block.
82 * @param clientName client's name.
83 * @param targets target datanodes in the pipeline.
84 * @param source source datanode.
85 * @param stage pipeline stage.
86 * @param pipelineSize the size of the pipeline.
87 * @param minBytesRcvd minimum number of bytes received.
88 * @param maxBytesRcvd maximum number of bytes received.
89 * @param latestGenerationStamp the latest generation stamp of the block.
90 */
91 virtual void writeBlock(const ExtendedBlock & blk, const Token & blockToken,
92 const char * clientName, const std::vector<DatanodeInfo> & targets,
93 int stage, int pipelineSize, int64_t minBytesRcvd,
94 int64_t maxBytesRcvd, int64_t latestGenerationStamp,
95 int checksumType, int bytesPerChecksum);
96
97 /**
98 * Transfer a block to another datanode.
99 * The block stage must be
100 * either {@link BlockConstructionStage#TRANSFER_RBW}
101 * or {@link BlockConstructionStage#TRANSFER_FINALIZED}.
102 *
103 * @param blk the block being transferred.
104 * @param blockToken security token for accessing the block.
105 * @param clientName client's name.
106 * @param targets target datanodes.
107 */
108 virtual void transferBlock(const ExtendedBlock & blk,
109 const Token & blockToken, const char * clientName,
110 const std::vector<DatanodeInfo> & targets);
111
112 /**
113 * Get block checksum (MD5 of CRC32).
114 *
115 * @param blk a block.
116 * @param blockToken security token for accessing the block.
117 * @throw HdfsIOException
118 */
119 virtual void blockChecksum(const ExtendedBlock & blk,
120 const Token & blockToken);
121
122 /**
123 * Request short circuit access file descriptors from a DataNode.
124 *
125 * @param blk The block to get file descriptors for.
126 * @param blockToken Security token for accessing the block.
127 * @param maxVersion Maximum version of the block data the client
128 * can understand.
129 */
130 virtual void requestShortCircuitFds(const ExtendedBlock blk,
131 const Token& blockToken,
132 uint32_t maxVersion);
133
134private:
135 Socket & sock;
136 int writeTimeout;
137 std::string datanode;
138};
139
140}
141}
142
143#endif /* _HDFS_LIBHDFS_3_CLIENT_DATATRANSFERPROTOCOLSENDER_H_ */
144