/// <exception cref="Com.Google.Protobuf.ServiceException"/> public virtual ClientDatanodeProtocolProtos.GetBlockLocalPathInfoResponseProto GetBlockLocalPathInfo (RpcController unused, ClientDatanodeProtocolProtos.GetBlockLocalPathInfoRequestProto request) { BlockLocalPathInfo resp; try { resp = impl.GetBlockLocalPathInfo(PBHelper.Convert(request.GetBlock()), PBHelper. Convert(request.GetToken())); } catch (IOException e) { throw new ServiceException(e); } return((ClientDatanodeProtocolProtos.GetBlockLocalPathInfoResponseProto)ClientDatanodeProtocolProtos.GetBlockLocalPathInfoResponseProto .NewBuilder().SetBlock(PBHelper.Convert(resp.GetBlock())).SetLocalPath(resp.GetBlockPath ()).SetLocalMetaPath(resp.GetMetaPath()).Build()); }
/// <exception cref="System.IO.IOException"/> public virtual void TestDeprecatedGetBlockLocalPathInfoRpc() { Configuration conf = new Configuration(); MiniDFSCluster cluster = new MiniDFSCluster.Builder(conf).NumDataNodes(1).Format( true).Build(); cluster.WaitActive(); FileSystem fs = cluster.GetFileSystem(); try { DFSTestUtil.CreateFile(fs, new Path("/tmp/x"), 16, (short)1, 23); LocatedBlocks lb = cluster.GetNameNode().GetRpcServer().GetBlockLocations("/tmp/x" , 0, 16); // Create a new block object, because the block inside LocatedBlock at // namenode is of type BlockInfo. ExtendedBlock blk = new ExtendedBlock(lb.Get(0).GetBlock()); Org.Apache.Hadoop.Security.Token.Token <BlockTokenIdentifier> token = lb.Get(0).GetBlockToken (); DatanodeInfo dnInfo = lb.Get(0).GetLocations()[0]; ClientDatanodeProtocol proxy = DFSUtil.CreateClientDatanodeProtocolProxy(dnInfo, conf, 60000, false); try { proxy.GetBlockLocalPathInfo(blk, token); NUnit.Framework.Assert.Fail("The call should have failed as this user " + " is not allowed to call getBlockLocalPathInfo" ); } catch (IOException ex) { NUnit.Framework.Assert.IsTrue(ex.Message.Contains("not allowed to call getBlockLocalPathInfo" )); } } finally { fs.Close(); cluster.Shutdown(); } }
/// <exception cref="System.IO.IOException"/> private static BlockLocalPathInfo GetBlockPathInfo(UserGroupInformation ugi, ExtendedBlock blk, DatanodeInfo node, Configuration conf, int timeout, Org.Apache.Hadoop.Security.Token.Token <BlockTokenIdentifier> token, bool connectToDnViaHostname, StorageType storageType ) { BlockReaderLocalLegacy.LocalDatanodeInfo localDatanodeInfo = GetLocalDatanodeInfo (node.GetIpcPort()); BlockLocalPathInfo pathinfo = null; ClientDatanodeProtocol proxy = localDatanodeInfo.GetDatanodeProxy(ugi, node, conf , timeout, connectToDnViaHostname); try { // make RPC to local datanode to find local pathnames of blocks pathinfo = proxy.GetBlockLocalPathInfo(blk, token); // We cannot cache the path information for a replica on transient storage. // If the replica gets evicted, then it moves to a different path. Then, // our next attempt to read from the cached path would fail to find the // file. Additionally, the failure would cause us to disable legacy // short-circuit read for all subsequent use in the ClientContext. Unlike // the newer short-circuit read implementation, we have no communication // channel for the DataNode to notify the client that the path has been // invalidated. Therefore, our only option is to skip caching. if (pathinfo != null && !storageType.IsTransient()) { if (Log.IsDebugEnabled()) { Log.Debug("Cached location of block " + blk + " as " + pathinfo); } localDatanodeInfo.SetBlockLocalPathInfo(blk, pathinfo); } } catch (IOException e) { localDatanodeInfo.ResetDatanodeProxy(); // Reset proxy on error throw; } return(pathinfo); }