Ejemplo n.º 1
0
        /// <exception cref="System.Exception"/>
        private void Commit(string fileName, int len)
        {
            HdfsFileStatus status  = nn.GetRpcServer().GetFileInfo(fileName);
            long           dirId   = status.GetFileId();
            FileHandle     handle  = new FileHandle(dirId);
            XDR            xdr_req = new XDR();
            COMMIT3Request req     = new COMMIT3Request(handle, 0, len);

            req.Serialize(xdr_req);
            Org.Jboss.Netty.Channel.Channel ch = Org.Mockito.Mockito.Mock <Org.Jboss.Netty.Channel.Channel
                                                                           >();
            COMMIT3Response response2 = nfsd.Commit(xdr_req.AsReadOnlyWrap(), ch, 1, securityHandler
                                                    , new IPEndPoint("localhost", 1234));

            NUnit.Framework.Assert.AreEqual("Incorrect COMMIT3Response:", null, response2);
        }
Ejemplo n.º 2
0
        /// <exception cref="System.Exception"/>
        public virtual void TestCommit()
        {
            HdfsFileStatus status  = nn.GetRpcServer().GetFileInfo("/tmp/bar");
            long           dirId   = status.GetFileId();
            FileHandle     handle  = new FileHandle(dirId);
            XDR            xdr_req = new XDR();
            COMMIT3Request req     = new COMMIT3Request(handle, 0, 5);

            req.Serialize(xdr_req);
            Org.Jboss.Netty.Channel.Channel ch = Org.Mockito.Mockito.Mock <Org.Jboss.Netty.Channel.Channel
                                                                           >();
            // Attempt by an unpriviledged user should fail.
            COMMIT3Response response1 = nfsd.Commit(xdr_req.AsReadOnlyWrap(), ch, 1, securityHandlerUnpriviledged
                                                    , new IPEndPoint("localhost", 1234));

            NUnit.Framework.Assert.AreEqual("Incorrect return code:", Nfs3Status.Nfs3errAcces
                                            , response1.GetStatus());
            // Attempt by a priviledged user should pass.
            COMMIT3Response response2 = nfsd.Commit(xdr_req.AsReadOnlyWrap(), ch, 1, securityHandler
                                                    , new IPEndPoint("localhost", 1234));

            NUnit.Framework.Assert.AreEqual("Incorrect COMMIT3Response:", null, response2);
        }
Ejemplo n.º 3
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);
        }