Get the App
SLTechnology News&Howtos  ›  Servers  › 

What is the function of addBlock function in HDFS

Shulou Source: shulou.com Published: 2022-06-01 18:16:03 10月23日 Update

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.

Tags: Functions files functions errors information content skills times knowledge nodes analysis minimum concise important and then anyway concise number of copies key Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Huawei MariaDB Shulou Information Redmi vpn