Skip to content

Commit eb184f6

Browse files
Merge branch 'hdfs-merge-HDFS-16024' into 'branch-3.3.2-bzl-hdfs-merge'
HDFS-16024: RBF: Rename data to the Trash should be based on src locations See merge request dap/hadoop!101
2 parents bfca623 + 122e5b6 commit eb184f6

File tree

8 files changed

+791
-110
lines changed

8 files changed

+791
-110
lines changed

hadoop-hdfs-project/hadoop-hdfs-rbf/src/main/java/org/apache/hadoop/hdfs/server/federation/resolver/FileSubclusterResolver.java

Lines changed: 123 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,17 @@
1919
package org.apache.hadoop.hdfs.server.federation.resolver;
2020

2121
import java.io.IOException;
22+
import java.util.Collection;
23+
import java.util.IdentityHashMap;
24+
import java.util.LinkedList;
2225
import java.util.List;
23-
26+
import java.util.Set;
27+
import java.util.SortedMap;
28+
import java.util.TreeSet;
2429
import org.apache.hadoop.classification.InterfaceAudience;
2530
import org.apache.hadoop.classification.InterfaceStability;
31+
import org.apache.hadoop.fs.Path;
32+
import org.apache.hadoop.hdfs.server.federation.store.records.MountTable;
2633

2734
/**
2835
* Interface to map a file path in the global name space to a specific
@@ -69,10 +76,125 @@ public interface FileSubclusterResolver {
6976
*/
7077
List<String> getMountPoints(String path) throws IOException;
7178

79+
/**
80+
* Get a IdentityHashMap (child, mountTable source path) of mount points for a path.
81+
* Results are from the mount table cache.
82+
*
83+
* @param path Path to get the mount points under.
84+
* @return IdentityHashMap of mount points present at this path. Return zero-length
85+
* IdentityHashMap if the path is a mount point but there are no mount points
86+
* under the path. Return null if the path is not a mount point
87+
* and there are no mount points under the path.
88+
* @throws IOException Throws exception if the data is not available.
89+
*/
90+
IdentityHashMap<String,String> getMountPointsWithSrc(String path) throws IOException;
91+
92+
7293
/**
7394
* Get the default namespace for the cluster.
7495
*
7596
* @return Default namespace identifier.
7697
*/
7798
String getDefaultNamespace();
99+
100+
/**
101+
* Get the all namespace which has mountpoints for the cluster.
102+
*
103+
* @return a set of namespace identifiers.
104+
*/
105+
Set<String> getAllNamespaces();
106+
107+
/**
108+
* Get a list of mount points for a path.
109+
*
110+
* @param path Path to get the mount points under.
111+
* @param mountPoints the mount points to choose.
112+
* @return Return empty list if the path is a mount point but there are no
113+
* mount points under the path. Return null if the path is not a mount
114+
* point and there are no mount points under the path.
115+
*/
116+
static List<String> getMountPoints(String path,
117+
Collection<String> mountPoints) {
118+
Set<String> children = new TreeSet<>();
119+
boolean exists = false;
120+
for (String subPath : mountPoints) {
121+
String child = subPath;
122+
123+
// Special case for /
124+
if (!path.equals(Path.SEPARATOR)) {
125+
// Get the children
126+
int ini = path.length();
127+
child = subPath.substring(ini);
128+
}
129+
130+
if (child.isEmpty()) {
131+
// This is a mount point but without children
132+
exists = true;
133+
} else if (child.startsWith(Path.SEPARATOR)) {
134+
// This is a mount point with children
135+
exists = true;
136+
child = child.substring(1);
137+
138+
// We only return immediate children
139+
int fin = child.indexOf(Path.SEPARATOR);
140+
if (fin > -1) {
141+
child = child.substring(0, fin);
142+
}
143+
if (!child.isEmpty()) {
144+
children.add(child);
145+
}
146+
}
147+
}
148+
if (!exists) {
149+
return null;
150+
}
151+
return new LinkedList<>(children);
152+
}
153+
154+
/**
155+
* Get a IdentityHashMap (child, mountTable source path) for a path. The child can be repetitive.
156+
*
157+
* @param path Path to get the mount points under.
158+
* @param tree the mount points tree.
159+
* @return Return empty IdentityHashMap if the path is a mount point but there are no
160+
* mount points under the path. Return null if the path is not a mount
161+
* point and there are no mount points under the path.
162+
*/
163+
static IdentityHashMap<String,String> getMountPointsWithSrc(String path, SortedMap<String,
164+
MountTable> tree) {
165+
IdentityHashMap<String,String> childWithSourcePaths = new IdentityHashMap<>();
166+
boolean exists = false;
167+
for (String subPath : tree.keySet()) {
168+
String child = subPath;
169+
170+
// Special case for /
171+
if (!path.equals(Path.SEPARATOR)) {
172+
// Get the children
173+
int ini = path.length();
174+
child = subPath.substring(ini);
175+
}
176+
177+
if (child.isEmpty()) {
178+
// This is a mount point but without children
179+
exists = true;
180+
} else if (child.startsWith(Path.SEPARATOR)) {
181+
// This is a mount point with children
182+
exists = true;
183+
child = child.substring(1);
184+
185+
// We only return immediate children
186+
int fin = child.indexOf(Path.SEPARATOR);
187+
if (fin > -1) {
188+
child = child.substring(0, fin);
189+
}
190+
if (!child.isEmpty()) {
191+
childWithSourcePaths.put(child, tree.get(subPath).getSourcePath());
192+
}
193+
}
194+
}
195+
if (!exists) {
196+
return null;
197+
}
198+
return childWithSourcePaths;
199+
}
78200
}

0 commit comments

Comments
 (0)