Esempio n. 1
0
        // Do a possible commit before read request in case there is buffered data
        // inside DFSClient which has been flushed but not synced.
        internal virtual int CommitBeforeRead(DFSClient dfsClient, FileHandle fileHandle,
                                              long commitOffset)
        {
            int         status;
            OpenFileCtx openFileCtx = fileContextCache.Get(fileHandle);

            if (openFileCtx == null)
            {
                if (Log.IsDebugEnabled())
                {
                    Log.Debug("No opened stream for fileId: " + fileHandle.GetFileId() + " commitOffset="
                              + commitOffset + ". Return success in this case.");
                }
                status = Nfs3Status.Nfs3Ok;
            }
            else
            {
                // commit request triggered by read won't create pending comment obj
                OpenFileCtx.COMMIT_STATUS ret = openFileCtx.CheckCommit(dfsClient, commitOffset,
                                                                        null, 0, null, true);
                switch (ret)
                {
                case OpenFileCtx.COMMIT_STATUS.CommitFinished:
                case OpenFileCtx.COMMIT_STATUS.CommitInactiveCtx:
                {
                    status = Nfs3Status.Nfs3Ok;
                    break;
                }

                case OpenFileCtx.COMMIT_STATUS.CommitInactiveWithPendingWrite:
                case OpenFileCtx.COMMIT_STATUS.CommitError:
                {
                    status = Nfs3Status.Nfs3errIo;
                    break;
                }

                case OpenFileCtx.COMMIT_STATUS.CommitWait:
                case OpenFileCtx.COMMIT_STATUS.CommitSpecialWait:
                {
                    status = Nfs3Status.Nfs3errJukebox;
                    break;
                }

                case OpenFileCtx.COMMIT_STATUS.CommitSpecialSuccess:
                {
                    // Read beyond eof could result in partial read
                    status = Nfs3Status.Nfs3Ok;
                    break;
                }

                default:
                {
                    Log.Error("Should not get commit return code: " + ret.ToString());
                    throw new RuntimeException("Should not get commit return code: " + ret.ToString()
                                               );
                }
                }
            }
            return(status);
        }
Esempio n. 2
0
        internal virtual void HandleCommit(DFSClient dfsClient, FileHandle fileHandle, long
                                           commitOffset, Org.Jboss.Netty.Channel.Channel channel, int xid, Nfs3FileAttributes
                                           preOpAttr)
        {
            long        startTime = Runtime.NanoTime();
            int         status;
            OpenFileCtx openFileCtx = fileContextCache.Get(fileHandle);

            if (openFileCtx == null)
            {
                Log.Info("No opened stream for fileId: " + fileHandle.GetFileId() + " commitOffset="
                         + commitOffset + ". Return success in this case.");
                status = Nfs3Status.Nfs3Ok;
            }
            else
            {
                OpenFileCtx.COMMIT_STATUS ret = openFileCtx.CheckCommit(dfsClient, commitOffset,
                                                                        channel, xid, preOpAttr, false);
                switch (ret)
                {
                case OpenFileCtx.COMMIT_STATUS.CommitFinished:
                case OpenFileCtx.COMMIT_STATUS.CommitInactiveCtx:
                {
                    status = Nfs3Status.Nfs3Ok;
                    break;
                }

                case OpenFileCtx.COMMIT_STATUS.CommitInactiveWithPendingWrite:
                case OpenFileCtx.COMMIT_STATUS.CommitError:
                {
                    status = Nfs3Status.Nfs3errIo;
                    break;
                }

                case OpenFileCtx.COMMIT_STATUS.CommitWait:
                {
                    // Do nothing. Commit is async now.
                    return;
                }

                case OpenFileCtx.COMMIT_STATUS.CommitSpecialWait:
                {
                    status = Nfs3Status.Nfs3errJukebox;
                    break;
                }

                case OpenFileCtx.COMMIT_STATUS.CommitSpecialSuccess:
                {
                    status = Nfs3Status.Nfs3Ok;
                    break;
                }

                default:
                {
                    Log.Error("Should not get commit return code: " + ret.ToString());
                    throw new RuntimeException("Should not get commit return code: " + ret.ToString()
                                               );
                }
                }
            }
            // Send out the response
            Nfs3FileAttributes postOpAttr = null;

            try
            {
                postOpAttr = GetFileAttr(dfsClient, new FileHandle(preOpAttr.GetFileId()), iug);
            }
            catch (IOException e1)
            {
                Log.Info("Can't get postOpAttr for fileId: " + preOpAttr.GetFileId(), e1);
            }
            WccData         fileWcc  = new WccData(Nfs3Utils.GetWccAttr(preOpAttr), postOpAttr);
            COMMIT3Response response = new COMMIT3Response(status, fileWcc, Nfs3Constant.WriteCommitVerf
                                                           );

            RpcProgramNfs3.metrics.AddCommit(Nfs3Utils.GetElapsedTime(startTime));
            Nfs3Utils.WriteChannelCommit(channel, response.Serialize(new XDR(), xid, new VerifierNone
                                                                         ()), xid);
        }
