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_NAMENODEPROXY_H_ |
29 | #define _HDFS_LIBHDFS3_SERVER_NAMENODEPROXY_H_ |
30 | |
31 | #include "Memory.h" |
32 | #include "Namenode.h" |
33 | #include "NamenodeInfo.h" |
34 | #include "Thread.h" |
35 | |
36 | namespace Hdfs { |
37 | namespace Internal { |
38 | |
39 | class NamenodeProxy: public Namenode { |
40 | public: |
41 | NamenodeProxy(const std::vector<NamenodeInfo> & namenodeInfos, const std::string & tokenService, |
42 | const SessionConfig & c, const RpcAuth & a); |
43 | ~NamenodeProxy(); |
44 | |
45 | public: |
46 | |
47 | void getBlockLocations(const std::string & src, int64_t offset, |
48 | int64_t length, LocatedBlocks & lbs); |
49 | |
50 | void create(const std::string & src, const Permission & masked, |
51 | const std::string & clientName, int flag, bool createParent, |
52 | short replication, int64_t blockSize); |
53 | |
54 | std::pair<shared_ptr<LocatedBlock>, shared_ptr<FileStatus> > append( |
55 | const std::string& src, const std::string& clientName); |
56 | |
57 | bool setReplication(const std::string & src, short replication); |
58 | |
59 | void setPermission(const std::string & src, const Permission & permission); |
60 | |
61 | void setOwner(const std::string & src, const std::string & username, |
62 | const std::string & groupname); |
63 | |
64 | void abandonBlock(const ExtendedBlock & b, const std::string & src, |
65 | const std::string & holder); |
66 | |
67 | shared_ptr<LocatedBlock> addBlock(const std::string & src, |
68 | const std::string & clientName, const ExtendedBlock * previous, |
69 | const std::vector<DatanodeInfo> & excludeNodes); |
70 | |
71 | shared_ptr<LocatedBlock> getAdditionalDatanode(const std::string & src, |
72 | const ExtendedBlock & blk, |
73 | const std::vector<DatanodeInfo> & existings, |
74 | const std::vector<std::string> & storageIDs, |
75 | const std::vector<DatanodeInfo> & excludes, int numAdditionalNodes, |
76 | const std::string & clientName); |
77 | |
78 | bool complete(const std::string & src, const std::string & clientName, |
79 | const ExtendedBlock * last); |
80 | |
81 | void reportBadBlocks(const std::vector<LocatedBlock> & blocks); |
82 | |
83 | bool rename(const std::string & src, const std::string & dst); |
84 | |
85 | void concat(const std::string & trg, const std::vector<std::string> & srcs); |
86 | |
87 | bool truncate(const std::string & src, int64_t size, |
88 | const std::string & clientName); |
89 | |
90 | void getLease(const std::string & src, const std::string & clientName); |
91 | |
92 | void releaseLease(const std::string & src, const std::string & clientName); |
93 | |
94 | /*void rename2(const std::string & src, const std::string & dst) |
95 | throw (AccessControlException, DSQuotaExceededException, |
96 | FileAlreadyExistsException, FileNotFoundException, |
97 | NSQuotaExceededException, ParentNotDirectoryException, |
98 | SafeModeException, UnresolvedLinkException, HdfsIOException) ;*/ |
99 | |
100 | bool deleteFile(const std::string & src, bool recursive); |
101 | |
102 | bool mkdirs(const std::string & src, const Permission & masked, |
103 | bool createParent); |
104 | |
105 | bool getListing(const std::string & src, const std::string & startAfter, |
106 | bool needLocation, std::vector<FileStatus> & dl); |
107 | |
108 | void renewLease(const std::string & clientName); |
109 | |
110 | bool recoverLease(const std::string & src, const std::string & clientName); |
111 | |
112 | std::vector<int64_t> getFsStats(); |
113 | |
114 | void metaSave(const std::string & filename); |
115 | |
116 | FileStatus getFileInfo(const std::string & src); |
117 | |
118 | FileStatus getFileLinkInfo(const std::string & src); |
119 | |
120 | void setQuota(const std::string & path, int64_t namespaceQuota, |
121 | int64_t diskspaceQuota); |
122 | |
123 | void fsync(const std::string & src, const std::string & client); |
124 | |
125 | void setTimes(const std::string & src, int64_t mtime, int64_t atime); |
126 | |
127 | void createSymlink(const std::string & target, const std::string & link, |
128 | const Permission & dirPerm, bool createParent); |
129 | |
130 | std::string getLinkTarget(const std::string & path); |
131 | |
132 | shared_ptr<LocatedBlock> updateBlockForPipeline(const ExtendedBlock & block, |
133 | const std::string & clientName); |
134 | |
135 | void updatePipeline(const std::string & clientName, |
136 | const ExtendedBlock & oldBlock, const ExtendedBlock & newBlock, |
137 | const std::vector<DatanodeInfo> & newNodes, |
138 | const std::vector<std::string> & storageIDs); |
139 | |
140 | Token getDelegationToken(const std::string & renewer); |
141 | |
142 | int64_t renewDelegationToken(const Token & token); |
143 | |
144 | void cancelDelegationToken(const Token & token); |
145 | |
146 | void close(); |
147 | |
148 | private: |
149 | shared_ptr<Namenode> getActiveNamenode(uint32_t & oldValue); |
150 | void failoverToNextNamenode(uint32_t oldValue); |
151 | |
152 | private: |
153 | bool enableNamenodeHA; |
154 | int maxNamenodeHARetry; |
155 | mutex mut; |
156 | std::string clusterid; |
157 | std::vector<shared_ptr<Namenode> > namenodes; |
158 | uint32_t currentNamenode; |
159 | }; |
160 | |
161 | } |
162 | } |
163 | |
164 | #endif /* _HDFS_LIBHDFS3_SERVER_NAMENODEPROXY_H_ */ |
165 | |