From a2200a64175867a1c66cf8338f536ccaaaa36508 Mon Sep 17 00:00:00 2001 From: Brandon Li Date: Sat, 16 Nov 2013 00:57:26 +0000 Subject: [PATCH] HDFS-5519. COMMIT handler should update the commit status after sync. Contributed by Brandon Li git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/trunk@1542437 13f79535-47bb-0310-9956-ffa450edef68 --- .../org/apache/hadoop/hdfs/nfs/nfs3/OpenFileCtx.java | 4 +++- .../org/apache/hadoop/hdfs/nfs/nfs3/TestWrites.java | 10 ++++++++-- hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt | 3 +++ 3 files changed, 14 insertions(+), 3 deletions(-) diff --git a/hadoop-hdfs-project/hadoop-hdfs-nfs/src/main/java/org/apache/hadoop/hdfs/nfs/nfs3/OpenFileCtx.java b/hadoop-hdfs-project/hadoop-hdfs-nfs/src/main/java/org/apache/hadoop/hdfs/nfs/nfs3/OpenFileCtx.java index e999615d0e0..ce2a7d35923 100644 --- a/hadoop-hdfs-project/hadoop-hdfs-nfs/src/main/java/org/apache/hadoop/hdfs/nfs/nfs3/OpenFileCtx.java +++ b/hadoop-hdfs-project/hadoop-hdfs-nfs/src/main/java/org/apache/hadoop/hdfs/nfs/nfs3/OpenFileCtx.java @@ -726,6 +726,7 @@ public COMMIT_STATUS checkCommit(DFSClient dfsClient, long commitOffset, try { // Sync file data and length fos.hsync(EnumSet.of(SyncFlag.UPDATE_LENGTH)); + ret = COMMIT_STATUS.COMMIT_FINISHED; // Remove COMMIT_DO_SYNC status // Nothing to do for metadata since attr related change is pass-through } catch (ClosedChannelException cce) { if (pendingWrites.isEmpty()) { @@ -747,7 +748,8 @@ public COMMIT_STATUS checkCommit(DFSClient dfsClient, long commitOffset, * return one commit status: COMMIT_FINISHED, COMMIT_WAIT, * COMMIT_INACTIVE_CTX, COMMIT_INACTIVE_WITH_PENDING_WRITE, COMMIT_ERROR */ - private synchronized COMMIT_STATUS checkCommitInternal(long commitOffset, + @VisibleForTesting + synchronized COMMIT_STATUS checkCommitInternal(long commitOffset, Channel channel, int xid, Nfs3FileAttributes preOpAttr) { if (!activeState) { if (pendingWrites.isEmpty()) { diff --git a/hadoop-hdfs-project/hadoop-hdfs-nfs/src/test/java/org/apache/hadoop/hdfs/nfs/nfs3/TestWrites.java b/hadoop-hdfs-project/hadoop-hdfs-nfs/src/test/java/org/apache/hadoop/hdfs/nfs/nfs3/TestWrites.java index 1a808807f9a..d16b268382c 100644 --- a/hadoop-hdfs-project/hadoop-hdfs-nfs/src/test/java/org/apache/hadoop/hdfs/nfs/nfs3/TestWrites.java +++ b/hadoop-hdfs-project/hadoop-hdfs-nfs/src/test/java/org/apache/hadoop/hdfs/nfs/nfs3/TestWrites.java @@ -150,10 +150,16 @@ public void testCheckCommit() throws IOException { // Test request with non zero commit offset ctx.setActiveStatusForTest(true); Mockito.when(fos.getPos()).thenReturn((long) 10); + COMMIT_STATUS status = ctx.checkCommitInternal(5, null, 1, attr); + Assert.assertTrue(status == COMMIT_STATUS.COMMIT_DO_SYNC); + // Do_SYNC state will be updated to FINISHED after data sync ret = ctx.checkCommit(dfsClient, 5, null, 1, attr); - Assert.assertTrue(ret == COMMIT_STATUS.COMMIT_DO_SYNC); + Assert.assertTrue(ret == COMMIT_STATUS.COMMIT_FINISHED); + + status = ctx.checkCommitInternal(10, null, 1, attr); + Assert.assertTrue(status == COMMIT_STATUS.COMMIT_DO_SYNC); ret = ctx.checkCommit(dfsClient, 10, null, 1, attr); - Assert.assertTrue(ret == COMMIT_STATUS.COMMIT_DO_SYNC); + Assert.assertTrue(ret == COMMIT_STATUS.COMMIT_FINISHED); ConcurrentNavigableMap commits = ctx .getPendingCommitsForTest(); diff --git a/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt b/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt index 32e1df676c0..da8e28e8976 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt +++ b/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt @@ -661,6 +661,9 @@ Release 2.2.1 - UNRELEASED HDFS-5469. Add configuration property for the sub-directroy export path (brandonli) + HDFS-5519. COMMIT handler should update the commit status after sync + (brandonli) + Release 2.2.0 - 2013-10-13 INCOMPATIBLE CHANGES