|
@@ -138,8 +138,10 @@ public class TestWrites {
|
|
HdfsDataOutputStream fos = Mockito.mock(HdfsDataOutputStream.class);
|
|
HdfsDataOutputStream fos = Mockito.mock(HdfsDataOutputStream.class);
|
|
Mockito.when(fos.getPos()).thenReturn((long) 0);
|
|
Mockito.when(fos.getPos()).thenReturn((long) 0);
|
|
|
|
|
|
|
|
+ NfsConfiguration conf = new NfsConfiguration();
|
|
|
|
+ conf.setBoolean(NfsConfigKeys.LARGE_FILE_UPLOAD, false);
|
|
OpenFileCtx ctx = new OpenFileCtx(fos, attr, "/dumpFilePath", dfsClient,
|
|
OpenFileCtx ctx = new OpenFileCtx(fos, attr, "/dumpFilePath", dfsClient,
|
|
- new IdUserGroup(new NfsConfiguration()));
|
|
|
|
|
|
+ new IdUserGroup(conf), false, conf);
|
|
|
|
|
|
COMMIT_STATUS ret;
|
|
COMMIT_STATUS ret;
|
|
|
|
|
|
@@ -157,6 +159,7 @@ public class TestWrites {
|
|
// Test request with non zero commit offset
|
|
// Test request with non zero commit offset
|
|
ctx.setActiveStatusForTest(true);
|
|
ctx.setActiveStatusForTest(true);
|
|
Mockito.when(fos.getPos()).thenReturn((long) 10);
|
|
Mockito.when(fos.getPos()).thenReturn((long) 10);
|
|
|
|
+ ctx.setNextOffsetForTest(10);
|
|
COMMIT_STATUS status = ctx.checkCommitInternal(5, null, 1, attr, false);
|
|
COMMIT_STATUS status = ctx.checkCommitInternal(5, null, 1, attr, false);
|
|
Assert.assertTrue(status == COMMIT_STATUS.COMMIT_DO_SYNC);
|
|
Assert.assertTrue(status == COMMIT_STATUS.COMMIT_DO_SYNC);
|
|
// Do_SYNC state will be updated to FINISHED after data sync
|
|
// Do_SYNC state will be updated to FINISHED after data sync
|
|
@@ -192,15 +195,85 @@ public class TestWrites {
|
|
Assert.assertTrue(ret == COMMIT_STATUS.COMMIT_FINISHED);
|
|
Assert.assertTrue(ret == COMMIT_STATUS.COMMIT_FINISHED);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ @Test
|
|
|
|
+ // Validate all the commit check return codes OpenFileCtx.COMMIT_STATUS with
|
|
|
|
+ // large file upload option.
|
|
|
|
+ public void testCheckCommitLargeFileUpload() throws IOException {
|
|
|
|
+ DFSClient dfsClient = Mockito.mock(DFSClient.class);
|
|
|
|
+ Nfs3FileAttributes attr = new Nfs3FileAttributes();
|
|
|
|
+ HdfsDataOutputStream fos = Mockito.mock(HdfsDataOutputStream.class);
|
|
|
|
+ Mockito.when(fos.getPos()).thenReturn((long) 0);
|
|
|
|
+
|
|
|
|
+ NfsConfiguration conf = new NfsConfiguration();
|
|
|
|
+ conf.setBoolean(NfsConfigKeys.LARGE_FILE_UPLOAD, true);
|
|
|
|
+ OpenFileCtx ctx = new OpenFileCtx(fos, attr, "/dumpFilePath", dfsClient,
|
|
|
|
+ new IdUserGroup(conf), false, conf);
|
|
|
|
+
|
|
|
|
+ COMMIT_STATUS ret;
|
|
|
|
+
|
|
|
|
+ // Test inactive open file context
|
|
|
|
+ ctx.setActiveStatusForTest(false);
|
|
|
|
+ Channel ch = Mockito.mock(Channel.class);
|
|
|
|
+ ret = ctx.checkCommit(dfsClient, 0, ch, 1, attr, false);
|
|
|
|
+ Assert.assertTrue(ret == COMMIT_STATUS.COMMIT_INACTIVE_CTX);
|
|
|
|
+
|
|
|
|
+ ctx.getPendingWritesForTest().put(new OffsetRange(5, 10),
|
|
|
|
+ new WriteCtx(null, 0, 0, 0, null, null, null, 0, false, null));
|
|
|
|
+ ret = ctx.checkCommit(dfsClient, 0, ch, 1, attr, false);
|
|
|
|
+ Assert.assertTrue(ret == COMMIT_STATUS.COMMIT_INACTIVE_WITH_PENDING_WRITE);
|
|
|
|
+
|
|
|
|
+ // Test request with non zero commit offset
|
|
|
|
+ ctx.setActiveStatusForTest(true);
|
|
|
|
+ Mockito.when(fos.getPos()).thenReturn((long) 10);
|
|
|
|
+ ctx.setNextOffsetForTest(10);
|
|
|
|
+ COMMIT_STATUS status = ctx.checkCommitInternal(5, null, 1, attr, false);
|
|
|
|
+ Assert.assertTrue(status == COMMIT_STATUS.COMMIT_DO_SYNC);
|
|
|
|
+ // Do_SYNC state will be updated to FINISHED after data sync
|
|
|
|
+ ret = ctx.checkCommit(dfsClient, 5, ch, 1, attr, false);
|
|
|
|
+ Assert.assertTrue(ret == COMMIT_STATUS.COMMIT_FINISHED);
|
|
|
|
+
|
|
|
|
+ status = ctx.checkCommitInternal(10, ch, 1, attr, false);
|
|
|
|
+ Assert.assertTrue(status == COMMIT_STATUS.COMMIT_DO_SYNC);
|
|
|
|
+ ret = ctx.checkCommit(dfsClient, 10, ch, 1, attr, false);
|
|
|
|
+ Assert.assertTrue(ret == COMMIT_STATUS.COMMIT_FINISHED);
|
|
|
|
+
|
|
|
|
+ ConcurrentNavigableMap<Long, CommitCtx> commits = ctx
|
|
|
|
+ .getPendingCommitsForTest();
|
|
|
|
+ Assert.assertTrue(commits.size() == 0);
|
|
|
|
+ ret = ctx.checkCommit(dfsClient, 11, ch, 1, attr, false);
|
|
|
|
+ Assert.assertTrue(ret == COMMIT_STATUS.COMMIT_SPECIAL_SUCCESS);
|
|
|
|
+ Assert.assertTrue(commits.size() == 0);
|
|
|
|
+
|
|
|
|
+ // Test request with zero commit offset
|
|
|
|
+ commits.remove(new Long(11));
|
|
|
|
+ // There is one pending write [5,10]
|
|
|
|
+ ret = ctx.checkCommitInternal(0, ch, 1, attr, false);
|
|
|
|
+ Assert.assertTrue(ret == COMMIT_STATUS.COMMIT_DO_SYNC);
|
|
|
|
+
|
|
|
|
+ Mockito.when(fos.getPos()).thenReturn((long) 6);
|
|
|
|
+ ret = ctx.checkCommitInternal(8, ch, 1, attr, false);
|
|
|
|
+ Assert.assertTrue(ret == COMMIT_STATUS.COMMIT_SPECIAL_WAIT);
|
|
|
|
+ Assert.assertTrue(commits.size() == 1);
|
|
|
|
+ long key = commits.firstKey();
|
|
|
|
+ Assert.assertTrue(key == 8);
|
|
|
|
+
|
|
|
|
+ // Empty pending writes
|
|
|
|
+ ctx.getPendingWritesForTest().remove(new OffsetRange(5, 10));
|
|
|
|
+ ret = ctx.checkCommit(dfsClient, 0, ch, 1, attr, false);
|
|
|
|
+ Assert.assertTrue(ret == COMMIT_STATUS.COMMIT_FINISHED);
|
|
|
|
+ }
|
|
|
|
+
|
|
@Test
|
|
@Test
|
|
public void testCheckCommitAixCompatMode() throws IOException {
|
|
public void testCheckCommitAixCompatMode() throws IOException {
|
|
DFSClient dfsClient = Mockito.mock(DFSClient.class);
|
|
DFSClient dfsClient = Mockito.mock(DFSClient.class);
|
|
Nfs3FileAttributes attr = new Nfs3FileAttributes();
|
|
Nfs3FileAttributes attr = new Nfs3FileAttributes();
|
|
HdfsDataOutputStream fos = Mockito.mock(HdfsDataOutputStream.class);
|
|
HdfsDataOutputStream fos = Mockito.mock(HdfsDataOutputStream.class);
|
|
|
|
|
|
- // Last argument "true" here to enable AIX compatibility mode.
|
|
|
|
|
|
+ NfsConfiguration conf = new NfsConfiguration();
|
|
|
|
+ conf.setBoolean(NfsConfigKeys.LARGE_FILE_UPLOAD, false);
|
|
|
|
+ // Enable AIX compatibility mode.
|
|
OpenFileCtx ctx = new OpenFileCtx(fos, attr, "/dumpFilePath", dfsClient,
|
|
OpenFileCtx ctx = new OpenFileCtx(fos, attr, "/dumpFilePath", dfsClient,
|
|
- new IdUserGroup(new NfsConfiguration()), true);
|
|
|
|
|
|
+ new IdUserGroup(new NfsConfiguration()), true, conf);
|
|
|
|
|
|
// Test fall-through to pendingWrites check in the event that commitOffset
|
|
// Test fall-through to pendingWrites check in the event that commitOffset
|
|
// is greater than the number of bytes we've so far flushed.
|
|
// is greater than the number of bytes we've so far flushed.
|
|
@@ -210,6 +283,8 @@ public class TestWrites {
|
|
|
|
|
|
// Test the case when we actually have received more bytes than we're trying
|
|
// Test the case when we actually have received more bytes than we're trying
|
|
// to commit.
|
|
// to commit.
|
|
|
|
+ ctx.getPendingWritesForTest().put(new OffsetRange(0, 10),
|
|
|
|
+ new WriteCtx(null, 0, 0, 0, null, null, null, 0, false, null));
|
|
Mockito.when(fos.getPos()).thenReturn((long) 10);
|
|
Mockito.when(fos.getPos()).thenReturn((long) 10);
|
|
status = ctx.checkCommitInternal(5, null, 1, attr, false);
|
|
status = ctx.checkCommitInternal(5, null, 1, attr, false);
|
|
Assert.assertTrue(status == COMMIT_STATUS.COMMIT_DO_SYNC);
|
|
Assert.assertTrue(status == COMMIT_STATUS.COMMIT_DO_SYNC);
|
|
@@ -226,8 +301,9 @@ public class TestWrites {
|
|
Mockito.when(fos.getPos()).thenReturn((long) 0);
|
|
Mockito.when(fos.getPos()).thenReturn((long) 0);
|
|
NfsConfiguration config = new NfsConfiguration();
|
|
NfsConfiguration config = new NfsConfiguration();
|
|
|
|
|
|
|
|
+ config.setBoolean(NfsConfigKeys.LARGE_FILE_UPLOAD, false);
|
|
OpenFileCtx ctx = new OpenFileCtx(fos, attr, "/dumpFilePath", dfsClient,
|
|
OpenFileCtx ctx = new OpenFileCtx(fos, attr, "/dumpFilePath", dfsClient,
|
|
- new IdUserGroup(config));
|
|
|
|
|
|
+ new IdUserGroup(config), false, config);
|
|
|
|
|
|
FileHandle h = new FileHandle(1); // fake handle for "/dumpFilePath"
|
|
FileHandle h = new FileHandle(1); // fake handle for "/dumpFilePath"
|
|
COMMIT_STATUS ret;
|
|
COMMIT_STATUS ret;
|
|
@@ -285,6 +361,75 @@ public class TestWrites {
|
|
assertEquals(Nfs3Status.NFS3_OK, wm.commitBeforeRead(dfsClient, h, 0));
|
|
assertEquals(Nfs3Status.NFS3_OK, wm.commitBeforeRead(dfsClient, h, 0));
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ @Test
|
|
|
|
+ // Validate all the commit check return codes OpenFileCtx.COMMIT_STATUS with large file upload option
|
|
|
|
+ public void testCheckCommitFromReadLargeFileUpload() throws IOException {
|
|
|
|
+ DFSClient dfsClient = Mockito.mock(DFSClient.class);
|
|
|
|
+ Nfs3FileAttributes attr = new Nfs3FileAttributes();
|
|
|
|
+ HdfsDataOutputStream fos = Mockito.mock(HdfsDataOutputStream.class);
|
|
|
|
+ Mockito.when(fos.getPos()).thenReturn((long) 0);
|
|
|
|
+ NfsConfiguration config = new NfsConfiguration();
|
|
|
|
+
|
|
|
|
+ config.setBoolean(NfsConfigKeys.LARGE_FILE_UPLOAD, true);
|
|
|
|
+ OpenFileCtx ctx = new OpenFileCtx(fos, attr, "/dumpFilePath", dfsClient,
|
|
|
|
+ new IdUserGroup(config), false, config);
|
|
|
|
+
|
|
|
|
+ FileHandle h = new FileHandle(1); // fake handle for "/dumpFilePath"
|
|
|
|
+ COMMIT_STATUS ret;
|
|
|
|
+ WriteManager wm = new WriteManager(new IdUserGroup(config), config, false);
|
|
|
|
+ assertTrue(wm.addOpenFileStream(h, ctx));
|
|
|
|
+
|
|
|
|
+ // Test inactive open file context
|
|
|
|
+ ctx.setActiveStatusForTest(false);
|
|
|
|
+ Channel ch = Mockito.mock(Channel.class);
|
|
|
|
+ ret = ctx.checkCommit(dfsClient, 0, ch, 1, attr, true);
|
|
|
|
+ assertEquals( COMMIT_STATUS.COMMIT_INACTIVE_CTX, ret);
|
|
|
|
+ assertEquals(Nfs3Status.NFS3_OK, wm.commitBeforeRead(dfsClient, h, 0));
|
|
|
|
+
|
|
|
|
+ ctx.getPendingWritesForTest().put(new OffsetRange(5, 10),
|
|
|
|
+ new WriteCtx(null, 0, 0, 0, null, null, null, 0, false, null));
|
|
|
|
+ ret = ctx.checkCommit(dfsClient, 0, ch, 1, attr, true);
|
|
|
|
+ assertEquals(COMMIT_STATUS.COMMIT_INACTIVE_WITH_PENDING_WRITE, ret);
|
|
|
|
+ assertEquals(Nfs3Status.NFS3ERR_IO, wm.commitBeforeRead(dfsClient, h, 0));
|
|
|
|
+
|
|
|
|
+ // Test request with non zero commit offset
|
|
|
|
+ ctx.setActiveStatusForTest(true);
|
|
|
|
+ Mockito.when(fos.getPos()).thenReturn((long) 10);
|
|
|
|
+ COMMIT_STATUS status = ctx.checkCommitInternal(5, ch, 1, attr, false);
|
|
|
|
+ assertEquals(COMMIT_STATUS.COMMIT_DO_SYNC, status);
|
|
|
|
+ // Do_SYNC state will be updated to FINISHED after data sync
|
|
|
|
+ ret = ctx.checkCommit(dfsClient, 5, ch, 1, attr, true);
|
|
|
|
+ assertEquals(COMMIT_STATUS.COMMIT_FINISHED, ret);
|
|
|
|
+ assertEquals(Nfs3Status.NFS3_OK, wm.commitBeforeRead(dfsClient, h, 5));
|
|
|
|
+
|
|
|
|
+ status = ctx.checkCommitInternal(10, ch, 1, attr, true);
|
|
|
|
+ assertTrue(status == COMMIT_STATUS.COMMIT_DO_SYNC);
|
|
|
|
+ ret = ctx.checkCommit(dfsClient, 10, ch, 1, attr, true);
|
|
|
|
+ assertEquals(COMMIT_STATUS.COMMIT_FINISHED, ret);
|
|
|
|
+ assertEquals(Nfs3Status.NFS3_OK, wm.commitBeforeRead(dfsClient, h, 10));
|
|
|
|
+
|
|
|
|
+ ConcurrentNavigableMap<Long, CommitCtx> commits = ctx
|
|
|
|
+ .getPendingCommitsForTest();
|
|
|
|
+ assertTrue(commits.size() == 0);
|
|
|
|
+ ret = ctx.checkCommit(dfsClient, 11, ch, 1, attr, true);
|
|
|
|
+ assertEquals(COMMIT_STATUS.COMMIT_SPECIAL_SUCCESS, ret);
|
|
|
|
+ assertEquals(0, commits.size()); // commit triggered by read doesn't wait
|
|
|
|
+ assertEquals(Nfs3Status.NFS3_OK, wm.commitBeforeRead(dfsClient, h, 11));
|
|
|
|
+
|
|
|
|
+ // Test request with zero commit offset
|
|
|
|
+ // There is one pending write [5,10]
|
|
|
|
+ ret = ctx.checkCommit(dfsClient, 0, ch, 1, attr, true);
|
|
|
|
+ assertEquals(COMMIT_STATUS.COMMIT_FINISHED, ret);
|
|
|
|
+ assertEquals(0, commits.size());
|
|
|
|
+ assertEquals(Nfs3Status.NFS3_OK, wm.commitBeforeRead(dfsClient, h, 0));
|
|
|
|
+
|
|
|
|
+ // Empty pending writes
|
|
|
|
+ ctx.getPendingWritesForTest().remove(new OffsetRange(5, 10));
|
|
|
|
+ ret = ctx.checkCommit(dfsClient, 0, ch, 1, attr, true);
|
|
|
|
+ assertEquals(COMMIT_STATUS.COMMIT_FINISHED, ret);
|
|
|
|
+ assertEquals(Nfs3Status.NFS3_OK, wm.commitBeforeRead(dfsClient, h, 0));
|
|
|
|
+ }
|
|
|
|
+
|
|
private void waitWrite(RpcProgramNfs3 nfsd, FileHandle handle, int maxWaitTime)
|
|
private void waitWrite(RpcProgramNfs3 nfsd, FileHandle handle, int maxWaitTime)
|
|
throws InterruptedException {
|
|
throws InterruptedException {
|
|
int waitedTime = 0;
|
|
int waitedTime = 0;
|