Skip to content

Commit 904c19f

Browse files
committed
merge with other pul reqs
2 parents 64adf37 + 69746e3 commit 904c19f

File tree

2 files changed

+50
-47
lines changed

2 files changed

+50
-47
lines changed

pom.xml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,15 @@
44
<groupId>org.apache.hadoop.fs.glusterfs</groupId>
55
<artifactId>glusterfs</artifactId>
66
<packaging>jar</packaging>
7-
<version>0.20.2-0.1</version>
7+
<version>0.20.2-0.1-SNAPSHOT</version>
88
<name>glusterfs</name>
99
<url>http://maven.apache.org</url>
10+
11+
<!-- Used for formatting the jar with timestamp -->
12+
<properties>
13+
<maven.build.timestamp.format>yyyyMMdd-HHmm</maven.build.timestamp.format>
14+
</properties>
15+
1016
<dependencies>
1117
<dependency>
1218
<groupId>junit</groupId>
@@ -20,6 +26,7 @@
2026
</dependency>
2127
</dependencies>
2228
<build>
29+
<finalName>${project.artifactId}-${project.version}-${maven.build.timestamp}</finalName>
2330
<plugins>
2431
<plugin>
2532
<groupId>org.apache.maven.plugins</groupId>

src/main/java/org/apache/hadoop/fs/glusterfs/GlusterFileSystem.java

Lines changed: 42 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,13 @@
4747
* This package provides interface for hadoop jobs (incl. Map/Reduce)
4848
* to access files in GlusterFS backed file system via FUSE mount
4949
*/
50+
51+
52+
/*
53+
*
54+
* TODO: Evaluate LocalFileSystem and RawLocalFileSystem as possible delegate file systems to remove & refactor this code.
55+
*
56+
*/
5057
public class GlusterFileSystem extends FileSystem {
5158

5259
private FileSystem glusterFs = null;
@@ -101,6 +108,7 @@ public void initialize(URI uri, Configuration conf) throws IOException {
101108
String volName = null;
102109
String remoteGFSServer = null;
103110
String needQuickRead = null;
111+
boolean autoMount = true;
104112

105113
if (this.mounted)
106114
return;
@@ -112,6 +120,7 @@ public void initialize(URI uri, Configuration conf) throws IOException {
112120
glusterMount = conf.get("fs.glusterfs.mount", null);
113121
remoteGFSServer = conf.get("fs.glusterfs.server", null);
114122
needQuickRead = conf.get("quick.slave.io", null);
123+
autoMount = conf.getBoolean("fs.glusterfs.automount", true);
115124

116125
/*
117126
* bail out if we do not have enough information to do a FUSE mount
@@ -124,12 +133,18 @@ public void initialize(URI uri, Configuration conf) throws IOException {
124133
+ ",glustermount=" + glusterMount);
125134

126135
ret = FUSEMount(volName, remoteGFSServer, glusterMount);
127-
if (!ret) {
128-
throw new RuntimeException("Failed to init Gluster FS");
129-
}
130-
131-
if((needQuickRead.length() != 0)
132-
&& (needQuickRead.equalsIgnoreCase("yes")
136+
137+
if (!ret) {
138+
throw new RuntimeException("Failed to init Gluster FS");
139+
}
140+
if (autoMount) {
141+
ret = FUSEMount(volName, remoteGFSServer, glusterMount);
142+
if (!ret) {
143+
throw new RuntimeException("Initialize: Failed to mount GlusterFS ");
144+
}
145+
}
146+
if((needQuickRead.length() != 0)
147+
&& (needQuickRead.equalsIgnoreCase("yes")
133148
|| needQuickRead.equalsIgnoreCase("on") || needQuickRead
134149
.equals("1")))
135150
this.quickSlaveIO = true;
@@ -184,19 +199,22 @@ public boolean exists(Path path) throws IOException {
184199
return f.exists();
185200
}
186201

187-
public boolean mkdirs(Path path, FsPermission permission)
188-
throws IOException {
189-
boolean created = false;
190-
Path absolute = makeAbsolute(path);
191-
File f = new File(absolute.toUri().getPath());
192-
193-
if (f.exists()) {
194-
System.out.println("Directory " + f.getPath() + " already exist");
195-
return true;
196-
}
197-
198-
return f.mkdirs();
199-
}
202+
/*
203+
* Code copied from:
204+
* @see org.apache.hadoop.fs.RawLocalFileSystem#mkdirs(org.apache.hadoop.fs.Path)
205+
* as incremental fix towards a re-write. of this class to remove duplicity.
206+
*
207+
*/
208+
public boolean mkdirs(Path f, FsPermission permission) throws IOException {
209+
210+
if(f==null)
211+
return true;
212+
213+
Path parent = f.getParent();
214+
Path absolute = makeAbsolute(f);
215+
File p2f = new File(absolute.toUri().getPath());
216+
return (f == null || mkdirs(parent)) && (p2f.mkdir() || p2f.isDirectory());
217+
}
200218

201219
@Deprecated
202220
public boolean isDirectory(Path path) throws IOException {
@@ -403,9 +421,10 @@ public FileStatus getFileStatus(Path path) throws IOException {
403421
* is an instance of OutputStream class.
404422
*/
405423
public FSDataOutputStream create(Path path, FsPermission permission,
406-
boolean overwrite, int bufferSize, short replication,
424+
boolean overwrite, int bufferSize, short replication,
407425
long blockSize, Progressable progress) throws IOException {
408-
Path absolute = makeAbsolute(path);
426+
427+
Path absolute = makeAbsolute(path);
409428
Path parent = null;
410429
File f = null;
411430
File fParent = null;
@@ -421,32 +440,9 @@ public FSDataOutputStream create(Path path, FsPermission permission,
421440
}
422441

423442
parent = path.getParent();
424-
fParent = new File((makeAbsolute(parent)).toUri().getPath());
425-
if ((parent != null) && (fParent != null) && (!fParent.exists())) {
426-
if (!fParent.mkdirs()) {
427-
//
428-
// File.mkdirs() is not multi-process safe. It is possible for
429-
// a peer who is running mkdirs() to cause us to fail. In such
430-
// a case, a rudimentary test is to try our exists() test for a
431-
// second time. The isDirectory() protects us from exists()
432-
// passing when a file is put in place of the directory we were
433-
// trying to create. We can be fooled by a directory, or set of
434-
// directories in the path, being owned by another user or with
435-
// incompatible permissions.
436-
//
437-
// This could be slightly improved to retry the mkdirs(), which
438-
// would cover races deep within the fParent's path. Each
439-
// iteration will address one race.
440-
//
441-
if (!fParent.exists() || !fParent.isDirectory()) {
442-
throw new IOException("cannot create parent directory: "
443-
+ fParent.getPath());
444-
}
445-
}
446-
}
443+
mkdirs(parent);
447444

448-
glusterFileStream = new FSDataOutputStream(new GlusterFUSEOutputStream(
449-
f.getPath(), false));
445+
glusterFileStream = new FSDataOutputStream(new GlusterFUSEOutputStream(f.getPath(), false));
450446

451447
return glusterFileStream;
452448
}

0 commit comments

Comments
 (0)