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_LIBHDFS3_SERVER_LOCATEDBLOCK_H_ |
29 | #define _HDFS_LIBHDFS3_SERVER_LOCATEDBLOCK_H_ |
30 | |
31 | #include "client/Token.h" |
32 | #include "DatanodeInfo.h" |
33 | #include "ExtendedBlock.h" |
34 | |
35 | #include <vector> |
36 | |
37 | namespace Hdfs { |
38 | namespace Internal { |
39 | |
40 | /** |
41 | * Associates a block with the Datanodes that contain its replicas |
42 | * and other block metadata (E.g. the file offset associated with this |
43 | * block, whether it is corrupt, security token, etc). |
44 | */ |
45 | class LocatedBlock: public ExtendedBlock { |
46 | public: |
47 | LocatedBlock() : |
48 | offset(0), corrupt(false) { |
49 | } |
50 | |
51 | LocatedBlock(int64_t position) : |
52 | offset(position), corrupt(false) { |
53 | } |
54 | |
55 | bool isCorrupt() const { |
56 | return corrupt; |
57 | } |
58 | |
59 | void setCorrupt(bool corrupt) { |
60 | this->corrupt = corrupt; |
61 | } |
62 | |
63 | const std::vector<DatanodeInfo> & getLocations() const { |
64 | return locs; |
65 | } |
66 | |
67 | std::vector<DatanodeInfo> & mutableLocations() { |
68 | return locs; |
69 | } |
70 | |
71 | void setLocations(const std::vector<DatanodeInfo> & locs) { |
72 | this->locs = locs; |
73 | } |
74 | |
75 | int64_t getOffset() const { |
76 | return offset; |
77 | } |
78 | |
79 | void setOffset(int64_t offset) { |
80 | this->offset = offset; |
81 | } |
82 | |
83 | const Token & getToken() const { |
84 | return token; |
85 | } |
86 | |
87 | void setToken(const Token & token) { |
88 | this->token = token; |
89 | } |
90 | |
91 | bool operator <(const LocatedBlock & that) const { |
92 | return this->offset < that.offset; |
93 | } |
94 | |
95 | const std::vector<std::string> & getStorageIDs() const { |
96 | return storageIDs; |
97 | } |
98 | |
99 | std::vector<std::string> & mutableStorageIDs() { |
100 | return storageIDs; |
101 | } |
102 | |
103 | void setStorageIDs(const std::vector<std::string>& sid) { |
104 | this->storageIDs = sid; |
105 | } |
106 | |
107 | private: |
108 | int64_t offset; |
109 | bool corrupt; |
110 | std::vector<DatanodeInfo> locs; |
111 | std::vector<std::string> storageIDs; |
112 | Token token; |
113 | }; |
114 | |
115 | } |
116 | } |
117 | |
118 | #endif /* _HDFS_LIBHDFS3_SERVER_LOCATEDBLOCK_H_ */ |
119 | |