You are viewing a plain text version of this content. The canonical link for it is here.
Posted to hdfs-commits@hadoop.apache.org by dh...@apache.org on 2011/01/04 20:10:59 UTC
svn commit: r1055142 - in /hadoop/hdfs/trunk: ./
src/java/org/apache/hadoop/hdfs/
src/java/org/apache/hadoop/hdfs/server/datanode/
src/test/hdfs/org/apache/hadoop/hdfs/
Author: dhruba
Date: Tue Jan 4 19:10:58 2011
New Revision: 1055142
URL: http://svn.apache.org/viewvc?rev=1055142&view=rev
Log:
HDFS-1539. A config option for the datanode to fsycn a block file
when block is completely written. (dhruba)
Modified:
hadoop/hdfs/trunk/CHANGES.txt
hadoop/hdfs/trunk/src/java/org/apache/hadoop/hdfs/DFSConfigKeys.java
hadoop/hdfs/trunk/src/java/org/apache/hadoop/hdfs/server/datanode/BlockReceiver.java
hadoop/hdfs/trunk/src/java/org/apache/hadoop/hdfs/server/datanode/DataNode.java
hadoop/hdfs/trunk/src/test/hdfs/org/apache/hadoop/hdfs/TestFileCreation.java
Modified: hadoop/hdfs/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/hadoop/hdfs/trunk/CHANGES.txt?rev=1055142&r1=1055141&r2=1055142&view=diff
==============================================================================
--- hadoop/hdfs/trunk/CHANGES.txt (original)
+++ hadoop/hdfs/trunk/CHANGES.txt Tue Jan 4 19:10:58 2011
@@ -30,6 +30,9 @@ Trunk (unreleased changes)
name node is in safe mode. (Patrick Kling via hairong)
HDFS-1534. Fix some incorrect logs in FSDirectory. (eli)
+
+ HDFS-1539. A config option for the datanode to fsycn a block file
+ when block is completely written. (dhruba)
OPTIMIZATIONS
Modified: hadoop/hdfs/trunk/src/java/org/apache/hadoop/hdfs/DFSConfigKeys.java
URL: http://svn.apache.org/viewvc/hadoop/hdfs/trunk/src/java/org/apache/hadoop/hdfs/DFSConfigKeys.java?rev=1055142&r1=1055141&r2=1055142&view=diff
==============================================================================
--- hadoop/hdfs/trunk/src/java/org/apache/hadoop/hdfs/DFSConfigKeys.java (original)
+++ hadoop/hdfs/trunk/src/java/org/apache/hadoop/hdfs/DFSConfigKeys.java Tue Jan 4 19:10:58 2011
@@ -105,6 +105,8 @@ public class DFSConfigKeys extends Commo
public static final int DFS_LIST_LIMIT_DEFAULT = 1000;
public static final String DFS_DATANODE_FAILED_VOLUMES_TOLERATED_KEY = "dfs.datanode.failed.volumes.tolerated";
public static final int DFS_DATANODE_FAILED_VOLUMES_TOLERATED_DEFAULT = 0;
+ public static final String DFS_DATANODE_SYNCONCLOSE_KEY = "dfs.datanode.synconclose";
+ public static final boolean DFS_DATANODE_SYNCONCLOSE_DEFAULT = false;
//Delegation token related keys
public static final String DFS_NAMENODE_DELEGATION_KEY_UPDATE_INTERVAL_KEY = "dfs.namenode.delegation.key.update-interval";
Modified: hadoop/hdfs/trunk/src/java/org/apache/hadoop/hdfs/server/datanode/BlockReceiver.java
URL: http://svn.apache.org/viewvc/hadoop/hdfs/trunk/src/java/org/apache/hadoop/hdfs/server/datanode/BlockReceiver.java?rev=1055142&r1=1055141&r2=1055142&view=diff
==============================================================================
--- hadoop/hdfs/trunk/src/java/org/apache/hadoop/hdfs/server/datanode/BlockReceiver.java (original)
+++ hadoop/hdfs/trunk/src/java/org/apache/hadoop/hdfs/server/datanode/BlockReceiver.java Tue Jan 4 19:10:58 2011
@@ -25,6 +25,7 @@ import java.io.BufferedOutputStream;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.EOFException;
+import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.nio.ByteBuffer;
@@ -61,6 +62,7 @@ class BlockReceiver implements java.io.C
private DataInputStream in = null; // from where data are read
private DataChecksum checksum; // from where chunks of a block can be read
private OutputStream out = null; // to block file at local disk
+ private OutputStream cout = null; // output stream for cehcksum file
private DataOutputStream checksumOut = null; // to crc file at local disk
private int bytesPerChecksum;
private int checksumSize;
@@ -138,10 +140,10 @@ class BlockReceiver implements java.io.C
this.bytesPerChecksum, this.checksumSize);
if (streams != null) {
this.out = streams.dataOut;
+ this.cout = streams.checksumOut;
this.checksumOut = new DataOutputStream(new BufferedOutputStream(
- streams.checksumOut,
+ streams.checksumOut,
SMALL_BUFFER_SIZE));
-
// write data chunk header if creating a new replica
if (isCreate) {
BlockMetadataHeader.writeHeader(checksumOut, checksum);
@@ -182,6 +184,9 @@ class BlockReceiver implements java.io.C
try {
if (checksumOut != null) {
checksumOut.flush();
+ if (datanode.syncOnClose && (cout instanceof FileOutputStream)) {
+ ((FileOutputStream)cout).getChannel().force(true);
+ }
checksumOut.close();
checksumOut = null;
}
@@ -192,6 +197,9 @@ class BlockReceiver implements java.io.C
try {
if (out != null) {
out.flush();
+ if (datanode.syncOnClose && (out instanceof FileOutputStream)) {
+ ((FileOutputStream)out).getChannel().force(true);
+ }
out.close();
out = null;
}
Modified: hadoop/hdfs/trunk/src/java/org/apache/hadoop/hdfs/server/datanode/DataNode.java
URL: http://svn.apache.org/viewvc/hadoop/hdfs/trunk/src/java/org/apache/hadoop/hdfs/server/datanode/DataNode.java?rev=1055142&r1=1055141&r2=1055142&view=diff
==============================================================================
--- hadoop/hdfs/trunk/src/java/org/apache/hadoop/hdfs/server/datanode/DataNode.java (original)
+++ hadoop/hdfs/trunk/src/java/org/apache/hadoop/hdfs/server/datanode/DataNode.java Tue Jan 4 19:10:58 2011
@@ -230,6 +230,7 @@ public class DataNode extends Configured
boolean isBlockTokenEnabled;
BlockTokenSecretManager blockTokenSecretManager;
boolean isBlockTokenInitialized = false;
+ boolean syncOnClose;
public DataBlockScanner blockScanner = null;
public Daemon blockScannerThread = null;
@@ -319,6 +320,10 @@ public class DataNode extends Configured
"dfs.blockreport.intervalMsec." + " Setting initial delay to 0 msec:");
}
this.heartBeatInterval = conf.getLong("dfs.heartbeat.interval", HEARTBEAT_INTERVAL) * 1000L;
+
+ // do we need to sync block file contents to disk when blockfile is closed?
+ this.syncOnClose = conf.getBoolean(DFSConfigKeys.DFS_DATANODE_SYNCONCLOSE_KEY,
+ DFSConfigKeys.DFS_DATANODE_SYNCONCLOSE_DEFAULT);
}
private void startInfoServer(Configuration conf) throws IOException {
Modified: hadoop/hdfs/trunk/src/test/hdfs/org/apache/hadoop/hdfs/TestFileCreation.java
URL: http://svn.apache.org/viewvc/hadoop/hdfs/trunk/src/test/hdfs/org/apache/hadoop/hdfs/TestFileCreation.java?rev=1055142&r1=1055141&r2=1055142&view=diff
==============================================================================
--- hadoop/hdfs/trunk/src/test/hdfs/org/apache/hadoop/hdfs/TestFileCreation.java (original)
+++ hadoop/hdfs/trunk/src/test/hdfs/org/apache/hadoop/hdfs/TestFileCreation.java Tue Jan 4 19:10:58 2011
@@ -720,6 +720,39 @@ public class TestFileCreation extends ju
}
/**
+ * Test creating a file whose data gets sync when closed
+ */
+ public void testFileCreationSyncOnClose() throws IOException {
+ Configuration conf = new HdfsConfiguration();
+ conf.setBoolean(DFSConfigKeys.DFS_DATANODE_SYNCONCLOSE_KEY, true);
+ MiniDFSCluster cluster = new MiniDFSCluster.Builder(conf).build();
+
+ try {
+ FileSystem fs = cluster.getFileSystem();
+
+ Path[] p = {new Path("/foo"), new Path("/bar")};
+
+ //write 2 files at the same time
+ FSDataOutputStream[] out = {fs.create(p[0]), fs.create(p[1])};
+ int i = 0;
+ for(; i < 100; i++) {
+ out[0].write(i);
+ out[1].write(i);
+ }
+ out[0].close();
+ for(; i < 200; i++) {out[1].write(i);}
+ out[1].close();
+
+ //verify
+ FSDataInputStream[] in = {fs.open(p[0]), fs.open(p[1])};
+ for(i = 0; i < 100; i++) {assertEquals(i, in[0].read());}
+ for(i = 0; i < 200; i++) {assertEquals(i, in[1].read());}
+ } finally {
+ if (cluster != null) {cluster.shutdown();}
+ }
+ }
+
+ /**
* Create a file, write something, hflush but not close.
* Then change lease period and wait for lease recovery.
* Finally, read the block directly from each Datanode and verify the content.