Search in sources :

Example 1 with RpcProgramNfs3

use of org.apache.hadoop.hdfs.nfs.nfs3.RpcProgramNfs3 in project hadoop by apache.

the class WriteManager method handleCommit.

void handleCommit(DFSClient dfsClient, FileHandle fileHandle, long commitOffset, Channel channel, int xid, Nfs3FileAttributes preOpAttr) {
    long startTime = System.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.NFS3_OK;
    } else {
        COMMIT_STATUS ret = openFileCtx.checkCommit(dfsClient, commitOffset, channel, xid, preOpAttr, false);
        switch(ret) {
            case COMMIT_FINISHED:
            case COMMIT_INACTIVE_CTX:
                status = Nfs3Status.NFS3_OK;
                break;
            case COMMIT_INACTIVE_WITH_PENDING_WRITE:
            case COMMIT_ERROR:
                status = Nfs3Status.NFS3ERR_IO;
                break;
            case COMMIT_WAIT:
                // Do nothing. Commit is async now.
                return;
            case COMMIT_SPECIAL_WAIT:
                status = Nfs3Status.NFS3ERR_JUKEBOX;
                break;
            case COMMIT_SPECIAL_SUCCESS:
                status = Nfs3Status.NFS3_OK;
                break;
            default:
                LOG.error("Should not get commit return code: " + ret.name());
                throw new RuntimeException("Should not get commit return code: " + ret.name());
        }
    }
    // 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.WRITE_COMMIT_VERF);
    RpcProgramNfs3.metrics.addCommit(Nfs3Utils.getElapsedTime(startTime));
    Nfs3Utils.writeChannelCommit(channel, response.serialize(new XDR(), xid, new VerifierNone()), xid);
}
Also used : WccData(org.apache.hadoop.nfs.nfs3.response.WccData) COMMIT3Response(org.apache.hadoop.nfs.nfs3.response.COMMIT3Response) FileHandle(org.apache.hadoop.nfs.nfs3.FileHandle) Nfs3FileAttributes(org.apache.hadoop.nfs.nfs3.Nfs3FileAttributes) XDR(org.apache.hadoop.oncrpc.XDR) VerifierNone(org.apache.hadoop.oncrpc.security.VerifierNone) IOException(java.io.IOException) COMMIT_STATUS(org.apache.hadoop.hdfs.nfs.nfs3.OpenFileCtx.COMMIT_STATUS)

Example 2 with RpcProgramNfs3

use of org.apache.hadoop.hdfs.nfs.nfs3.RpcProgramNfs3 in project hadoop by apache.

the class TestMountd method testStart.

@Test
public void testStart() throws IOException {
    // Start minicluster
    NfsConfiguration config = new NfsConfiguration();
    MiniDFSCluster cluster = new MiniDFSCluster.Builder(config).numDataNodes(1).build();
    cluster.waitActive();
    // Use emphral port in case tests are running in parallel
    config.setInt("nfs3.mountd.port", 0);
    config.setInt("nfs3.server.port", 0);
    // 1s
    int newTimeoutMillis = 1000;
    // Set the new portmap rpc timeout values and check
    config.setInt(NfsConfigKeys.NFS_UDP_CLIENT_PORTMAP_TIMEOUT_MILLIS_KEY, newTimeoutMillis);
    assertTrue(config.getInt(NfsConfigKeys.NFS_UDP_CLIENT_PORTMAP_TIMEOUT_MILLIS_KEY, 0) == newTimeoutMillis);
    // Start nfs
    Nfs3 nfs3 = new Nfs3(config);
    nfs3.startServiceInternal(false);
    RpcProgramMountd mountd = (RpcProgramMountd) nfs3.getMountd().getRpcProgram();
    mountd.nullOp(new XDR(), 1234, InetAddress.getByName("localhost"));
    assertTrue(mountd.getPortmapUdpTimeoutMillis() == newTimeoutMillis);
    RpcProgramNfs3 nfsd = (RpcProgramNfs3) nfs3.getRpcProgram();
    nfsd.nullProcedure();
    assertTrue(nfsd.getPortmapUdpTimeoutMillis() == newTimeoutMillis);
    cluster.shutdown();
}
Also used : RpcProgramMountd(org.apache.hadoop.hdfs.nfs.mount.RpcProgramMountd) MiniDFSCluster(org.apache.hadoop.hdfs.MiniDFSCluster) RpcProgramNfs3(org.apache.hadoop.hdfs.nfs.nfs3.RpcProgramNfs3) XDR(org.apache.hadoop.oncrpc.XDR) NfsConfiguration(org.apache.hadoop.hdfs.nfs.conf.NfsConfiguration) RpcProgramNfs3(org.apache.hadoop.hdfs.nfs.nfs3.RpcProgramNfs3) Nfs3(org.apache.hadoop.hdfs.nfs.nfs3.Nfs3) Test(org.junit.Test)

