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 br...@apache.org on 2013/12/17 21:40:16 UTC
svn commit: r1551691 - in /hadoop/common/trunk/hadoop-hdfs-project:
hadoop-hdfs-nfs/src/main/java/org/apache/hadoop/hdfs/nfs/nfs3/OpenFileCtx.java
hadoop-hdfs/CHANGES.txt
Author: brandonli
Date: Tue Dec 17 20:40:15 2013
New Revision: 1551691
URL: http://svn.apache.org/r1551691
Log:
HDFS-5657. race condition causes writeback state error in NFS gateway. Contributed by Brandon Li
Modified:
hadoop/common/trunk/hadoop-hdfs-project/hadoop-hdfs-nfs/src/main/java/org/apache/hadoop/hdfs/nfs/nfs3/OpenFileCtx.java
hadoop/common/trunk/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt
Modified: hadoop/common/trunk/hadoop-hdfs-project/hadoop-hdfs-nfs/src/main/java/org/apache/hadoop/hdfs/nfs/nfs3/OpenFileCtx.java
URL: http://svn.apache.org/viewvc/hadoop/common/trunk/hadoop-hdfs-project/hadoop-hdfs-nfs/src/main/java/org/apache/hadoop/hdfs/nfs/nfs3/OpenFileCtx.java?rev=1551691&r1=1551690&r2=1551691&view=diff
==============================================================================
--- hadoop/common/trunk/hadoop-hdfs-project/hadoop-hdfs-nfs/src/main/java/org/apache/hadoop/hdfs/nfs/nfs3/OpenFileCtx.java (original)
+++ hadoop/common/trunk/hadoop-hdfs-project/hadoop-hdfs-nfs/src/main/java/org/apache/hadoop/hdfs/nfs/nfs3/OpenFileCtx.java Tue Dec 17 20:40:15 2013
@@ -85,6 +85,7 @@ class OpenFileCtx {
private volatile boolean activeState;
// The stream write-back status. True means one thread is doing write back.
private volatile boolean asyncStatus;
+ private volatile long asyncWriteBackStartOffset;
/**
* The current offset of the file in HDFS. All the content before this offset
@@ -209,6 +210,7 @@ class OpenFileCtx {
updateLastAccessTime();
activeState = true;
asyncStatus = false;
+ asyncWriteBackStartOffset = 0;
dumpOut = null;
raf = null;
nonSequentialWriteInMemory = new AtomicLong(0);
@@ -580,6 +582,7 @@ class OpenFileCtx {
+ nextOffset.get());
}
asyncStatus = true;
+ asyncWriteBackStartOffset = writeCtx.getOffset();
asyncDataService.execute(new AsyncDataService.WriteBackTask(this));
} else {
if (LOG.isDebugEnabled()) {
@@ -903,9 +906,11 @@ class OpenFileCtx {
/** Invoked by AsynDataService to write back to HDFS */
void executeWriteBack() {
Preconditions.checkState(asyncStatus,
- "The openFileCtx has false async status");
+ "openFileCtx has false asyncStatus, fileId:" + latestAttr.getFileid());
+ final long startOffset = asyncWriteBackStartOffset;
try {
while (activeState) {
+ // asyncStatus could be changed to false in offerNextToWrite()
WriteCtx toWrite = offerNextToWrite();
if (toWrite != null) {
// Do the write
@@ -921,8 +926,18 @@ class OpenFileCtx {
+ latestAttr.getFileId());
}
} finally {
- // make sure we reset asyncStatus to false
- asyncStatus = false;
+ // Make sure to reset asyncStatus to false unless a race happens
+ synchronized (this) {
+ if (startOffset == asyncWriteBackStartOffset) {
+ asyncStatus = false;
+ } else {
+ LOG.info("Another asyn task is already started before this one"
+ + " is finalized. fileId:" + latestAttr.getFileid()
+ + " asyncStatus:" + asyncStatus + " original startOffset:"
+ + startOffset + " new startOffset:" + asyncWriteBackStartOffset
+ + ". Won't change asyncStatus here.");
+ }
+ }
}
}
@@ -1177,4 +1192,4 @@ class OpenFileCtx {
return String.format("activeState: %b asyncStatus: %b nextOffset: %d",
activeState, asyncStatus, nextOffset.get());
}
-}
\ No newline at end of file
+}
Modified: hadoop/common/trunk/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt
URL: http://svn.apache.org/viewvc/hadoop/common/trunk/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt?rev=1551691&r1=1551690&r2=1551691&view=diff
==============================================================================
--- hadoop/common/trunk/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt (original)
+++ hadoop/common/trunk/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt Tue Dec 17 20:40:15 2013
@@ -976,6 +976,8 @@ Release 2.3.0 - UNRELEASED
HDFS-4201. NPE in BPServiceActor#sendHeartBeat. (jxiang via cmccabe)
HDFS-5666. Fix inconsistent synchronization in BPOfferService (jxiang via cmccabe)
+
+ HDFS-5657. race condition causes writeback state error in NFS gateway (brandonli)
Release 2.2.0 - 2013-10-13