Esempio n. 3
0
        public virtual void TestCheckCommitFromReadLargeFileUpload()
        {
            // Validate all the commit check return codes OpenFileCtx.COMMIT_STATUS with large file upload option
            DFSClient            dfsClient = Org.Mockito.Mockito.Mock <DFSClient>();
            Nfs3FileAttributes   attr      = new Nfs3FileAttributes();
            HdfsDataOutputStream fos       = Org.Mockito.Mockito.Mock <HdfsDataOutputStream>();

            Org.Mockito.Mockito.When(fos.GetPos()).ThenReturn((long)0);
            NfsConfiguration config = new NfsConfiguration();

            config.SetBoolean(NfsConfigKeys.LargeFileUpload, true);
            OpenFileCtx ctx = new OpenFileCtx(fos, attr, "/dumpFilePath", dfsClient, new ShellBasedIdMapping
                                                  (config), false, config);
            FileHandle h = new FileHandle(1);

            // fake handle for "/dumpFilePath"
            OpenFileCtx.COMMIT_STATUS ret;
            WriteManager wm = new WriteManager(new ShellBasedIdMapping(config), config, false
                                               );

            NUnit.Framework.Assert.IsTrue(wm.AddOpenFileStream(h, ctx));
            // Test inactive open file context
            ctx.SetActiveStatusForTest(false);
            Org.Jboss.Netty.Channel.Channel ch = Org.Mockito.Mockito.Mock <Org.Jboss.Netty.Channel.Channel
                                                                           >();
            ret = ctx.CheckCommit(dfsClient, 0, ch, 1, attr, true);
            NUnit.Framework.Assert.AreEqual(OpenFileCtx.COMMIT_STATUS.CommitInactiveCtx, ret);
            NUnit.Framework.Assert.AreEqual(Nfs3Status.Nfs3Ok, wm.CommitBeforeRead(dfsClient,
                                                                                   h, 0));
            ctx.GetPendingWritesForTest()[new OffsetRange(10, 15)] = new WriteCtx(null, 0, 0,
                                                                                  0, null, null, null, 0, false, null);
            ret = ctx.CheckCommit(dfsClient, 0, ch, 1, attr, true);
            NUnit.Framework.Assert.AreEqual(OpenFileCtx.COMMIT_STATUS.CommitInactiveWithPendingWrite
                                            , ret);
            NUnit.Framework.Assert.AreEqual(Nfs3Status.Nfs3errIo, wm.CommitBeforeRead(dfsClient
                                                                                      , h, 0));
            // Test request with non zero commit offset
            ctx.SetActiveStatusForTest(true);
            Org.Mockito.Mockito.When(fos.GetPos()).ThenReturn((long)6);
            ctx.SetNextOffsetForTest((long)10);
            OpenFileCtx.COMMIT_STATUS status = ctx.CheckCommitInternal(5, ch, 1, attr, false);
            NUnit.Framework.Assert.AreEqual(OpenFileCtx.COMMIT_STATUS.CommitDoSync, status);
            // Do_SYNC state will be updated to FINISHED after data sync
            ret = ctx.CheckCommit(dfsClient, 5, ch, 1, attr, true);
            NUnit.Framework.Assert.AreEqual(OpenFileCtx.COMMIT_STATUS.CommitFinished, ret);
            NUnit.Framework.Assert.AreEqual(Nfs3Status.Nfs3Ok, wm.CommitBeforeRead(dfsClient,
                                                                                   h, 5));
            // Test request with sequential writes
            status = ctx.CheckCommitInternal(9, ch, 1, attr, true);
            NUnit.Framework.Assert.IsTrue(status == OpenFileCtx.COMMIT_STATUS.CommitSpecialWait
                                          );
            ret = ctx.CheckCommit(dfsClient, 9, ch, 1, attr, true);
            NUnit.Framework.Assert.AreEqual(OpenFileCtx.COMMIT_STATUS.CommitSpecialWait, ret);
            NUnit.Framework.Assert.AreEqual(Nfs3Status.Nfs3errJukebox, wm.CommitBeforeRead(dfsClient
                                                                                           , h, 9));
            // Test request with non-sequential writes
            ConcurrentNavigableMap <long, OpenFileCtx.CommitCtx> commits = ctx.GetPendingCommitsForTest
                                                                               ();

            NUnit.Framework.Assert.IsTrue(commits.Count == 0);
            ret = ctx.CheckCommit(dfsClient, 16, ch, 1, attr, true);
            NUnit.Framework.Assert.AreEqual(OpenFileCtx.COMMIT_STATUS.CommitSpecialSuccess, ret
                                            );
            NUnit.Framework.Assert.AreEqual(0, commits.Count);
            // commit triggered by read doesn't wait
            NUnit.Framework.Assert.AreEqual(Nfs3Status.Nfs3Ok, wm.CommitBeforeRead(dfsClient,
                                                                                   h, 16));
            // Test request with zero commit offset
            // There is one pending write [10,15]
            ret = ctx.CheckCommit(dfsClient, 0, ch, 1, attr, true);
            NUnit.Framework.Assert.AreEqual(OpenFileCtx.COMMIT_STATUS.CommitSpecialWait, ret);
            NUnit.Framework.Assert.AreEqual(0, commits.Count);
            NUnit.Framework.Assert.AreEqual(Nfs3Status.Nfs3errJukebox, wm.CommitBeforeRead(dfsClient
                                                                                           , h, 0));
            // Empty pending writes
            Sharpen.Collections.Remove(ctx.GetPendingWritesForTest(), new OffsetRange(10, 15)
                                       );
            ret = ctx.CheckCommit(dfsClient, 0, ch, 1, attr, true);
            NUnit.Framework.Assert.AreEqual(OpenFileCtx.COMMIT_STATUS.CommitSpecialWait, ret);
            NUnit.Framework.Assert.AreEqual(Nfs3Status.Nfs3errJukebox, wm.CommitBeforeRead(dfsClient
                                                                                           , h, 0));
        }
