input
stringlengths
10
828
output
stringlengths
5
107
public datanode descriptor choose random string scope if scope starts with return choose random node base root scope substring 1 else return choose random scope null
randomly choose one node from i scope i
public boolean exists path f throws ioexception return fs exists f
check if exists
public boolean is directory path f throws ioexception return fs is directory f
true iff the named path is a directory
public long get length path f throws ioexception return fs get length f
the number of bytes in a file
protected void set user job conf props boolean do early props iterator it user job conf props key set iterator while it has next string key string it next string val string user job conf props get key boolean early name key equals fs default name early name key equals stream shipped hadoopstreaming if do early props early name msg xxx job conf set key val early do early props job conf set key val
this method sets the user jobconf variable specified
public boolean mkdirs path f throws ioexception return fs mkdirs f
make the given file and all non existent parents into directories
public long get checksum file length path file long file size return fsoutput summer get checksum length file size get bytes per sum
return the length of the checksum file given the size of the
public int get bytes per sum return get conf get int io bytes per checksum 512
return the bytes per checksum
public string to string print the number of racks string buffer tree new string buffer tree append number of racks tree append num of racks tree append n print the number of leaves int num of leaves get num of leaves tree append expected number of leaves tree append num of leaves tree append n print datanodes for int i 0 i num of leaves i tree append cluster map get leaf i null get path tree append n return tree to string
convert a network tree to a string
public long get block size path f throws ioexception return fs get block size f
get the block size for a particular file
public short get replication path f throws ioexception return 1
replication is not supported for the local file system
public void checkpoint throws ioexception if fs exists current no trash no checkpoint return path checkpoint synchronized checkpoint checkpoint new path root checkpoint format new date if fs rename current checkpoint log info created trash checkpoint checkpoint else throw new ioexception failed to checkpoint trash checkpoint
create a trash checkpoint
private void copy bytes input stream in output stream out throws ioexception print stream ps out instanceof print stream print stream out null byte buf new byte conf get int io file buffer size 4096 int bytes read in read buf while bytes read 0 out write buf 0 bytes read if ps null ps check error throw new ioexception unable to write to output stream bytes read in read buf
copies from one stream to another
public short get replication path src throws ioexception return 1
replication is not supported for the inmemory file system
public path make qualified path path check path path if path is absolute path new path get working directory path uri path uri path to uri uri fs uri get uri string scheme path uri get scheme string authority path uri get authority if scheme null authority null fs uri get authority null return path if scheme null scheme fs uri get scheme if authority null authority fs uri get authority if authority null authority return new path scheme authority path uri get path
make sure that a path specifies a file system
private void copy from stdin path dst throws ioexception if fs is directory dst throw new ioexception when source is stdin destination must be a file if fs exists dst throw new ioexception target dst to string already exists fsdata output stream out fs create dst try copy bytes system in out finally out close
copies from stdin to the indicated file
protected void check path path path uri uri path to uri if uri get scheme null fs is relative return string this authority this get uri get authority string that authority uri get authority if this get uri get scheme equals uri get scheme this authority null that authority null this authority equals that authority throw new illegal argument exception wrong fs path expected this get uri
check that a path belongs to this file system
private void print to stdout path src throws ioexception if fs is directory src throw new ioexception source must be a file fsdata input stream in fs open src try copy bytes in system out finally in close
print from src to stdout
private void set replication string cmd int pos throws ioexception if cmd length pos 2 cmd length pos 2 cmd pos equals ignore case r system err println usage r repvalue path system exit 1 boolean recursive false short rep 3 if r equals ignore case cmd pos recursive true pos try rep short parse short cmd pos pos catch number format exception e system err println cannot set replication to cmd pos system exit 1 set replication rep cmd pos recursive
parse the incoming command string
public boolean is directory path f throws ioexception return is file f
directory operations are not supported
public fsdata output stream create path f throws ioexception return create f true get conf get int io file buffer size 4096 get default replication get default block size
opens an fsdata output stream at the indicated path
private void set file replication path file short new rep throws ioexception if fs set replication file new rep system out println replication new rep set file else system err println could not set replication for file
actually set the replication for this file
public void lock path f boolean shared throws ioexception
lock operations are not supported
public progress add phase progress phase new progress phases add phase phase parent this progress per phase 1 0f float phases size return phase
adds a node to the tree
public progress phase return progress phases get current phase
returns the current sub node executing
public void set writable obj instance obj class clazzes get types for int i 0 i clazzes length i class clazz clazzes i if clazz is instance instance type byte i return throw new runtime exception the type of instance is instance get class which is not registered
set the instance that is wrapped
public void complete progress 1 0f if parent null parent start next phase
completes this node moving the parent node to its next child
public void set float progress this progress progress
called during execution on a leaf node to set its progress
public float get progress node this while node parent null find the root node parent return node get internal
returns the overall progress of the root
private float get internal int phase count phases size if phase count 0 float sub progress current phase phase count phase get internal 0 0f return progress per phase current phase sub progress else return progress
computes progress in this node
public void dus string src throws ioexception path paths fs glob paths new path src if paths null paths length 0 throw new ioexception dus no match src for int i 0 i paths length i path items fs list paths paths i if items null int total size 0 for int j 0 j items length j total size fs get content length items j string path str paths i to string system out println equals path str path str t total size
show the summary disk usage of each dir file
static public compression type get compression type configuration job string name job get io seqfile compression type return name null compression type record compression type value of name
get the compression type for the reduce outputs
public boolean is file path f throws ioexception if exists f is directory f return true else return false
true iff the named path is a regular file
public void mkdir string src throws ioexception path f new path src if fs mkdirs f throw new ioexception mkdirs failed to create src
create the given dir
public boolean reserve space path f int size synchronized this if can fit in memory size return false file attributes file attr try file attr new file attributes size catch out of memory error o return false total used size temp file attribs put get path f file attr return true
register a path with its size
public long get content length path f throws ioexception if is directory f f is a file return get length f f is a diretory path contents list paths f long size 0 for int i 0 i contents length i size get content length contents i return size
return the number of bytes of the given path
public void rename string srcf string dstf throws ioexception path srcs fs glob paths new path srcf path dst new path dstf if srcs length 1 fs is directory dst throw new ioexception when moving multiple files destination should be a directory for int i 0 i srcs length i if fs rename srcs i dst system out println renamed srcs i to dstf else throw new ioexception rename failed srcs i
move files that match the file pattern i srcf i
public boolean delete path f throws ioexception if fs is directory f return fs delete f else path check file get checksum file f if fs exists check file fs delete check file return fs delete f
get rid of path f whether a true file or dir
public string get default extension return deflate
get the default filename extension for this kind of compression
public void copy string srcf string dstf configuration conf throws ioexception path srcs fs glob paths new path srcf path dst new path dstf if srcs length 1 fs is directory dst throw new ioexception when copying multiple files destination should be a directory for int i 0 i srcs length i file util copy fs srcs i fs dst false conf
copy files that match the file pattern i srcf i
public void delete string srcf boolean recursive throws ioexception path srcs fs glob paths new path srcf for int i 0 i srcs length i delete srcs i recursive
delete all files that match the file pattern i srcf i
public string get default extension return gz
get the default filename extension for this kind of compression
public void set byte new data int offset int length set size 0 set size length system arraycopy new data 0 bytes 0 size
set the value to a copy of the given byte range
public boolean reserve space with check sum path f int size get the size of the checksum file we know it is going to be int since this is an inmem fs with file sizes that will fit in 4 bytes long checksum size get checksum file length f size raw in memory file system mfs raw in memory file system get raw file system synchronized mfs return mfs reserve space f size mfs reserve space get checksum file f int get checksum file length f size
register a file with its size
public string to string string buffer sb new string buffer 3 size for int idx 0 idx size idx if not the first put a blank separator in if idx 0 sb append string num integer to hex string int bytes idx if it is only one digit add a leading 0 if num length 2 sb append 0 sb append num return sb to string
generate the stream of bytes as hex pairs separated by
public void close throws ioexception uri uri get uri synchronized file system class map string file system authority to fs cache get uri get scheme if authority to fs null authority to fs remove uri get authority
no more filesystem operations are needed
public void set text other set other bytes 0 other length
copy a text
public long get used throws ioexception long used 0 path files list paths new path for path file files used get content length file return used
return the total size of all files in the filesystem
public string to string try return decode bytes 0 length catch character coding exception e return null
convert text back to string
private void lock int idx throws ioexception random access file file random access file storage files get idx file lock lock file get channel try lock if lock null log a warning log warn cannot lock storage file in directory orig dirs idx get name remove the file from file list and close it storage files add idx null file close storage locks add idx lock
lock datastorage file
private void unlock int idx throws ioexception file lock lock file lock storage locks get idx if lock null lock release
unlock datastorage file
private void close int idx throws ioexception file lock lock file lock storage locks get idx if lock null return lock release random access file file random access file storage files get idx file close
close a datastorage file
public void close all throws ioexception for int idx 0 idx dirs length idx close idx
close all datastorage files
private boolean read int idx throws ioexception random access file file random access file storage files get idx if file null return false file seek 0 this version file read int this storage id utf8 read string file return false
read data storage file
private void write int idx throws ioexception random access file file random access file storage files get idx if file null return file seek 0 file write int this version utf8 write string file this storage id
write data storage file
public void write all throws ioexception for int idx 0 idx dirs length idx write idx
write all data storage files
public void shutdown should run false try info server stop catch exception e
shut down this instance of the datanode
synchronized public boolean is dir return blocks null
check whether its a directory
private void get fsimage throws ioexception string fs name get info server string fileid getimage 1 transfer fs image get file client fs name fileid src image log info downloaded file src image size src image length bytes
get the current fsimage from namenode
public long get block size if blocks null blocks length 0 return 0 else return blocks 0 get num bytes
get the block size of the first block
public void do updates metrics context unused synchronized this metrics record incr metric files created num files created metrics record incr metric files opened num files opened metrics record incr metric files renamed num files renamed metrics record incr metric files listed num files listed num files created 0 num files opened 0 num files renamed 0 num files listed 0 metrics record update
since this object is a registered updater this method will be called
private void get fsedits throws ioexception string fs name get info server string fileid getedit 1 transfer fs image get file client fs name fileid edit file log info downloaded file edit file size edit file length bytes
get the old edits file from the name node
private void put fsimage throws ioexception string fs name get info server string fileid putimage 1 port info port machine inet address get local host get host address log info posted url fs name fileid transfer fs image get file client fs name fileid file null
copy the new fsimage into the name node
private void do merge throws ioexception fsimage fs image new fsimage checkpoint dir fs edits fsnamesystem namesystem new fsnamesystem fs image fs image load fsimage conf src image fs image get edit log load fsedits conf edit file fs image save fsimage dest fs image
merges src fs image with fs edits and writes the output into
public void do updates metrics context unused synchronized this metrics record incr metric bytes read bytes read metrics record incr metric bytes written bytes written metrics record incr metric blocks read blocks read metrics record incr metric blocks written blocks written metrics record incr metric blocks replicated blocks replicated metrics record incr metric blocks removed blocks removed bytes written 0 bytes read 0 blocks written 0 blocks read 0 blocks replicated 0 blocks removed 0 metrics record update
since this object is a registered updater this method will be called
public void close throws ioexception fs image get edit log close
shutdown the filestore
public void stop if stop requested stop requested true namesystem close emptier interrupt server stop
stop all name node threads and wait for all to finish
public void fsck throws ioexception try dfsfile info files nn get listing path fsck result res new fsck result res set replication short conf get int dfs replication 3 if files null for int i 0 i files length i check files i res out println res if res is healthy out println n n the filesystem under path path is healthy else out println n n the filesystem under path path is corrupt else out println n n path path does not exist finally out close
check files on dfs starting from the indicated path
public void get block info tree set block block set if children null for int i 0 i children length i children i get block info block set file block files dir list files for int i 0 i block files length i if block is block filename block files i block set add new block block files i block files i length
populate the given block set with any child blocks
public boolean rename to utf8 src utf8 dst name node state change log debug dir fsdirectory rename to src to dst wait for ready if unprotected rename to src dst return false fs image get edit log log rename src dst return true
change the filename
public boolean delete path f throws ioexception return dfs delete get path f
get rid of path f whether a true file or dir
public long get block size string filename throws ioexception synchronized root dir inode file node root dir get node filename if file node null throw new ioexception unknown file filename if file node is dir throw new ioexception getting block size of a directory filename return file node get block size
get the blocksize of a file
public void report written block located block lb throws ioexception block b lb get block datanode info targets lb get locations state change log debug block name node report written block b get block name is written to targets length locations for int i 0 i targets length i namesystem block received targets i b
the client can report in a set written blocks that it wrote
public boolean is healthy return missing ids size 0
dfs is considered healthy if there are no missing blocks
public void shutdown try info server stop catch exception e this should run false data xceive server this data xceive server get runnable kill try this storage close all catch ioexception ie
shut down this instance of the datanode
public void abandon block block b string src throws ioexception state change log debug block name node abandon block b get block name of file src if namesystem abandon block b new utf8 src throw new ioexception cannot abandon block during write to src
the client needs to give up on the block
public array list get missing ids return missing ids
return a list of missing block names as list of strings
private int new namespace id random r new random r set seed system current time millis int new id 0 while new id 0 new id r next int return new id
generate new namespace id
public boolean is dir utf8 src synchronized root dir inode node root dir get node normalize path src return node null node is dir
check whether the path specifies a directory
public long get over replicated blocks return over replicated blocks
return the number of over replicated blocks
public void close synchronized this fs running false try pending replications stop info server stop hbthread join 3000 replthread join 3000 dnthread join 3000 catch interrupted exception ie finally using finally to ensure we also wait for lease daemon try lmthread join 3000 catch interrupted exception ie finally try dir close catch ioexception ex do nothing
close down this filesystem manager
public void report bad blocks located block blocks throws ioexception state change log debug dir name node report bad blocks for int i 0 i blocks length i block blk blocks i get block datanode info nodes blocks i get locations for int j 0 j nodes length j datanode info dn nodes j namesystem invalidate block blk dn
the client has detected an error on the specified located blocks
public boolean is valid block block b synchronized root dir if active blocks contains key b return true else return false
returns whether the given block is one pointed to by a file
public void write data output out throws ioexception datanode id id new datanode id node get name node get storage id node get info port id write out out write long node get capacity out write long node get remaining out write long node get last update out write int node get xceiver count
public method that serializes the information about a
public float get replication factor if total blocks 0 return float total blocks replication over replicated blocks under replicated blocks float total blocks else return 0 0f
return the actual replication factor
public long get under replicated blocks return under replicated blocks
return the number of under replicated blocks
public inode get file by block block b synchronized root dir return inode active blocks get b
returns whether the given block is one pointed to by a file
public boolean is valid block block b file f get file b return f null f exists
check whether the given block is a valid one
public int refresh nodes throws ioexception int exit code 1 if fs instanceof distributed file system system out println file system is fs get name return exit code distributed file system dfs distributed file system fs dfs refresh nodes exit code 0 return exit code
command to ask the namenode to reread the hosts and excluded hosts
public void print usage string cmd if report equals cmd system err println usage java dfsadmin report else if safemode equals cmd system err println usage java dfsadmin safemode enter leave get wait else if refresh nodes equals cmd system err println usage java dfsadmin refresh nodes else system err println usage java dfsadmin system err println report system err println safemode enter leave get wait system err println refresh nodes
displays format of commands
public long get block size return block size
get the block size of the file
public void close throws ioexception synchronize in here so that we don t need to change the api synchronized this check open synchronized pending creates iterator file itr pending creates key set iterator while file itr has next string name string file itr next try namenode abandon file in progress name client name catch ioexception ie system err println exception abandoning create lock on name ie print stack trace pending creates clear this running false try lease checker join catch interrupted exception ie
close the file system abadoning all of the leases and files being
public long get raw capacity throws ioexception return raw distributed file system fs get raw capacity
return the total raw capacity of the filesystem disregarding
public long get raw used throws ioexception return raw distributed file system fs get raw used
return the total raw used space in the filesystem disregarding
public dfsinput stream open utf8 src throws ioexception check open get block info from namenode return new dfsinput stream src to string
create an input stream that obtains a nodelist from the
public boolean prepare throws ioexception task std out log writer init initialize the child task s stdout log task std err log writer init initialize the child task s stderr log return true
called to assemble this tasks input
public long get shuffle finish time return shuffle finish time
get shuffle finish time for the task
public long get sort finish time return sort finish time
get sort finish time for the task
public void kill if process null process destroy killed true
kill the child process
public void roll edit log throws ioexception namesystem roll edit log
roll the edit log