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 addBlock function in HDFS

2025-02-25 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

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

This article shows you what the function of addBlock in HDFS is. The content is concise and easy to understand. It can definitely brighten your eyes. I hope you can get something through the detailed introduction of this article.

Public LocatedBlock addBlock (String src, String clientMachine) throws IOException {

Int retries = 5 / set the number of retries to 5

Object results [] = namesystem.getAdditionalBlock (new UTF8 (src), new UTF8 (clientMachine))

/ / get a new Block and DataNode node information

While (results! = null & & results [0] = = null & & retries > 0) {

If an error occurs in try {/ / and does not exceed the number of errors, it will be retrieved.

Thread.sleep (100)

} catch (InterruptedException ie) {

}

Results = namesystem.getAdditionalBlock (new UTF8 (src), new UTF8 (clientMachine))

Retries--

}

/ / anyway, it's over!

If (results = = null) {/ / not found? Return error

Throw new IOException ("Cannot obtain additional block for file" + src)

} else if (results [0] = = null) {

Return null;// doesn't have Block? Return to null

} else {

Block b = (Block) results [0]

DatanodeInfo targets [] = (DatanodeInfo []) results [1]

Return new LocatedBlock (b, targets); / / this is simple and returns Block and DatanodeInfo

}

}

=

C1:OKAY c2:OKAY c3:OKAY

=

Let's start with the explanation.

Public synchronized Object [] getAdditionalBlock (UTF8 src, UTF8 clientMachine) {

-

Public synchronized Object [] getAdditionalBlock (UTF8 src, UTF8 clientMachine) {

Object results [] = null

If (dir.getFile (src) = = null & & pendingCreates.get (src)! = null) {

/ / this file does not exist in the file system dir and is in the process of being created

Results = new Object [2]; / / create an array of returned variables

/ /

/ / If we fail this, bad things happen!

/ / the checkFileProgress here is critical.

/ / the role of checkFileProgress will be analyzed later.

If (checkFileProgress (src)) {

/ / Get the array of replication targets / / this is still very simple. It has been analyzed before.

DatanodeInfo targets [] = chooseTargets (this.desiredReplication, null, clientMachine)

If (targets.length < this.minReplication) {

Return null

}

/ / Create next block returns not to say much!

Results [0] = allocateBlock (src)

Results [1] = targets

}

}

Return results

}

=

And then there's the function.

Synchronized boolean checkFileProgress (UTF8 src) {

This function is still very important!

/ * *

* Check that the indicated file's blocks are present and

* replicated. If not, return false.

, /

Synchronized boolean checkFileProgress (UTF8 src) {

Vector v = (Vector) pendingCreates.get (src); / / get each block corresponding to the file name src

For (Iterator it = v.iterator (); it.hasNext ();) {

Block b = (Block) it.next (); / / for the current block

TreeSet containingNodes = (TreeSet) blocksMap.get (b); / / get the datanode node information corresponding to this block

If (containingNodes = = null | | containingNodes.size () < this.minReplication) {

Return false;//. If the number of datanode corresponding to this Block is less than the minimum number of backups, the Block is prohibited.

}

}

Return true;// successfully returned to true.

}

The above is what is the function of addBlock function in HDFS. Have you learned any knowledge or skills? If you want to learn more skills or enrich your knowledge reserve, 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