Esempio n. 4
0
        public virtual void TestCheckCommit()
        {
            // Validate all the commit check return codes OpenFileCtx.COMMIT_STATUS, which
            // includes COMMIT_FINISHED, COMMIT_WAIT, COMMIT_INACTIVE_CTX,
            // COMMIT_INACTIVE_WITH_PENDING_WRITE, COMMIT_ERROR, and COMMIT_DO_SYNC.
            DFSClient            dfsClient = Org.Mockito.Mockito.Mock <DFSClient>();
            Nfs3FileAttributes   attr      = new Nfs3FileAttributes();
            HdfsDataOutputStream fos       = Org.Mockito.Mockito.Mock <HdfsDataOutputStream>();

            Org.Mockito.Mockito.When(fos.GetPos()).ThenReturn((long)0);
            NfsConfiguration conf = new NfsConfiguration();

            conf.SetBoolean(NfsConfigKeys.LargeFileUpload, false);
            OpenFileCtx ctx = new OpenFileCtx(fos, attr, "/dumpFilePath", dfsClient, new ShellBasedIdMapping
                                                  (conf), false, conf);

            OpenFileCtx.COMMIT_STATUS ret;
            // Test inactive open file context
            ctx.SetActiveStatusForTest(false);
            Org.Jboss.Netty.Channel.Channel ch = Org.Mockito.Mockito.Mock <Org.Jboss.Netty.Channel.Channel
                                                                           >();
            ret = ctx.CheckCommit(dfsClient, 0, ch, 1, attr, false);
            NUnit.Framework.Assert.IsTrue(ret == OpenFileCtx.COMMIT_STATUS.CommitInactiveCtx);
            ctx.GetPendingWritesForTest()[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);
            NUnit.Framework.Assert.IsTrue(ret == OpenFileCtx.COMMIT_STATUS.CommitInactiveWithPendingWrite
                                          );
            // Test request with non zero commit offset
            ctx.SetActiveStatusForTest(true);
            Org.Mockito.Mockito.When(fos.GetPos()).ThenReturn((long)10);
            ctx.SetNextOffsetForTest(10);
            OpenFileCtx.COMMIT_STATUS status = ctx.CheckCommitInternal(5, null, 1, attr, false
                                                                       );
            NUnit.Framework.Assert.IsTrue(status == OpenFileCtx.COMMIT_STATUS.CommitDoSync);
            // Do_SYNC state will be updated to FINISHED after data sync
            ret = ctx.CheckCommit(dfsClient, 5, ch, 1, attr, false);
            NUnit.Framework.Assert.IsTrue(ret == OpenFileCtx.COMMIT_STATUS.CommitFinished);
            status = ctx.CheckCommitInternal(10, ch, 1, attr, false);
            NUnit.Framework.Assert.IsTrue(status == OpenFileCtx.COMMIT_STATUS.CommitDoSync);
            ret = ctx.CheckCommit(dfsClient, 10, ch, 1, attr, false);
            NUnit.Framework.Assert.IsTrue(ret == OpenFileCtx.COMMIT_STATUS.CommitFinished);
            ConcurrentNavigableMap <long, OpenFileCtx.CommitCtx> commits = ctx.GetPendingCommitsForTest
                                                                               ();

            NUnit.Framework.Assert.IsTrue(commits.Count == 0);
            ret = ctx.CheckCommit(dfsClient, 11, ch, 1, attr, false);
            NUnit.Framework.Assert.IsTrue(ret == OpenFileCtx.COMMIT_STATUS.CommitWait);
            NUnit.Framework.Assert.IsTrue(commits.Count == 1);
            long key = commits.FirstKey();

            NUnit.Framework.Assert.IsTrue(key == 11);
            // Test request with zero commit offset
            Sharpen.Collections.Remove(commits, System.Convert.ToInt64(11));
            // There is one pending write [5,10]
            ret = ctx.CheckCommit(dfsClient, 0, ch, 1, attr, false);
            NUnit.Framework.Assert.IsTrue(ret == OpenFileCtx.COMMIT_STATUS.CommitWait);
            NUnit.Framework.Assert.IsTrue(commits.Count == 1);
            key = commits.FirstKey();
            NUnit.Framework.Assert.IsTrue(key == 9);
            // Empty pending writes
            Sharpen.Collections.Remove(ctx.GetPendingWritesForTest(), new OffsetRange(5, 10));
            ret = ctx.CheckCommit(dfsClient, 0, ch, 1, attr, false);
            NUnit.Framework.Assert.IsTrue(ret == OpenFileCtx.COMMIT_STATUS.CommitFinished);
        }
