Skip to content

Commit 3b8bf99

Browse files
committed
conf.xml example + added test for buffering of Fuse stream
1 parent bb19cb4 commit 3b8bf99

File tree

4 files changed

+47
-3
lines changed

4 files changed

+47
-3
lines changed

conf/core-site.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,4 +35,8 @@
3535
<value>Off</value>
3636
</property>
3737

38+
<property>
39+
<name>fs.glusterfs.write.buffer.size</name>
40+
<value>1024</value>
41+
</property>
3842
</configuration>

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

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,19 +26,24 @@ public class GlusterFUSEOutputStream extends OutputStream{
2626
long pos;
2727
boolean closed;
2828
OutputStream fuseOutputStream;
29-
29+
org.slf4j.Logger LOG = org.slf4j.LoggerFactory.getLogger(GlusterFUSEOutputStream.class);
30+
3031
public GlusterFUSEOutputStream(String file, boolean append) throws IOException{
3132
this(file,append,0);
3233
}
3334

35+
/**
36+
* @param bufferSize : Size of buffer in bytes (if 0, then no buffer will be used).
37+
*/
3438
public GlusterFUSEOutputStream(String file, boolean append, int bufferSize) throws IOException{
3539
this.f=new File(file); /* not needed ? */
3640
this.pos=0;
37-
this.fuseOutputStream=(bufferSize==0) ? new FileOutputStream(file, append) : new BufferedOutputStream(new FileOutputStream(file, append), bufferSize);
41+
fuseOutputStream=new FileOutputStream(file, append) ;
42+
if(bufferSize > 0)
43+
fuseOutputStream = new BufferedOutputStream(fuseOutputStream, bufferSize);
3844
this.closed=false;
3945
}
4046

41-
4247
public long getPos() throws IOException{
4348
return pos;
4449
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ public void initialize(URI uri,Configuration conf) throws IOException{
126126
needQuickRead=conf.get("quick.slave.io", null);
127127
autoMount=conf.getBoolean("fs.glusterfs.automount", true);
128128
writeBufferSize = conf.getInt("fs.glusterfs.write.buffer.size", 0);
129+
LOG.info("Gluster Output Buffering size configured to " + writeBufferSize + " bytes.");
129130
/*
130131
* bail out if we do not have enough information to do a FUSE mount
131132
*/
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
package org.gluster.test;
2+
3+
import java.io.File;
4+
import java.io.IOException;
5+
import java.util.TreeMap;
6+
7+
import junit.framework.Assert;
8+
9+
import org.apache.hadoop.fs.glusterfs.GlusterFSBrickClass;
10+
import org.apache.hadoop.fs.glusterfs.GlusterFUSEInputStream;
11+
import org.apache.hadoop.fs.glusterfs.GlusterFUSEOutputStream;
12+
import org.junit.Test;
13+
14+
public class TestGlusterFuseOutputStream {
15+
16+
@Test
17+
public void testOutputStream() throws IOException{
18+
File out = new File("/tmp/testGlusterFuseOutputStream");
19+
20+
//Create a 3 byte FuseOutputStream
21+
final GlusterFUSEOutputStream stream = new GlusterFUSEOutputStream(out.getAbsolutePath(), true, 3);
22+
23+
stream.write("ab".getBytes());
24+
25+
long sizeBeforeFlush = out.length();
26+
27+
stream.flush();
28+
stream.close();
29+
30+
//Confirm that the buffer held 100 bytes.
31+
Assert.assertTrue(out.length() > sizeBeforeFlush);
32+
out.delete();
33+
}
34+
}

0 commit comments

Comments
 (0)