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

Example Analysis of NameNode Block report processing in HDFS2.X

2025-03-31 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

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

This article mainly introduces the example analysis of NameNode block report processing in HDFS2.X, which has a certain reference value, and interested friends can refer to it. I hope you will gain a lot after reading this article.

NameNode will receive block reports in two cases, DataNode all block reports and incremental block reports.

4.1 full report Analysis

At present, full reports are reported periodically, since there are already full block reports at startup, error block reports, incremental block reports (including delete block reports), why do you need periodic full block reports? At the same time, for example, each block report will clean up the block list maintained by the DatanodeDescriptor object and the information of a certain block, but the DN node will never report it again. Regularly clearing these invalid information will help to improve the operational performance of the block list, thus providing the performance of NameNode. At the same time, we can consider and analyze whether there are other reasons that may affect the performance of NameNode.

So how to improve the start-up speed?

For the first block report, the code invocation process is: NameNodeRpcServer.blockReport ()-> BlockManager. ProcessReport ()-> BlockManager.processFirstBlockReport (). For the Standby node, if the reported metadata log related to the data block has not been loaded from the node, the reported block information will be added to a queue, and when the Standby node loads the metadata, the message queue will be processed. The detailed code for the first block report processing is as follows. You can see that in order to improve the reporting speed, there are only a few simple steps for block report processing, and only to verify whether the block is damaged. Then directly determine whether the block state is FINALIZED state, and if so, directly establish the mapping between the block and the DN node.

[java] view plain copy

Private void processFirstBlockReport (final DatanodeDescriptor node

Final BlockListAsLongs report) throws IOException {

If (report = = null) return

Assert (namesystem.hasWriteLock ())

Assert (node.numBlocks () = = 0)

BlockReportIterator itBR = report.getBlockReportIterator ()

While (itBR.hasNext ()) {

Block iblk = itBR.next ()

ReplicaState reportedState = itBR.getCurrentReplicaState ()

/ / for slave nodes, shouldPostponeBlocksFromFuture is true; to determine whether the block timestamp / / is greater than the current time.

If (shouldPostponeBlocksFromFuture&&

Namesystem.isGenStampInFuture (iblk.getGenerationStamp ()) {

/ / add the block information to the queue, and the queue will be processed after the relevant logs are digested from the node.

QueueReportedBlock (node, iblk, reportedState

QUEUE_REASON_FUTURE_GENSTAMP)

Continue

}

BlockInfo storedBlock = blocksMap.getStoredBlock (iblk)

/ / If block does not belong to any file, we are done.

If (storedBlock = = null) continue

/ / If block is corrupt, mark it and continue to next block.

BlockUCState ucState = storedBlock.getBlockUCState ()

BlockToMarkCorrupt c = checkReplicaCorrupt (

Iblk, reportedState, storedBlock, ucState, node)

If (c! = null) {

/ / for slave nodes, add the block information to the pendingDNMessages queue first

/ / add the block information to the queue, and after digesting the relevant logs from the node, the queue will be processed. If the block is still damaged, it is really damaged.

If (shouldPostponeBlocksFromFuture) {

/ / In the Standby, we may receive a block report for a file that we

/ / just have an out-of-date gen-stamp or state for, for example.

QueueReportedBlock (node, iblk, reportedState

QUEUE_REASON_CORRUPT_STATE)

} else {

/ / for the primary node, a block is damaged and directly marked as damaged

MarkBlockAsCorrupt (c, node)

}

Continue

}

/ / If block is under construction, add this replica to its list

If (isBlockUnderConstruction (storedBlock, ucState, reportedState)) {

((BlockInfoUnderConstruction) storedBlock) .addReplicaIfNotPresent

Node, iblk, reportedState)

/ / and fall through to next clause

}

/ / add replica if appropriate

If (reportedState = = ReplicaState.FINALIZED) {

AddStoredBlockImmediate (storedBlock, node)

}

}

}

For the non-first block report, the situation is more complicated. For each block information reported, not only the mapping between the block and DN is established, but also whether the block is damaged, whether the block is invalid, whether the metadata has been invalid should be deleted, whether it is a block with UC status, etc., this process is mainly completed by the method processReport.

[java] view plain copy

Private void processReport (final DatanodeDescriptor node

Final BlockListAsLongs report) throws IOException {

/ / Normal case:

/ / Modify the (block-- > datanode) map, according to the difference

/ / between the old and new block report.

/ /

Collection toAdd = new LinkedList ()

Collection toRemove = new LinkedList ()

Collection toInvalidate = new LinkedList ()

Collection toCorrupt = new LinkedList ()

Collection toUC = new LinkedList ()

/ / count blocks and determine whether blocks should be deleted, whether they should be added to the blocksMap list, etc.

ReportDiff (node, report, toAdd, toRemove, toInvalidate, toCorrupt, toUC)

/ / Process the blocks on each queue

For (StatefulBlockInfo b: toUC) {

AddStoredBlockUnderConstruction (b.storedBlock, node, b.reportedState)

}

For (Block b: toRemove) {

RemoveStoredBlock (b, node)

}

For (BlockInfo b: toAdd) {

AddStoredBlock (b, node, null, true)

}

For (Block b: toInvalidate) {

NameNode.stateChangeLog.info ("BLOCK* processReport: block"

+ b + "on" + node + "size" + b.getNumBytes ()

+ "does not belong to any file.")

AddToInvalidates (b, node)

}

For (BlockToMarkCorrupt b: toCorrupt) {

MarkBlockAsCorrupt (b, node)

}

}

Within the reportDiff method, the implementation is as follows:

[java] view plain copy

Private void reportDiff (DatanodeDescriptor dn

BlockListAsLongs newReport

Collection toAdd, / / add to DatanodeDescriptor

Collection toRemove, / / remove from DatanodeDescriptor

Collection toInvalidate, / / should be removed from DN

Collection toCorrupt, / / add to corrupt replicas list

Collection toUC) {/ / add to under-construction list

/ / place a delimiter delimiter in the list which separates blocks

/ / that have been reported from those that have not

BlockInfo delimiter = new BlockInfo (new Block (), 1)

Boolean added = dn.addBlock (delimiter)

Assert added: "Delimiting block cannot be present in the node"

Int headIndex = 0; / / currently the delimiter is in the head of the list

Int curIndex

If (newReport = = null)

NewReport = new BlockListAsLongs ()

/ / scan the report and process newly reported blocks

BlockReportIterator itBR = newReport.getBlockReportIterator ()

While (itBR.hasNext ()) {

Block iblk = itBR.next ()

ReplicaState iState = itBR.getCurrentReplicaState ()

BlockInfo storedBlock = processReportedBlock (dn, iblk, iState

ToAdd, toInvalidate, toCorrupt, toUC)

/ / move block to the head of the list

If (storedBlock! = null & & (curIndex = storedBlock.findDatanode (dn)) > = 0) {

HeadIndex = dn.moveBlockToHead (storedBlock, curIndex, headIndex)

}

}

/ / collect blocks that have not been reported

/ / all of them are next to the delimiter

/ / collect all the blocks in the DN object that have not been reported by the DN node, and delete these block information from the list maintained by the DN object, which can effectively control the existence of a large number of invalid blocks in the DN block list.

/ / affect the operational performance of NameNode

Iterator

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

Internet Technology

Wechat

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

12
Report