Esempio n. 5
0
        public virtual void TestCheckCommitLargeFileUpload()
        {
            // Validate all the commit check return codes OpenFileCtx.COMMIT_STATUS with
            // large file upload option.
            DFSClient            dfsClient = Org.Mockito.Mockito.Mock <DFSClient>();
            Nfs3FileAttributes   attr      = new Nfs3FileAttributes();
            HdfsDataOutputStream fos       = Org.Mockito.Mockito.Mock <HdfsDataOutputStream>();

            Org.Mockito.Mockito.When(fos.GetPos()).ThenReturn((long)0);
            NfsConfiguration conf = new NfsConfiguration();

            conf.SetBoolean(NfsConfigKeys.LargeFileUpload, true);
            OpenFileCtx ctx = new OpenFileCtx(fos, attr, "/dumpFilePath", dfsClient, new ShellBasedIdMapping
                                                  (conf), false, conf);

            OpenFileCtx.COMMIT_STATUS ret;
            // Test inactive open file context
            ctx.SetActiveStatusForTest(false);
            Org.Jboss.Netty.Channel.Channel ch = Org.Mockito.Mockito.Mock <Org.Jboss.Netty.Channel.Channel
                                                                           >();
            ret = ctx.CheckCommit(dfsClient, 0, ch, 1, attr, false);
            NUnit.Framework.Assert.IsTrue(ret == OpenFileCtx.COMMIT_STATUS.CommitInactiveCtx);
            ctx.GetPendingWritesForTest()[new OffsetRange(10, 15)] = new WriteCtx(null, 0, 0,
                                                                                  0, null, null, null, 0, false, null);
            ret = ctx.CheckCommit(dfsClient, 0, ch, 1, attr, false);
            NUnit.Framework.Assert.IsTrue(ret == OpenFileCtx.COMMIT_STATUS.CommitInactiveWithPendingWrite
                                          );
            // Test request with non zero commit offset
            ctx.SetActiveStatusForTest(true);
            Org.Mockito.Mockito.When(fos.GetPos()).ThenReturn((long)8);
            ctx.SetNextOffsetForTest(10);
            OpenFileCtx.COMMIT_STATUS status = ctx.CheckCommitInternal(5, null, 1, attr, false
                                                                       );
            NUnit.Framework.Assert.IsTrue(status == OpenFileCtx.COMMIT_STATUS.CommitDoSync);
            // Do_SYNC state will be updated to FINISHED after data sync
            ret = ctx.CheckCommit(dfsClient, 5, ch, 1, attr, false);
            NUnit.Framework.Assert.IsTrue(ret == OpenFileCtx.COMMIT_STATUS.CommitFinished);
            // Test commit sequential writes
            status = ctx.CheckCommitInternal(10, ch, 1, attr, false);
            NUnit.Framework.Assert.IsTrue(status == OpenFileCtx.COMMIT_STATUS.CommitSpecialWait
                                          );
            ret = ctx.CheckCommit(dfsClient, 10, ch, 1, attr, false);
            NUnit.Framework.Assert.IsTrue(ret == OpenFileCtx.COMMIT_STATUS.CommitSpecialWait);
            // Test commit non-sequential writes
            ConcurrentNavigableMap <long, OpenFileCtx.CommitCtx> commits = ctx.GetPendingCommitsForTest
                                                                               ();

            NUnit.Framework.Assert.IsTrue(commits.Count == 1);
            ret = ctx.CheckCommit(dfsClient, 16, ch, 1, attr, false);
            NUnit.Framework.Assert.IsTrue(ret == OpenFileCtx.COMMIT_STATUS.CommitSpecialSuccess
                                          );
            NUnit.Framework.Assert.IsTrue(commits.Count == 1);
            // Test request with zero commit offset
            Sharpen.Collections.Remove(commits, System.Convert.ToInt64(10));
            // There is one pending write [10,15]
            ret = ctx.CheckCommitInternal(0, ch, 1, attr, false);
            NUnit.Framework.Assert.IsTrue(ret == OpenFileCtx.COMMIT_STATUS.CommitSpecialWait);
            ret = ctx.CheckCommitInternal(9, ch, 1, attr, false);
            NUnit.Framework.Assert.IsTrue(ret == OpenFileCtx.COMMIT_STATUS.CommitSpecialWait);
            NUnit.Framework.Assert.IsTrue(commits.Count == 2);
            // Empty pending writes. nextOffset=10, flushed pos=8
            Sharpen.Collections.Remove(ctx.GetPendingWritesForTest(), new OffsetRange(10, 15)
                                       );
            ret = ctx.CheckCommit(dfsClient, 0, ch, 1, attr, false);
            NUnit.Framework.Assert.IsTrue(ret == OpenFileCtx.COMMIT_STATUS.CommitSpecialWait);
            // Empty pending writes
            ctx.SetNextOffsetForTest((long)8);
            // flushed pos = 8
            ret = ctx.CheckCommit(dfsClient, 0, ch, 1, attr, false);
            NUnit.Framework.Assert.IsTrue(ret == OpenFileCtx.COMMIT_STATUS.CommitFinished);
        }