47
47
* This package provides interface for hadoop jobs (incl. Map/Reduce)
48
48
* to access files in GlusterFS backed file system via FUSE mount
49
49
*/
50
+
51
+
52
+ /*
53
+ *
54
+ * TODO: Evaluate LocalFileSystem and RawLocalFileSystem as possible delegate file systems to remove & refactor this code.
55
+ *
56
+ */
50
57
public class GlusterFileSystem extends FileSystem {
51
58
52
59
private FileSystem glusterFs = null ;
@@ -101,6 +108,7 @@ public void initialize(URI uri, Configuration conf) throws IOException {
101
108
String volName = null ;
102
109
String remoteGFSServer = null ;
103
110
String needQuickRead = null ;
111
+ boolean autoMount = true ;
104
112
105
113
if (this .mounted )
106
114
return ;
@@ -112,6 +120,7 @@ public void initialize(URI uri, Configuration conf) throws IOException {
112
120
glusterMount = conf .get ("fs.glusterfs.mount" , null );
113
121
remoteGFSServer = conf .get ("fs.glusterfs.server" , null );
114
122
needQuickRead = conf .get ("quick.slave.io" , null );
123
+ autoMount = conf .getBoolean ("fs.glusterfs.automount" , true );
115
124
116
125
/*
117
126
* 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 {
124
133
+ ",glustermount=" + glusterMount );
125
134
126
135
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" )
133
148
|| needQuickRead .equalsIgnoreCase ("on" ) || needQuickRead
134
149
.equals ("1" )))
135
150
this .quickSlaveIO = true ;
@@ -184,19 +199,22 @@ public boolean exists(Path path) throws IOException {
184
199
return f .exists ();
185
200
}
186
201
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
+ }
200
218
201
219
@ Deprecated
202
220
public boolean isDirectory (Path path ) throws IOException {
@@ -403,9 +421,10 @@ public FileStatus getFileStatus(Path path) throws IOException {
403
421
* is an instance of OutputStream class.
404
422
*/
405
423
public FSDataOutputStream create (Path path , FsPermission permission ,
406
- boolean overwrite , int bufferSize , short replication ,
424
+ boolean overwrite , int bufferSize , short replication ,
407
425
long blockSize , Progressable progress ) throws IOException {
408
- Path absolute = makeAbsolute (path );
426
+
427
+ Path absolute = makeAbsolute (path );
409
428
Path parent = null ;
410
429
File f = null ;
411
430
File fParent = null ;
@@ -421,32 +440,9 @@ public FSDataOutputStream create(Path path, FsPermission permission,
421
440
}
422
441
423
442
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 );
447
444
448
- glusterFileStream = new FSDataOutputStream (new GlusterFUSEOutputStream (
449
- f .getPath (), false ));
445
+ glusterFileStream = new FSDataOutputStream (new GlusterFUSEOutputStream (f .getPath (), false ));
450
446
451
447
return glusterFileStream ;
452
448
}
0 commit comments