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_DATATRANSFERPROTOCOL_H_ |
29 | #define _HDFS_LIBHDFS_3_CLIENT_DATATRANSFERPROTOCOL_H_ |
30 | |
31 | #include "client/Token.h" |
32 | #include "server/DatanodeInfo.h" |
33 | #include "server/ExtendedBlock.h" |
34 | |
35 | #include <vector> |
36 | |
37 | namespace Hdfs { |
38 | namespace Internal { |
39 | |
40 | /** |
41 | * Transfer data to/from datanode using a streaming protocol. |
42 | */ |
43 | class DataTransferProtocol { |
44 | public: |
45 | virtual ~DataTransferProtocol() { |
46 | } |
47 | /** |
48 | * Read a block. |
49 | * |
50 | * @param blk the block being read. |
51 | * @param blockToken security token for accessing the block. |
52 | * @param clientName client's name. |
53 | * @param blockOffset offset of the block. |
54 | * @param length maximum number of bytes for this read. |
55 | */ |
56 | virtual void readBlock(const ExtendedBlock & blk, |
57 | const Token & blockToken, const char * clientName, |
58 | int64_t blockOffset, int64_t length) = 0; |
59 | |
60 | /** |
61 | * Write a block to a datanode pipeline. |
62 | * |
63 | * @param blk the block being written. |
64 | * @param blockToken security token for accessing the block. |
65 | * @param clientName client's name. |
66 | * @param targets target datanodes in the pipeline. |
67 | * @param source source datanode. |
68 | * @param stage pipeline stage. |
69 | * @param pipelineSize the size of the pipeline. |
70 | * @param minBytesRcvd minimum number of bytes received. |
71 | * @param maxBytesRcvd maximum number of bytes received. |
72 | * @param latestGenerationStamp the latest generation stamp of the block. |
73 | */ |
74 | virtual void writeBlock(const ExtendedBlock & blk, |
75 | const Token & blockToken, const char * clientName, |
76 | const std::vector<DatanodeInfo> & targets, int stage, |
77 | int pipelineSize, int64_t minBytesRcvd, int64_t maxBytesRcvd, |
78 | int64_t latestGenerationStamp, int checksumType, |
79 | int bytesPerChecksum) = 0; |
80 | |
81 | /** |
82 | * Transfer a block to another datanode. |
83 | * The block stage must be |
84 | * either {@link BlockConstructionStage#TRANSFER_RBW} |
85 | * or {@link BlockConstructionStage#TRANSFER_FINALIZED}. |
86 | * |
87 | * @param blk the block being transferred. |
88 | * @param blockToken security token for accessing the block. |
89 | * @param clientName client's name. |
90 | * @param targets target datanodes. |
91 | */ |
92 | virtual void transferBlock(const ExtendedBlock & blk, |
93 | const Token & blockToken, const char * clientName, |
94 | const std::vector<DatanodeInfo> & targets) = 0; |
95 | |
96 | /** |
97 | * Get block checksum (MD5 of CRC32). |
98 | * |
99 | * @param blk a block. |
100 | * @param blockToken security token for accessing the block. |
101 | * @throw HdfsIOException |
102 | */ |
103 | virtual void blockChecksum(const ExtendedBlock & blk, |
104 | const Token & blockToken) = 0; |
105 | |
106 | /** |
107 | * Request short circuit access file descriptors from a DataNode. |
108 | * |
109 | * @param blk The block to get file descriptors for. |
110 | * @param blockToken Security token for accessing the block. |
111 | * @param clientName client's name. |
112 | * @param maxVersion Maximum version of the block data the client |
113 | * can understand. |
114 | */ |
115 | virtual void requestShortCircuitFds(const ExtendedBlock blk, |
116 | const Token& blockToken, |
117 | uint32_t maxVersion) = 0; |
118 | }; |
119 | |
120 | } |
121 | } |
122 | |
123 | #endif /* _HDFS_LIBHDFS_3_CLIENT_DATATRANSFERPROTOCOL_H_ */ |
124 | |