Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What is the function of exists function in HDFS

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/01 Report--

In this issue, the editor will bring you about the role of the exists function in HDFS. The article is rich in content and analyzes and describes it from a professional point of view. I hope you can get something after reading this article.

/ * *

, /

Public boolean exists (String src) throws IOException {

Return namesystem.exists (new UTF8 (src)); / / call namesystem directly.

}

So let's take a look at how namesystem judges.

Public boolean exists (UTF8 src) {

If (dir.getFile (src)! = null | | dir.isDir (src)) {

Return true;// can see from this that either it does exist, if it doesn't exist and it's a directory.

} else {

Return false

}

}

Analyze getFile (...) first. Function.

-

Public Block [] getFile (UTF8 src) {

WaitForReady ()

Synchronized (rootDir) {

INode targetNode = rootDir.getNode (src.toString ()); / / get node

If (targetNode = = null) {

Return null;// node does not exist

} else {

Return targetNode.blocks;// node exists and returns file block information

}

}

}

-continue to analyze getNode

INode getNode (String target) {

If (! Target.startsWith ("/") | | target.length () = = 0) {

Is the return null;// path standardized?

} else if (parent = = null & & "/" .equals (target)) {

Whether return this;// is the root directory

} else {

Vector components = new Vector ()

Int start = 0

Int slashid = 0

While (start

< target.length() && (slashid = target.indexOf('/', start)) >

= 0) {

Components.add (target.substring (start, slashid))

Start = slashid + 1

}

If (start < target.length ()) {

Components.add (target.substring (start))

}

Return getNode (components, 0); / / enable recursive lookup mode

}

}

-

INode getNode (Vector components, int index) {

If (! Name.equals ((String) components.elementAt (index) {

Is the name of return null;// 's current INode OK?

}

If (index = = components.size ()-1) {

Return this;// has reached the last item.

}

/ / Check with children

INode child = (INode) children.get (components.elementAt (index+1)); / / find the corresponding INode from the children according to the file name, and then find it recursively

If (child = = null) {

Return null

} else {

Return child.getNode (components, index+1)

}

}

-OK, then analyze the isDir function

Public boolean isDir (UTF8 src) {

Synchronized (rootDir) {

INode node = rootDir.getNode (normalizePath (src))

Return node! = null & & node.isDir ()

}

}

The above is the role of the exists function in HDFS shared by Xiaobian. If you happen to have similar doubts, you might as well refer to the above analysis to understand. If you want to know more about it, you are welcome to follow the industry information channel.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report