Example 3 with RpcProgramNfs3

use of org.apache.hadoop.hdfs.nfs.nfs3.RpcProgramNfs3 in project hadoop by apache.

the class TestReaddir method setup.

@BeforeClass
public static void setup() throws Exception {
    String currentUser = System.getProperty("user.name");
    config.set(DefaultImpersonationProvider.getTestProvider().getProxySuperuserGroupConfKey(currentUser), "*");
    config.set(DefaultImpersonationProvider.getTestProvider().getProxySuperuserIpConfKey(currentUser), "*");
    ProxyUsers.refreshSuperUserGroupsConfiguration(config);
    cluster = new MiniDFSCluster.Builder(config).numDataNodes(1).build();
    cluster.waitActive();
    hdfs = cluster.getFileSystem();
    nn = cluster.getNameNode();
    // Use emphral port in case tests are running in parallel
    config.setInt("nfs3.mountd.port", 0);
    config.setInt("nfs3.server.port", 0);
    // Start nfs
    Nfs3 nfs3 = new Nfs3(config);
    nfs3.startServiceInternal(false);
    nfsd = (RpcProgramNfs3) nfs3.getRpcProgram();
    securityHandler = Mockito.mock(SecurityHandler.class);
    Mockito.when(securityHandler.getUser()).thenReturn(System.getProperty("user.name"));
}
Also used : SecurityHandler(org.apache.hadoop.oncrpc.security.SecurityHandler) MiniDFSCluster(org.apache.hadoop.hdfs.MiniDFSCluster) RpcProgramNfs3(org.apache.hadoop.hdfs.nfs.nfs3.RpcProgramNfs3) Nfs3(org.apache.hadoop.hdfs.nfs.nfs3.Nfs3) BeforeClass(org.junit.BeforeClass)

Aggregations

MiniDFSCluster (org.apache.hadoop.hdfs.MiniDFSCluster)2 Nfs3 (org.apache.hadoop.hdfs.nfs.nfs3.Nfs3)2 RpcProgramNfs3 (org.apache.hadoop.hdfs.nfs.nfs3.RpcProgramNfs3)2 XDR (org.apache.hadoop.oncrpc.XDR)2 IOException (java.io.IOException)1 NfsConfiguration (org.apache.hadoop.hdfs.nfs.conf.NfsConfiguration)1 RpcProgramMountd (org.apache.hadoop.hdfs.nfs.mount.RpcProgramMountd)1 COMMIT_STATUS (org.apache.hadoop.hdfs.nfs.nfs3.OpenFileCtx.COMMIT_STATUS)1 FileHandle (org.apache.hadoop.nfs.nfs3.FileHandle)1 Nfs3FileAttributes (org.apache.hadoop.nfs.nfs3.Nfs3FileAttributes)1 COMMIT3Response (org.apache.hadoop.nfs.nfs3.response.COMMIT3Response)1 WccData (org.apache.hadoop.nfs.nfs3.response.WccData)1 SecurityHandler (org.apache.hadoop.oncrpc.security.SecurityHandler)1 VerifierNone (org.apache.hadoop.oncrpc.security.VerifierNone)1 BeforeClass (org.junit.BeforeClass)1 Test (org.junit.Test)1