HdfsDesign Prerequisites and Objectives:1,hardware error when normal2,Streaming data Access3,Large data sets4,Simple Consistency Model5,Mobile Computing is more cost effective than moving dataaHdfsthe cluster contains a separateNameNodenodes, more than oneDataNodeserver, and is accessed by multiple clients at the same time. All of these machines are usually normal.Linuxmachine, running at User level(User-level)service process. NameNodeManage File system metadata (record file data in eachDataNodelocation replica information, coordinate client access to files, and record changes in the namespace or changes in the namespace itself,DataNodeStore the actual data. Client throughNameNodeand theDataNodeInteractive access to the file system. <ignore_js_op>FigureHdfsstructure DiagramProtectionHdfsReliability Measures1,Redundant Backups2,Copy Storage3,Heartbeat Detection4,Safe Mode5,Data Integrity Detection6,Space Reclamation7,metadata Disk invalidation8,SnapshotHdfsof theJava APIuploading local files to HDFsthroughFilesystem.copyfromlocalfile (Path Src,path DST)local files can be uploaded to the specified location in HDFs, where SRC and DST are the full paths to the files. Import org.apache.hadoop.conf.Configuration; Import Org.apache.hadoop.fs.FileStatus; Import Org.apache.hadoop.fs.FileSystem; Import Org.apache.hadoop.fs.Path; public class CopyFile {configuration Conf=new configuration (); FileSystem hdfs= filesystem.get (conf); Path src=new path ("C:\\Test.txt"); Path dst=new path ("/"); Hdfs.copyfromlocalfile (SRC,DST); System.out.println ("Upload to" +conf.get ("Fs.defualt.name")); Filestatus Files[]=hdfs.liststatus (DST); for (Filestatus file:files) {System.out.println (File.getpath ());}}Create an HDFs filethrough filesystem. Create (Pathf) The file can be created on HDFs, where F is the full path to the file. Import org.apache.hadoop.conf.Configuration; Import Org.apache.hadoop.fs.FileStatus; Import Org.apache.hadoop.fs.FileSystem; Import Org.apache.hadoop.fs.Path; public class createfile{public static void Main (string[] args) throws exception{configuration Conf=new configuration () ; byte[] buff= "Hello". GetBytes (); FileSystem hdfs=filesystem.get (conf); Path dfs=new path ("/test"); Fsdataoutputstream outputstream=hdfs.create (DFS); Outputstream.write (Buff,0,buff.length);}}Renaming an HDFs filethroughFilesystem.rename (Path Src,path DST)can be specified for theHdfsfile Rename, whereSrcand theDstare the full path to the file. DeleteHdfson the filethroughFilesystem.delete (Path F,boolean recursive)You can delete the specifiedHdfsfile, whereFfor the full path of the file to be deleted,Recursiveused to determine whether recursive deletions are performed. ViewHdfslast modified time of filethroughFilestatus.getmodificationtime ()can view the specifiedHdfsthe time the file was modified. View aHdfswhether the file existsthroughFilesystem.exists (Path f)to view the specifiedHdfswhether the file exists, whereFthe full path to the file. view a file'sHdfsCluster LocationthroughFilesystem.getfileblocklocation (filestatus file,long start,long len)to find the specified file in theHdfsthe location on the cluster, whereFileis the full path to the file,Startand theLento identify the path to the lookup file. GetHdfsall node names on the clusterthroughDatanodeinfo.gethostname ()to getHdfsthe name of all nodes on the cluster. For more highlights, please pay attention to: http://bbs.superwu.cn attention to Superman academy QR Code:
HDFs Architecture Introduction and Java API usage