idx int64 0 41.2k | question stringlengths 73 5.81k | target stringlengths 5 918 |
|---|---|---|
33,100 | void internalReleaseLease ( Lease lease , String src , INodeFileUnderConstruction pendingFile ) throws IOException { if ( lease . hasPath ( ) ) { String [ ] leasePaths = new String [ lease . getPaths ( ) . size ( ) ] ; lease . getPaths ( ) . toArray ( leasePaths ) ; LOG . info ( "Recovering lease: " + lease + " for paths " + Arrays . toString ( leasePaths ) ) ; for ( String p : leasePaths ) { internalReleaseLeaseOne ( lease , p ) ; } } else { internalReleaseLeaseOne ( lease , src , pendingFile , false ) ; } } | This is invoked when a lease expires . On lease expiry all the files that were written from that dfsclient should be recovered . |
33,101 | private boolean discardDone ( INodeFileUnderConstruction pendingFile , String src ) throws IOException { Block [ ] blocks = pendingFile . getBlocks ( ) ; if ( blocks == null || blocks . length == 0 ) { return false ; } Block last = blocks [ blocks . length - 1 ] ; if ( last . getNumBytes ( ) == 0 ) { dir . removeBlock ( src , pendingFile , last ) ; finalizeINodeFileUnderConstruction ( src , pendingFile ) ; NameNode . stateChangeLog . warn ( "BLOCK*" + " internalReleaseLease: discarded last block " + last + " , lease removed for " + src ) ; return true ; } return false ; } | the last block completely . |
33,102 | void updatePipeline ( String clientName , Block oldBlock , Block newBlock , List < DatanodeID > newNodes ) throws IOException { LOG . info ( "updatePipeline(block=" + oldBlock + ", newGenerationStamp=" + newBlock . getGenerationStamp ( ) + ", newLength=" + newBlock . getNumBytes ( ) + ", newNodes=" + newNodes + ")" ) ; writeLock ( ) ; try { final INodeFileUnderConstruction pendingFile = checkUCBlock ( oldBlock , clientName ) ; final Block oldBlockInfo = pendingFile . getLastBlock ( ) ; if ( newBlock . getGenerationStamp ( ) == oldBlockInfo . getGenerationStamp ( ) ) { String msg = "Update " + oldBlock + " (len = " + oldBlockInfo . getNumBytes ( ) + ") to a same generation stamp: " + newBlock + " (len = " + newBlock . getNumBytes ( ) + ")" ; LOG . warn ( msg ) ; return ; } if ( newBlock . getGenerationStamp ( ) < oldBlockInfo . getGenerationStamp ( ) || newBlock . getNumBytes ( ) < oldBlockInfo . getNumBytes ( ) ) { String msg = "Update " + oldBlock + " (len = " + oldBlockInfo . getNumBytes ( ) + ") to an older state: " + newBlock + " (len = " + newBlock . getNumBytes ( ) + ")" ; LOG . warn ( msg ) ; throw new IOException ( msg ) ; } blocksMap . removeBlock ( oldBlockInfo ) ; BlockInfo newBlockInfo = blocksMap . addINode ( newBlock , pendingFile , pendingFile . getReplication ( ) ) ; DatanodeDescriptor [ ] descriptors = null ; if ( ! newNodes . isEmpty ( ) ) { descriptors = new DatanodeDescriptor [ newNodes . size ( ) ] ; for ( int i = 0 ; i < newNodes . size ( ) ; i ++ ) { descriptors [ i ] = getDatanode ( newNodes . get ( i ) ) ; } } pendingFile . setLastBlock ( newBlockInfo , descriptors ) ; String src = leaseManager . findPath ( pendingFile ) ; if ( supportAppends ) { dir . persistBlocks ( src , pendingFile ) ; } } finally { writeUnlock ( ) ; } if ( supportAppends ) { getEditLog ( ) . logSync ( ) ; } LOG . info ( "updatePipeline(" + oldBlock + ") successfully to " + newBlock ) ; } | Update a pipeline for a block under construction |
33,103 | private String newStorageID ( ) { String newID = null ; while ( newID == null ) { newID = "DS" + Integer . toString ( r . nextInt ( ) ) ; if ( datanodeMap . get ( newID ) != null ) { newID = null ; } } return newID ; } | Generate new storage ID . |
33,104 | public int computeDatanodeWork ( ) throws IOException { int workFound = 0 ; int blocksToProcess = 0 ; int nodesToProcess = 0 ; if ( isInSafeMode ( ) ) { updateReplicationCounts ( workFound ) ; return workFound ; } synchronized ( heartbeats ) { blocksToProcess = ( int ) ( heartbeats . size ( ) * ReplicationConfigKeys . replicationWorkMultiplier ) ; nodesToProcess = ( int ) Math . ceil ( ( double ) heartbeats . size ( ) * ReplicationConfigKeys . INVALIDATE_WORK_PCT_PER_ITERATION / 100 ) ; } workFound = computeReplicationWork ( blocksToProcess ) ; updateReplicationCounts ( workFound ) ; workFound += computeInvalidateWork ( nodesToProcess ) ; return workFound ; } | Compute block replication and block invalidation work that can be scheduled on data - nodes . The datanode will be informed of this work at the next heartbeat . |
33,105 | int computeInvalidateWork ( int nodesToProcess ) { int numOfNodes = 0 ; ArrayList < String > keyArray = null ; readLock ( ) ; try { numOfNodes = recentInvalidateSets . size ( ) ; keyArray = new ArrayList < String > ( recentInvalidateSets . keySet ( ) ) ; } finally { readUnlock ( ) ; } nodesToProcess = Math . min ( numOfNodes , nodesToProcess ) ; int remainingNodes = numOfNodes - nodesToProcess ; if ( nodesToProcess < remainingNodes ) { for ( int i = 0 ; i < nodesToProcess ; i ++ ) { int keyIndex = r . nextInt ( numOfNodes - i ) + i ; Collections . swap ( keyArray , keyIndex , i ) ; } } else { for ( int i = 0 ; i < remainingNodes ; i ++ ) { int keyIndex = r . nextInt ( numOfNodes - i ) ; Collections . swap ( keyArray , keyIndex , numOfNodes - i - 1 ) ; } } int blockCnt = 0 ; for ( int nodeCnt = 0 ; nodeCnt < nodesToProcess ; nodeCnt ++ ) { blockCnt += invalidateWorkForOneNode ( keyArray . get ( nodeCnt ) ) ; } return blockCnt ; } | Schedule blocks for deletion at datanodes |
33,106 | private int getQuotaForThisPriority ( int totalQuota , int blocksForThisPriority , int blocksForLowerPriorities ) { int quotaForLowerPriorities = Math . min ( totalQuota / 5 , blocksForLowerPriorities ) ; return Math . min ( blocksForThisPriority , totalQuota - quotaForLowerPriorities ) ; } | Decide the number of blocks to replicate on for this priority . The heuristic is that allocate at most 20% the quota for lower priority blocks |
33,107 | List < List < BlockInfo > > chooseUnderReplicatedBlocks ( int blocksToProcess ) { List < List < BlockInfo > > blocksToReplicate = new ArrayList < List < BlockInfo > > ( UnderReplicatedBlocks . LEVEL ) ; for ( int i = 0 ; i < UnderReplicatedBlocks . LEVEL ; i ++ ) { blocksToReplicate . add ( new ArrayList < BlockInfo > ( ) ) ; } writeLock ( ) ; try { synchronized ( neededReplications ) { if ( neededReplications . size ( ) == 0 ) { return blocksToReplicate ; } for ( int priority = 0 ; priority < UnderReplicatedBlocks . LEVEL ; priority ++ ) { BlockIterator neededReplicationsIterator = neededReplications . iterator ( priority ) ; int numBlocks = neededReplications . size ( priority ) ; if ( replIndex [ priority ] > numBlocks ) { replIndex [ priority ] = 0 ; } for ( int i = 0 ; i < replIndex [ priority ] && neededReplicationsIterator . hasNext ( ) ; i ++ ) { neededReplicationsIterator . next ( ) ; } int blocksToProcessIter = getQuotaForThisPriority ( blocksToProcess , numBlocks , neededReplications . getSize ( priority + 1 ) ) ; blocksToProcess -= blocksToProcessIter ; for ( int blkCnt = 0 ; blkCnt < blocksToProcessIter ; blkCnt ++ , replIndex [ priority ] ++ ) { if ( ! neededReplicationsIterator . hasNext ( ) ) { replIndex [ priority ] = 0 ; neededReplicationsIterator = neededReplications . iterator ( priority ) ; assert neededReplicationsIterator . hasNext ( ) : "neededReplications should not be empty." ; } BlockInfo block = neededReplicationsIterator . next ( ) ; blocksToReplicate . get ( priority ) . add ( block ) ; } } } return blocksToReplicate ; } finally { writeUnlock ( ) ; } } | Get a list of block lists to be replicated The index of block lists represents the |
33,108 | private void updateReplicationMetrics ( List < ReplicationWork > work ) { for ( ReplicationWork rw : work ) { DatanodeDescriptor [ ] targets = rw . targets ; if ( targets == null ) continue ; for ( DatanodeDescriptor target : targets ) { if ( clusterMap . isOnSameRack ( rw . srcNode , target ) ) { myFSMetrics . numLocalRackReplications . inc ( ) ; } else { myFSMetrics . numAcrossRackReplications . inc ( ) ; } } } } | Update replication metrics |
33,109 | private DatanodeDescriptor [ ] chooseTarget ( ReplicationWork work ) { if ( ! neededReplications . contains ( work . block ) ) { return null ; } if ( work . blockSize == BlockFlags . NO_ACK ) { LOG . warn ( "Block " + work . block . getBlockId ( ) + " of the file " + getFullPathName ( work . fileINode ) + " is invalidated and cannot be replicated." ) ; return null ; } if ( work . blockSize == BlockFlags . DELETED ) { LOG . warn ( "Block " + work . block . getBlockId ( ) + " of the file " + getFullPathName ( work . fileINode ) + " is a deleted block and cannot be replicated." ) ; return null ; } return replicator . chooseTarget ( work . fileINode , work . numOfReplicas , work . srcNode , work . containingNodes , null , work . blockSize ) ; } | Wrapper function for choosing targets for replication . |
33,110 | private boolean isGoodReplica ( DatanodeDescriptor node , Block block ) { Collection < Block > excessBlocks = excessReplicateMap . get ( node . getStorageID ( ) ) ; Collection < DatanodeDescriptor > nodesCorrupt = corruptReplicas . getNodes ( block ) ; return ( nodesCorrupt == null || ! nodesCorrupt . contains ( node ) ) && ( node . getNumberOfBlocksToBeReplicated ( ) < maxReplicationStreams ) && ( excessBlocks == null || ! excessBlocks . contains ( block ) ) && ! node . isDecommissioned ( ) ; } | Decide if a replica is valid |
33,111 | void processPendingReplications ( ) { BlockInfo [ ] timedOutItems = pendingReplications . getTimedOutBlocks ( ) ; if ( timedOutItems != null ) { writeLock ( ) ; try { for ( int i = 0 ; i < timedOutItems . length ; i ++ ) { NumberReplicas num = countNodes ( timedOutItems [ i ] ) ; neededReplications . add ( timedOutItems [ i ] , num . liveReplicas ( ) , num . decommissionedReplicas ( ) , getReplication ( timedOutItems [ i ] ) ) ; } } finally { writeUnlock ( ) ; } } } | If there were any replication requests that timed out reap them and put them back into the neededReplication queue |
33,112 | void clearReplicationQueues ( ) { writeLock ( ) ; try { synchronized ( neededReplications ) { neededReplications . clear ( ) ; } underReplicatedBlocksCount = 0 ; corruptReplicas . clear ( ) ; corruptReplicaBlocksCount = 0 ; overReplicatedBlocks . clear ( ) ; raidEncodingTasks . clear ( ) ; excessReplicateMap = new HashMap < String , LightWeightHashSet < Block > > ( ) ; excessBlocksCount = 0 ; } finally { writeUnlock ( ) ; } } | Clear replication queues . This is used by standby avatar to reclaim memory . |
33,113 | void wipeDatanode ( DatanodeID nodeID ) throws IOException { String key = nodeID . getStorageID ( ) ; host2DataNodeMap . remove ( datanodeMap . remove ( key ) ) ; if ( NameNode . stateChangeLog . isDebugEnabled ( ) ) { NameNode . stateChangeLog . debug ( "BLOCK* NameSystem.wipeDatanode: " + nodeID . getName ( ) + " storage " + key + " is removed from datanodeMap." ) ; } } | Physically remove node from datanodeMap . |
33,114 | void heartbeatCheck ( ) { if ( ! getNameNode ( ) . shouldCheckHeartbeat ( ) ) { return ; } boolean allAlive = false ; while ( ! allAlive ) { boolean foundDead = false ; DatanodeID nodeID = null ; synchronized ( heartbeats ) { for ( Iterator < DatanodeDescriptor > it = heartbeats . iterator ( ) ; it . hasNext ( ) ; ) { DatanodeDescriptor nodeInfo = it . next ( ) ; if ( isDatanodeDead ( nodeInfo ) ) { foundDead = true ; nodeID = nodeInfo ; break ; } } } if ( foundDead ) { writeLock ( ) ; try { synchronized ( heartbeats ) { synchronized ( datanodeMap ) { DatanodeDescriptor nodeInfo = null ; try { nodeInfo = getDatanode ( nodeID ) ; } catch ( IOException e ) { nodeInfo = null ; } if ( nodeInfo != null && isDatanodeDead ( nodeInfo ) ) { NameNode . stateChangeLog . info ( "BLOCK* NameSystem.heartbeatCheck: " + "lost heartbeat from " + nodeInfo . getName ( ) ) ; removeDatanode ( nodeInfo ) ; nodeInfo . setStartTime ( now ( ) ) ; } } } } finally { writeUnlock ( ) ; } } allAlive = ! foundDead ; } } | Check if there are any expired heartbeats and if so whether any blocks have to be re - replicated . While removing dead datanodes make sure that only one datanode is marked dead at a time within the synchronized section . Otherwise a cascading effect causes more datanodes to be declared dead . |
33,115 | private boolean checkBlockSize ( Block block , INodeFile inode ) { if ( block . getNumBytes ( ) < 0 ) { return false ; } BlockInfo [ ] blocks = inode . getBlocks ( ) ; if ( blocks . length == 0 ) { return false ; } return block . getNumBytes ( ) <= inode . getPreferredBlockSize ( ) ; } | Return true if the block size number is valid |
33,116 | private void rejectAddStoredBlock ( Block block , DatanodeDescriptor node , String msg , boolean ignoreInfoLogs , final boolean parallelInitialBlockReport ) { if ( ( ! isInSafeModeInternal ( ) ) && ( ! ignoreInfoLogs ) ) { NameNode . stateChangeLog . info ( "BLOCK* NameSystem.addStoredBlock: " + "addStoredBlock request received for " + block + " size " + block . getNumBytes ( ) + " but was rejected and added to invalidSet of " + node . getName ( ) + " : " + msg ) ; } lockParallelBRLock ( parallelInitialBlockReport ) ; try { addToInvalidatesNoLog ( block , node , false ) ; } finally { unlockParallelBRLock ( parallelInitialBlockReport ) ; } } | Log a rejection of an addStoredBlock RPC invalidate the reported block . |
33,117 | private void processOverReplicatedBlocksAsync ( ) { if ( isInSafeMode ( ) ) { return ; } if ( delayOverreplicationMonitorTime > now ( ) ) { LOG . info ( "Overreplication monitor delayed for " + ( ( delayOverreplicationMonitorTime - now ( ) ) / 1000 ) + " seconds" ) ; return ; } nameNode . clearOutstandingNodes ( ) ; final int nodes = heartbeats . size ( ) ; List < Block > blocksToProcess = new ArrayList < Block > ( Math . min ( overReplicatedBlocks . size ( ) , ReplicationConfigKeys . overreplicationWorkMultiplier * nodes ) ) ; for ( int i = 0 ; i < ReplicationConfigKeys . overreplicationWorkMultiplier ; i ++ ) { writeLock ( ) ; try { NameNode . getNameNodeMetrics ( ) . numOverReplicatedBlocks . set ( overReplicatedBlocks . size ( ) ) ; overReplicatedBlocks . pollNToList ( nodes , blocksToProcess ) ; if ( overReplicatedBlocks . isEmpty ( ) ) { break ; } } finally { writeUnlock ( ) ; } } for ( Block block : blocksToProcess ) { if ( NameNode . stateChangeLog . isDebugEnabled ( ) ) { NameNode . stateChangeLog . debug ( "BLOCK* NameSystem.processOverReplicatedBlocksAsync: " + block ) ; } if ( block instanceof OverReplicatedBlock ) { OverReplicatedBlock opb = ( OverReplicatedBlock ) block ; processOverReplicatedBlock ( block , ( short ) - 1 , opb . addedNode , opb . delNodeHint ) ; } else { processOverReplicatedBlock ( block , ( short ) - 1 , null , null ) ; } } } | This is called from the ReplicationMonitor to process over replicated blocks . |
33,118 | private void updateNeededReplicationQueue ( BlockInfo blockInfo , int delta , int numCurrentReplicas , int numCurrentDecommissionedReplicas , DatanodeDescriptor node , short fileReplication ) { int numOldReplicas = numCurrentReplicas ; int numOldDecommissionedReplicas = numCurrentDecommissionedReplicas ; if ( node . isDecommissioned ( ) || node . isDecommissionInProgress ( ) ) { numOldDecommissionedReplicas -= delta ; } else { numOldReplicas -= delta ; } if ( fileReplication > numOldReplicas ) { neededReplications . remove ( blockInfo , numOldReplicas , numOldDecommissionedReplicas , fileReplication ) ; } if ( fileReplication > numCurrentReplicas ) { neededReplications . add ( blockInfo , numCurrentReplicas , numCurrentDecommissionedReplicas , fileReplication ) ; } } | Update a block s priority queue in neededReplicaiton queues |
33,119 | private boolean blockReceived ( Block block , String delHint , DatanodeDescriptor node ) throws IOException { assert ( hasWriteLock ( ) ) ; node . decBlocksScheduled ( ) ; DatanodeDescriptor delHintNode = null ; if ( delHint != null && delHint . length ( ) != 0 ) { delHintNode = datanodeMap . get ( delHint ) ; if ( delHintNode == null ) { NameNode . stateChangeLog . warn ( "BLOCK* NameSystem.blockReceived: " + block + " is expected to be removed from an unrecorded node " + delHint ) ; } } pendingReplications . remove ( block ) ; return addStoredBlock ( block , node , delHintNode ) ; } | The given node is reporting that it received a certain block . |
33,120 | DatanodeInfo [ ] getDatanodes ( DatanodeReportType type ) { ArrayList < DatanodeDescriptor > results = getDatanodeListForReport ( type ) ; DatanodeInfo [ ] arr = new DatanodeInfo [ results . size ( ) ] ; for ( int i = 0 ; i < arr . length ; i ++ ) { arr [ i ] = new DatanodeInfo ( results . get ( i ) ) ; } return arr ; } | Get all the datanodes of the given type |
33,121 | void saveNamespace ( boolean force , boolean uncompressed ) throws AccessControlException , IOException { LOG . info ( "Saving namespace" ) ; writeLock ( ) ; try { checkSuperuserPrivilege ( ) ; if ( ! force && ! isInSafeMode ( ) ) { throw new IOException ( "Safe mode should be turned ON " + "in order to create namespace image." ) ; } getFSImage ( ) . saveNamespace ( uncompressed ) ; } finally { writeUnlock ( ) ; } LOG . info ( "Saving namespace - DONE" ) ; } | Save namespace image . This will save current namespace into fsimage file and empty edits file . Requires superuser privilege and safe mode . |
33,122 | private void datanodeDump ( PrintWriter out ) { readLock ( ) ; try { synchronized ( datanodeMap ) { out . println ( "Metasave: Number of datanodes: " + datanodeMap . size ( ) ) ; for ( Iterator < DatanodeDescriptor > it = datanodeMap . values ( ) . iterator ( ) ; it . hasNext ( ) ; ) { DatanodeDescriptor node = it . next ( ) ; out . println ( node . dumpDatanode ( ) ) ; } } } finally { readUnlock ( ) ; } } | Prints information about all datanodes . |
33,123 | void startDecommission ( DatanodeDescriptor node ) throws IOException { if ( ! node . isDecommissionInProgress ( ) && ! node . isDecommissioned ( ) ) { LOG . info ( "Start Decommissioning node " + node . getName ( ) + " with " + node . numBlocks ( ) + " blocks." ) ; synchronized ( heartbeats ) { updateStats ( node , false ) ; node . startDecommission ( ) ; updateStats ( node , true ) ; } if ( ( ( Monitor ) dnthread . getRunnable ( ) ) . startDecommision ( node ) ) { node . setStartTime ( now ( ) ) ; } } else if ( node . isDecommissionInProgress ( ) ) { if ( ( ( Monitor ) dnthread . getRunnable ( ) ) . startDecommision ( node ) ) { node . setStartTime ( now ( ) ) ; } } } | Start decommissioning the specified datanode . |
33,124 | void stopDecommission ( DatanodeDescriptor node ) throws IOException { if ( ( node . isDecommissionInProgress ( ) && ( ( Monitor ) dnthread . getRunnable ( ) ) . stopDecommission ( node ) ) || node . isDecommissioned ( ) ) { LOG . info ( "Stop Decommissioning node " + node . getName ( ) ) ; synchronized ( heartbeats ) { updateStats ( node , false ) ; node . stopDecommission ( ) ; updateStats ( node , true ) ; } writeLock ( ) ; try { Iterator < BlockInfo > it = node . getBlockIterator ( ) ; while ( it . hasNext ( ) ) { Block b = it . next ( ) ; if ( countLiveNodes ( b ) > getReplication ( b ) ) { overReplicatedBlocks . add ( b ) ; } } } finally { writeUnlock ( ) ; } } } | Stop decommissioning the specified datanodes . |
33,125 | private int countLiveNodes ( Block b , Iterator < DatanodeDescriptor > nodeIter ) { int live = 0 ; Collection < DatanodeDescriptor > nodesCorrupt = null ; if ( corruptReplicas . size ( ) != 0 ) { nodesCorrupt = corruptReplicas . getNodes ( b ) ; } while ( nodeIter . hasNext ( ) ) { DatanodeDescriptor node = nodeIter . next ( ) ; if ( ( ( nodesCorrupt != null ) && ( nodesCorrupt . contains ( node ) ) ) || node . isDecommissionInProgress ( ) || node . isDecommissioned ( ) ) { } else { live ++ ; } } return live ; } | Counts the number of live nodes in the given list |
33,126 | BlockInfo isReplicationInProgress ( final DecommissioningStatus status , final DatanodeDescriptor srcNode , final BlockInfo block , boolean addToNeeded ) { INode fileINode = blocksMap . getINode ( block ) ; if ( fileINode == null ) { return null ; } NumberReplicas num = countNodes ( block ) ; int curReplicas = num . liveReplicas ( ) ; int curExpectedReplicas = getReplication ( block ) ; if ( curExpectedReplicas > curReplicas ) { if ( status != null ) { if ( status . underReplicatedBlocks == 0 ) { logBlockReplicationInfo ( block , srcNode , num ) ; } status . underReplicatedBlocks ++ ; if ( ( curReplicas == 0 ) && ( num . decommissionedReplicas ( ) > 0 ) ) { status . decommissionOnlyReplicas ++ ; } if ( fileINode . isUnderConstruction ( ) ) { status . underReplicatedInOpenFiles ++ ; } } if ( ! neededReplications . contains ( block ) && pendingReplications . getNumReplicas ( block ) == 0 ) { if ( addToNeeded ) { neededReplications . add ( block , curReplicas , num . decommissionedReplicas ( ) , curExpectedReplicas ) ; } else { return block ; } } } return null ; } | Check if a block on srcNode has reached its replication factor or not |
33,127 | private String getHostNameForIp ( String ipAddr ) { try { InetAddress addr = InetAddress . getByName ( ipAddr ) ; return addr . getHostName ( ) ; } catch ( Exception e ) { } return null ; } | Best effort reverse DNS resolution . Returns null on error . |
33,128 | private boolean verifyNodeRegistration ( DatanodeRegistration nodeReg , String ipAddr ) throws IOException { assert ( hasWriteLock ( ) ) ; return inHostsList ( nodeReg , ipAddr ) ; } | Checks if the node is not on the hosts list . If it is not then it will be disallowed from registering . |
33,129 | private void checkDecommissioning ( DatanodeDescriptor nodeReg , String ipAddr ) throws IOException { if ( inExcludedHostsList ( nodeReg , ipAddr ) ) { startDecommission ( nodeReg ) ; } } | Decommission the node if it is in exclude list . |
33,130 | public DatanodeDescriptor getDatanode ( DatanodeID nodeID ) throws IOException { UnregisteredDatanodeException e = null ; DatanodeDescriptor node = datanodeMap . get ( nodeID . getStorageID ( ) ) ; if ( node == null ) { return null ; } if ( ! node . getName ( ) . equals ( nodeID . getName ( ) ) ) { e = new UnregisteredDatanodeException ( nodeID , node ) ; NameNode . stateChangeLog . fatal ( "BLOCK* NameSystem.getDatanode: " + e . getLocalizedMessage ( ) ) ; throw e ; } return node ; } | Get data node by storage ID . |
33,131 | void incrementSafeBlockCount ( int replication , boolean skipCheck ) { if ( safeMode != null && safeMode . isOn ( ) ) { if ( ( int ) replication == minReplication ) { this . blocksSafe ++ ; if ( ! skipCheck ) { safeMode . checkMode ( ) ; } } } } | Increment number of blocks that reached minimal replication . |
33,132 | void enterSafeMode ( ) throws IOException { writeLock ( ) ; try { getEditLog ( ) . logSyncAll ( ) ; if ( ! isInSafeMode ( ) ) { safeMode = SafeModeUtil . getInstance ( this ) ; safeMode . setManual ( ) ; return ; } safeMode . setManual ( ) ; getEditLog ( ) . logSyncAll ( ) ; NameNode . stateChangeLog . info ( "STATE* Safe mode is ON. " + safeMode . getTurnOffTip ( ) ) ; } finally { writeUnlock ( ) ; } } | Enter safe mode manually . |
33,133 | void leaveSafeMode ( boolean checkForUpgrades ) throws SafeModeException { writeLock ( ) ; try { if ( ! isInSafeMode ( ) ) { NameNode . stateChangeLog . info ( "STATE* Safe mode is already OFF." ) ; return ; } if ( getDistributedUpgradeState ( ) ) { throw new SafeModeException ( "Distributed upgrade is in progress" , safeMode ) ; } safeMode . leave ( checkForUpgrades ) ; safeMode = null ; } finally { writeUnlock ( ) ; } } | Leave safe mode . |
33,134 | void initializeReplQueues ( ) throws SafeModeException { writeLock ( ) ; try { if ( isPopulatingReplQueues ( ) ) { NameNode . stateChangeLog . info ( "STATE* Safe mode is already OFF." + " Replication queues are initialized" ) ; return ; } safeMode . initializeReplicationQueues ( ) ; } finally { writeUnlock ( ) ; } } | Manually initialize replication queues when in safemode . |
33,135 | public long nextGenerationStampForBlock ( Block block , boolean fromNN ) throws IOException { writeLock ( ) ; try { if ( isInSafeMode ( ) ) { throw new SafeModeException ( "Cannot get nextGenStamp for " + block , safeMode ) ; } Block blockWithWildcardGenstamp = new Block ( block . getBlockId ( ) ) ; BlockInfo storedBlock = blocksMap . getStoredBlock ( blockWithWildcardGenstamp ) ; if ( storedBlock == null ) { String msg = block + " is already commited, storedBlock == null." ; LOG . info ( msg ) ; throw new BlockAlreadyCommittedException ( msg ) ; } INodeFile fileINode = storedBlock . getINode ( ) ; if ( ! fileINode . isUnderConstruction ( ) ) { String msg = block + " is already commited, !fileINode.isUnderConstruction()." ; LOG . info ( msg ) ; throw new BlockAlreadyCommittedException ( msg ) ; } String path = null ; try { path = fileINode . getFullPathName ( ) ; } catch ( IOException ioe ) { throw ( BlockAlreadyCommittedException ) new BlockAlreadyCommittedException ( block + " is already deleted" ) . initCause ( ioe ) ; } if ( ! fromNN && HdfsConstants . NN_RECOVERY_LEASEHOLDER . equals ( leaseManager . getLeaseByPath ( path ) . getHolder ( ) ) ) { String msg = block + "is being recovered by NameNode, ignoring the request from a client" ; LOG . info ( msg ) ; throw new IOException ( msg ) ; } if ( ! ( ( INodeFileUnderConstruction ) fileINode ) . setLastRecoveryTime ( now ( ) ) ) { String msg = block + " is being recovered, ignoring this request." ; LOG . info ( msg ) ; throw new IOException ( msg ) ; } return nextGenerationStamp ( ) ; } finally { writeUnlock ( ) ; } } | Verifies that the block is associated with a file that has a lease . Increments logs and then returns the stamp |
33,136 | void saveFilesUnderConstruction ( SaveNamespaceContext ctx , DataOutputStream out ) throws IOException { synchronized ( leaseManager ) { int pathsToSave = 0 ; Iterator < Lease > itrl = leaseManager . getSortedLeases ( ) . iterator ( ) ; while ( itrl . hasNext ( ) ) { Lease lease = itrl . next ( ) ; for ( String path : lease . getPaths ( ) ) { INode node = dir . getFileINode ( path ) ; if ( node != null && node . isUnderConstruction ( ) ) { pathsToSave ++ ; } else if ( node == null ) { String msg = "saveLeases - counting - found path " + path + " but no matching entry in namespace." ; LOG . warn ( msg ) ; continue ; } else { throw new IOException ( "saveLeases found path " + path + " but is not under construction." ) ; } } } if ( pathsToSave != leaseManager . countPath ( ) ) { LOG . warn ( "Number of leases mismatch: " + pathsToSave + " are valid, lease manager indicated: " + leaseManager . countPath ( ) ) ; } out . writeInt ( pathsToSave ) ; int pathsSaved = 0 ; LightWeightLinkedSet < Lease > sortedLeases = leaseManager . getSortedLeases ( ) ; Iterator < Lease > itr = sortedLeases . iterator ( ) ; while ( itr . hasNext ( ) ) { ctx . checkCancelled ( ) ; Lease lease = itr . next ( ) ; for ( String path : lease . getPaths ( ) ) { INode node = dir . getFileINode ( path ) ; if ( node == null ) { String msg = "saveLeases found path " + path + " but no matching entry in namespace." ; LOG . warn ( msg ) ; continue ; } if ( ! node . isUnderConstruction ( ) ) { throw new IOException ( "saveLeases found path " + path + " but is not under construction." ) ; } INodeFileUnderConstruction cons = ( INodeFileUnderConstruction ) node ; FSImageSerialization . writeINodeUnderConstruction ( out , cons , path ) ; pathsSaved ++ ; } } if ( pathsSaved != pathsToSave ) { String msg = "Saved paths: " + pathsSaved + " is not equal to what we thought we would save: " + pathsToSave ; LOG . error ( msg ) ; throw new IOException ( msg ) ; } } } | Serializes leases . |
33,137 | public String getLiveNodes ( ) { final Map < String , Map < String , Object > > info = new HashMap < String , Map < String , Object > > ( ) ; try { final ArrayList < DatanodeDescriptor > liveNodeList = new ArrayList < DatanodeDescriptor > ( ) ; final ArrayList < DatanodeDescriptor > deadNodeList = new ArrayList < DatanodeDescriptor > ( ) ; DFSNodesStatus ( liveNodeList , deadNodeList ) ; removeDecommissionedNodeFromList ( liveNodeList ) ; for ( DatanodeDescriptor node : liveNodeList ) { final Map < String , Object > innerinfo = new HashMap < String , Object > ( ) ; innerinfo . put ( "lastContact" , getLastContact ( node ) ) ; innerinfo . put ( "usedSpace" , getDfsUsed ( node ) ) ; innerinfo . put ( "adminState" , node . getAdminState ( ) . toString ( ) ) ; innerinfo . put ( "excluded" , this . inExcludedHostsList ( node , null ) ) ; info . put ( node . getHostName ( ) + ":" + node . getPort ( ) , innerinfo ) ; } } catch ( Exception e ) { LOG . error ( "Exception:" , e ) ; } return JSON . toString ( info ) ; } | Returned information is a JSON representation of map with host name as the key and value is a map of live node attribute keys to its values |
33,138 | public String getDecomNodes ( ) { final Map < String , Map < String , Object > > info = new HashMap < String , Map < String , Object > > ( ) ; try { final ArrayList < DatanodeDescriptor > decomNodeList = this . getDecommissioningNodesList ( ) ; for ( DatanodeDescriptor node : decomNodeList ) { final Map < String , Object > innerinfo = new HashMap < String , Object > ( ) ; innerinfo . put ( "underReplicatedBlocks" , node . decommissioningStatus . getUnderReplicatedBlocks ( ) ) ; innerinfo . put ( "decommissionOnlyReplicas" , node . decommissioningStatus . getDecommissionOnlyReplicas ( ) ) ; innerinfo . put ( "underReplicateInOpenFiles" , node . decommissioningStatus . getUnderReplicatedInOpenFiles ( ) ) ; info . put ( node . getHostName ( ) + ":" + node . getPort ( ) , innerinfo ) ; } } catch ( Exception e ) { LOG . error ( "Exception:" , e ) ; } return JSON . toString ( info ) ; } | Returned information is a JSON representation of map with host name as the key and value is a map of decomisioning node attribute keys to its values |
33,139 | public short adjustReplication ( short replication ) { short r = ( short ) ( replication < minReplication ? minReplication : replication > maxReplication ? maxReplication : replication ) ; return r ; } | Clamp the specified replication between the minimum and the maximum replication levels . |
33,140 | public static URI translateToOldSchema ( Configuration clusterConf , String nameserviceId ) { String key = FSConstants . DFS_NAMENODE_RPC_ADDRESS_KEY + "." + nameserviceId ; String value = clusterConf . get ( key ) ; if ( value == null ) { throw new IllegalArgumentException ( "Cannot translate to old schema for nameserviceId: " + nameserviceId ) ; } InetSocketAddress address = NetUtils . createSocketAddr ( value ) ; return NameNode . getUri ( address ) ; } | Translates nameserviceId to ZK key in deprecated layout |
33,141 | public static SocketFactory getSocketFactoryFromProperty ( Configuration conf , String propValue ) { try { Class < ? > theClass = conf . getClassByName ( propValue ) ; return ( SocketFactory ) ReflectionUtils . newInstance ( theClass , conf ) ; } catch ( ClassNotFoundException cnfe ) { throw new RuntimeException ( "Socket Factory class not found: " + cnfe ) ; } } | Get the socket factory corresponding to the given proxy URI . If the given proxy URI corresponds to an absence of configuration parameter returns null . If the URI is malformed raises an exception . |
33,142 | public static String getServerAddress ( Configuration conf , String oldBindAddressName , String oldPortName , String newBindAddressName ) { String oldAddr = conf . get ( oldBindAddressName ) ; int oldPort = conf . getInt ( oldPortName , 0 ) ; String newAddrPort = conf . get ( newBindAddressName ) ; if ( oldAddr == null && oldPort == 0 ) { return toIpPort ( createSocketAddr ( newAddrPort ) ) ; } InetSocketAddress newAddr = NetUtils . createSocketAddr ( newAddrPort ) ; if ( oldAddr == null ) { oldAddr = newAddr . getAddress ( ) . getHostAddress ( ) ; } else { LOG . warn ( "Configuration parameter " + oldBindAddressName + " is deprecated. Use " + newBindAddressName + " instead." ) ; } if ( oldPort == 0 ) { oldPort = newAddr . getPort ( ) ; } else { LOG . warn ( "Configuration parameter " + oldPortName + " is deprecated. Use " + newBindAddressName + " instead." ) ; } try { return toIpPort ( oldAddr , oldPort ) ; } catch ( UnknownHostException e ) { LOG . error ( "DNS not supported." ) ; LOG . fatal ( e ) ; } return oldAddr + ":" + oldPort ; } | Handle the transition from pairs of attributes specifying a host and port to a single colon separated one . |
33,143 | public static List < String > normalizeHostNames ( Collection < String > names ) { List < String > resolvedIpAddresses = new ArrayList < String > ( names . size ( ) ) ; for ( String name : names ) { resolvedIpAddresses . add ( normalizeHostName ( name ) ) ; } return resolvedIpAddresses ; } | Given a collection of string representation of hosts return a list of corresponding IP addresses in the textual representation . |
33,144 | public static void isSocketBindable ( InetSocketAddress addr ) throws IOException { if ( addr == null ) { return ; } ServerSocket socket = new ServerSocket ( ) ; try { socket . bind ( addr ) ; } finally { socket . close ( ) ; } } | Tries to bind to the given address . Throws an exception on failure . Used to fail earlier and verify configuration values . |
33,145 | public boolean addSourceFile ( FileSystem fs , PolicyInfo info , FileStatus src , RaidState . Checker checker , long now , int targetReplication ) throws IOException { List < FileStatus > lfs = RaidNode . listDirectoryRaidFileStatus ( fs . getConf ( ) , fs , src . getPath ( ) ) ; if ( lfs == null ) { return false ; } RaidState state = checker . check ( info , src , now , false , lfs ) ; Counters counters = stateToSourceCounters . get ( state ) ; counters . inc ( lfs ) ; if ( state == RaidState . RAIDED ) { long paritySize = computeParitySize ( lfs , targetReplication ) ; estimatedParitySize += paritySize ; estimatedDoneParitySize += paritySize ; estimatedDoneSourceSize += DirectoryStripeReader . getDirPhysicalSize ( lfs ) ; return false ; } if ( state == RaidState . NOT_RAIDED_BUT_SHOULD ) { estimatedDoneParitySize += computeParitySize ( lfs , targetReplication ) ; estimatedDoneSourceSize += DirectoryStripeReader . getDirPhysicalSize ( lfs ) ; return true ; } return false ; } | Collect the statistics of a source directory . Return true if the file should be raided but not . |
33,146 | private void incrementAttemptUnprotected ( ) { attempt ++ ; currentAttemptId = new TaskAttemptID ( new TaskID ( attemptJobId , currentAttemptId . isMap ( ) , currentAttemptId . getTaskID ( ) . getId ( ) ) , attempt ) ; } | Increment the attempt number for launching a remote corona job tracker . Must be called only when holding the object lock . |
33,147 | private void checkAttempt ( TaskAttemptID attemptId ) throws IOException { if ( ! attemptId . equals ( currentAttemptId ) ) { throw new IOException ( "Attempt " + attemptId + " does not match current attempt " + currentAttemptId ) ; } } | Checks whether provided attempt id of remote JT matches currently set throws if not |
33,148 | void initializeClientUnprotected ( String host , int port , String sessionId ) throws IOException { if ( client != null ) { return ; } LOG . info ( "Creating JT client to " + host + ":" + port ) ; long connectTimeout = RemoteJTProxy . getRemotJTTimeout ( conf ) ; int rpcTimeout = RemoteJTProxy . getRemoteJTRPCTimeout ( conf ) ; remoteJTAddr = new InetSocketAddress ( host , port ) ; client = RPC . waitForProtocolProxy ( JobSubmissionProtocol . class , JobSubmissionProtocol . versionID , remoteJTAddr , conf , connectTimeout , rpcTimeout ) . getProxy ( ) ; remoteJTStatus = RemoteJTStatus . SUCCESS ; remoteJTHost = host ; remoteJTPort = port ; remoteSessionId = sessionId ; if ( remoteJTState != null ) { remoteJTState . setSessionId ( sessionId ) ; } } | Create the RPC client to the remote corona job tracker . |
33,149 | public void waitForJTStart ( JobConf jobConf ) throws IOException { int maxJTAttempts = jobConf . getInt ( "mapred.coronajobtracker.remotejobtracker.attempts" , 4 ) ; ResourceTracker resourceTracker = jt . getResourceTracker ( ) ; SessionDriver sessionDriver = jt . getSessionDriver ( ) ; List < ResourceGrant > excludeGrants = new ArrayList < ResourceGrant > ( ) ; boolean toExcludeFailed = jobConf . getBoolean ( REMOTE_JT_EXCLUDE_FAILED , true ) ; if ( remoteJTGrant != null ) { if ( toExcludeFailed ) { excludeGrants . add ( remoteJTGrant ) ; } resourceTracker . releaseResource ( remoteJTGrant . getId ( ) ) ; sessionDriver . releaseResources ( resourceTracker . getResourcesToRelease ( ) ) ; } for ( int i = 0 ; i < maxJTAttempts ; i ++ ) { try { remoteJTGrant = waitForJTGrant ( resourceTracker , sessionDriver , excludeGrants ) ; boolean success = startRemoteJT ( jobConf , remoteJTGrant ) ; if ( success ) { return ; } else { excludeGrants . add ( remoteJTGrant ) ; resourceTracker . releaseResource ( remoteJTGrant . getId ( ) ) ; List < ResourceRequest > released = resourceTracker . getResourcesToRelease ( ) ; sessionDriver . releaseResources ( released ) ; } } catch ( InterruptedException e ) { throw new IOException ( e ) ; } } throw new IOException ( "Could not start remote JT after " + maxJTAttempts + " attempts" ) ; } | Waits for the remote Corona JT to be ready . This involves - getting a JOBTRACKER resource from the cluster manager . - starting the remote job tracker by connecting to the corona task tracker on the machine . - waiting for the remote job tracker to report its port back to this process . |
33,150 | private ResourceGrant waitForJTGrant ( ResourceTracker resourceTracker , SessionDriver sessionDriver , List < ResourceGrant > previousGrants ) throws IOException , InterruptedException { LOG . info ( "Waiting for JT grant for " + attemptJobId ) ; ResourceRequest req = resourceTracker . newJobTrackerRequest ( ) ; for ( ResourceGrant prev : previousGrants ) { LOG . info ( "Adding " + prev . getNodeName ( ) + " to excluded hosts" ) ; req . addToExcludeHosts ( prev . getAddress ( ) . getHost ( ) ) ; } resourceTracker . recordRequest ( req ) ; List < ResourceRequest > newRequests = resourceTracker . getWantedResources ( ) ; sessionDriver . requestResources ( newRequests ) ; final List < ResourceGrant > grants = new ArrayList < ResourceGrant > ( ) ; ResourceTracker . ResourceProcessor proc = new ResourceTracker . ResourceProcessor ( ) { public boolean processAvailableResource ( ResourceGrant resource ) { grants . add ( resource ) ; final boolean consumed = true ; return consumed ; } } ; while ( true ) { long timeout = 60 * 1000 ; resourceTracker . processAvailableGrants ( proc , 1 , timeout ) ; IOException e = sessionDriver . getFailed ( ) ; if ( e != null ) { throw e ; } if ( ! grants . isEmpty ( ) ) { return grants . get ( 0 ) ; } } } | Wait for a JOBTRACKER grant . |
33,151 | private boolean startRemoteJT ( JobConf jobConf , ResourceGrant grant ) throws InterruptedException { org . apache . hadoop . corona . InetAddress ttAddr = Utilities . appInfoToAddress ( grant . appInfo ) ; CoronaTaskTrackerProtocol coronaTT = null ; try { coronaTT = jt . getTaskTrackerClient ( ttAddr . getHost ( ) , ttAddr . getPort ( ) ) ; } catch ( IOException e ) { LOG . error ( "Error while trying to connect to TT at " + ttAddr . getHost ( ) + ":" + ttAddr . getPort ( ) , e ) ; return false ; } LOG . warn ( "Starting remote JT for " + attemptJobId + " on " + ttAddr . getHost ( ) ) ; Path systemDir = new Path ( jt . getSystemDir ( ) ) ; LOG . info ( "startRemoteJT:systemDir " + systemDir . toString ( ) ) ; String jobFile = CoronaJobInProgress . getJobFile ( systemDir , attemptJobId ) . toString ( ) ; LOG . info ( "startRemoteJT:jobFile " + jobFile ) ; String splitClass = JobClient . RawSplit . class . getName ( ) ; BytesWritable split = new BytesWritable ( ) ; Task jobTask = new MapTask ( jobFile , currentAttemptId , currentAttemptId . getTaskID ( ) . getId ( ) , splitClass , split , 1 , jobConf . getUser ( ) ) ; CoronaSessionInfo info = new CoronaSessionInfo ( jt . getSessionId ( ) , jt . getJobTrackerAddress ( ) , jt . getJobTrackerAddress ( ) ) ; synchronized ( this ) { try { coronaTT . startCoronaJobTracker ( jobTask , info ) ; } catch ( IOException e ) { incrementAttemptUnprotected ( ) ; LOG . error ( "Error while performing RPC to TT at " + ttAddr . getHost ( ) + ":" + ttAddr . getPort ( ) , e ) ; return false ; } } final long waitStart = System . currentTimeMillis ( ) ; final long timeout = RemoteJTProxy . getRemotJTTimeout ( jobConf ) ; synchronized ( this ) { while ( client == null ) { LOG . warn ( "Waiting for remote JT to start on " + ttAddr . getHost ( ) ) ; this . wait ( 1000 ) ; if ( client == null && System . currentTimeMillis ( ) - waitStart > timeout ) { incrementAttemptUnprotected ( ) ; LOG . warn ( "Could not start remote JT on " + ttAddr . getHost ( ) ) ; return false ; } } } return true ; } | Start corona job tracker on the machine provided by using the corona task tracker API . |
33,152 | public void close ( ) { clientLock . writeLock ( ) . lock ( ) ; try { if ( client != null ) { RPC . stopProxy ( client ) ; client = null ; } } finally { clientLock . writeLock ( ) . unlock ( ) ; } } | Stop RPC client . |
33,153 | private JobSubmissionProtocol checkClient ( ) throws IOException { synchronized ( this ) { while ( client == null ) { try { if ( remoteJTStatus == RemoteJTStatus . FAILURE ) { throw new IOException ( "Remote Job Tracker is not available" ) ; } this . wait ( 1000 ) ; } catch ( InterruptedException e ) { throw new IOException ( e ) ; } } return client ; } } | Check if the RPC client to the remote job tracker is ready and wait if not . |
33,154 | boolean isProcessTreeOverLimit ( String tId , long currentMemUsage , long curMemUsageOfAgedProcesses , long limit ) { boolean isOverLimit = false ; if ( currentMemUsage > ( 2 * limit ) ) { LOG . warn ( "Process tree for task: " + tId + " running over twice " + "the configured limit. Limit=" + limit + ", current usage = " + currentMemUsage ) ; isOverLimit = true ; } else if ( curMemUsageOfAgedProcesses > limit ) { LOG . warn ( "Process tree for task: " + tId + " has processes older than 1 " + "iteration running over the configured limit. Limit=" + limit + ", current usage = " + curMemUsageOfAgedProcesses ) ; isOverLimit = true ; } return isOverLimit ; } | Check whether a task s process tree s current memory usage is over limit . |
33,155 | boolean isProcessTreeOverLimit ( ProcfsBasedProcessTree pTree , String tId , long limit ) { long currentMemUsage = pTree . getCumulativeVmem ( ) ; long curMemUsageOfAgedProcesses = pTree . getCumulativeVmem ( 1 ) ; return isProcessTreeOverLimit ( tId , currentMemUsage , curMemUsageOfAgedProcesses , limit ) ; } | method provided just for easy testing purposes |
33,156 | private long getTaskCumulativeRssmem ( TaskAttemptID tid ) { ProcessTreeInfo ptInfo = processTreeInfoMap . get ( tid ) ; ProcfsBasedProcessTree pTree = ptInfo . getProcessTree ( ) ; return pTree == null ? 0 : pTree . getCumulativeVmem ( ) ; } | Return the cumulative rss memory used by a task |
33,157 | private void failTasksWithMaxRssMemory ( long rssMemoryInUsage , long availableRssMemory ) { List < TaskAttemptID > tasksToKill = new ArrayList < TaskAttemptID > ( ) ; List < TaskAttemptID > allTasks = new ArrayList < TaskAttemptID > ( ) ; allTasks . addAll ( processTreeInfoMap . keySet ( ) ) ; Collections . sort ( allTasks , new Comparator < TaskAttemptID > ( ) { public int compare ( TaskAttemptID tid1 , TaskAttemptID tid2 ) { return getTaskCumulativeRssmem ( tid2 ) > getTaskCumulativeRssmem ( tid1 ) ? 1 : - 1 ; } } ) ; long rssMemoryStillInUsage = rssMemoryInUsage ; long availableRssMemoryAfterKilling = availableRssMemory ; while ( ( rssMemoryStillInUsage > maxRssMemoryAllowedForAllTasks || availableRssMemoryAfterKilling < reservedRssMemory ) && ! allTasks . isEmpty ( ) ) { TaskAttemptID tid = allTasks . remove ( 0 ) ; if ( ! isKillable ( tid ) ) { continue ; } long rssmem = getTaskCumulativeRssmem ( tid ) ; if ( rssmem == 0 ) { break ; } tasksToKill . add ( tid ) ; rssMemoryStillInUsage -= rssmem ; availableRssMemoryAfterKilling += rssmem ; } if ( ! tasksToKill . isEmpty ( ) ) { for ( TaskAttemptID tid : tasksToKill ) { long taskMemoryLimit = getTaskMemoryLimit ( tid ) ; long taskMemory = getTaskCumulativeRssmem ( tid ) ; String pid = processTreeInfoMap . get ( tid ) . getPID ( ) ; String msg = HIGH_MEMORY_KEYWORD + " task:" + tid + " pid:" + pid + " taskMemory:" + taskMemory + " taskMemoryLimit:" + taskMemoryLimit + " availableMemory:" + availableRssMemory + " totalMemory:" + rssMemoryInUsage + " totalMemoryLimit:" + maxRssMemoryAllowedForAllTasks ; if ( taskMemory > taskMemoryLimit ) { msg = "Failing " + msg ; LOG . warn ( msg ) ; killTask ( tid , msg , true ) ; } else { msg = "Killing " + msg ; LOG . warn ( msg ) ; killTask ( tid , msg , false ) ; } } } else { LOG . error ( "The total physical memory usage is overflowing TTs limits. " + "But found no alive task to kill for freeing memory." ) ; } } | Starting from the tasks use the highest amount of RSS memory fail the tasks until the RSS memory meets the requirement |
33,158 | public static byte [ ] prepareCachedNameBytes ( String entityName ) { UTF8 name = new UTF8 ( ) ; name . set ( entityName , true ) ; byte nameBytes [ ] = name . getBytes ( ) ; byte cachedName [ ] = new byte [ nameBytes . length + 2 ] ; System . arraycopy ( nameBytes , 0 , cachedName , 2 , nameBytes . length ) ; int v = nameBytes . length ; cachedName [ 0 ] = ( byte ) ( ( v >>> 8 ) & 0xFF ) ; cachedName [ 1 ] = ( byte ) ( ( v >>> 0 ) & 0xFF ) ; return cachedName ; } | Prepares a byte array for given name together with lenght as the two trailing bytes . |
33,159 | private static Class < ? > getClassWithCaching ( String className , Configuration conf ) { Class < ? > classs = cachedClassObjects . get ( className ) ; if ( classs == null ) { try { classs = conf . getClassByName ( className ) ; if ( cachedClassObjects . size ( ) < CACHE_MAX_SIZE ) { cachedClassObjects . put ( className , classs ) ; } } catch ( ClassNotFoundException e ) { throw new RuntimeException ( "readObject can't find class " + className , e ) ; } } if ( classs == null ) { throw new RuntimeException ( "readObject can't find class " + className ) ; } return classs ; } | Retrieve Class for given name from cache . if not present cache it it the map capacity is not exceeded . |
33,160 | private boolean blocksEquals ( Block [ ] a1 , Block [ ] a2 , boolean closedFile ) { if ( a1 == a2 ) return true ; if ( a1 == null || a2 == null || a2 . length != a1 . length ) return false ; for ( int i = 0 ; i < a1 . length ; i ++ ) { Block b1 = a1 [ i ] ; Block b2 = a2 [ i ] ; if ( b1 == b2 ) continue ; if ( b1 == null || b2 == null ) return false ; if ( ! ( b1 . getBlockId ( ) == b2 . getBlockId ( ) && b1 . getGenerationStamp ( ) == b2 . getGenerationStamp ( ) ) ) return false ; if ( ! closedFile && i >= a1 . length - 2 ) continue ; if ( b1 . getNumBytes ( ) != b2 . getNumBytes ( ) ) return false ; } return true ; } | Comapre two arrays of blocks . If the file is open do not compare sizes of the blocks . |
33,161 | void abort ( Throwable t ) throws IOException { LOG . info ( "Aborting because of " + StringUtils . stringifyException ( t ) ) ; try { downlink . abort ( ) ; downlink . flush ( ) ; } catch ( IOException e ) { } try { handler . waitForFinish ( ) ; } catch ( Throwable ignored ) { process . destroy ( ) ; } IOException wrapper = new IOException ( "pipe child exception" ) ; wrapper . initCause ( t ) ; throw wrapper ; } | Abort the application and wait for it to finish . |
33,162 | void cleanup ( ) throws IOException { serverSocket . close ( ) ; try { downlink . close ( ) ; } catch ( InterruptedException ie ) { Thread . currentThread ( ) . interrupt ( ) ; } } | Clean up the child procress and socket . |
33,163 | static Process runClient ( List < String > command , Map < String , String > env ) throws IOException { ProcessBuilder builder = new ProcessBuilder ( command ) ; if ( env != null ) { builder . environment ( ) . putAll ( env ) ; } Process result = builder . start ( ) ; return result ; } | Run a given command in a subprocess including threads to copy its stdout and stderr to our stdout and stderr . |
33,164 | synchronized void add ( Range range ) { if ( range . isEmpty ( ) ) { return ; } long startIndex = range . getStartIndex ( ) ; long endIndex = range . getEndIndex ( ) ; SortedSet < Range > headSet = ranges . headSet ( range ) ; if ( headSet . size ( ) > 0 ) { Range previousRange = headSet . last ( ) ; LOG . debug ( "previousRange " + previousRange ) ; if ( startIndex < previousRange . getEndIndex ( ) ) { if ( ranges . remove ( previousRange ) ) { indicesCount -= previousRange . getLength ( ) ; } startIndex = previousRange . getStartIndex ( ) ; endIndex = endIndex >= previousRange . getEndIndex ( ) ? endIndex : previousRange . getEndIndex ( ) ; } } Iterator < Range > tailSetIt = ranges . tailSet ( range ) . iterator ( ) ; while ( tailSetIt . hasNext ( ) ) { Range nextRange = tailSetIt . next ( ) ; LOG . debug ( "nextRange " + nextRange + " startIndex:" + startIndex + " endIndex:" + endIndex ) ; if ( endIndex >= nextRange . getStartIndex ( ) ) { tailSetIt . remove ( ) ; indicesCount -= nextRange . getLength ( ) ; if ( endIndex < nextRange . getEndIndex ( ) ) { endIndex = nextRange . getEndIndex ( ) ; break ; } } else { break ; } } add ( startIndex , endIndex ) ; } | Add the range indices . It is ensured that the added range doesn t overlap the existing ranges . If it overlaps the existing overlapping ranges are removed and a single range having the superset of all the removed ranges and this range is added . If the range is of 0 length doesn t do anything . |
33,165 | private JobStory getNextJobFiltered ( ) throws IOException { while ( true ) { ZombieJob job = producer . getNextJob ( ) ; if ( job == null ) { return null ; } if ( job . getOutcome ( ) == Pre21JobHistoryConstants . Values . KILLED ) { continue ; } if ( job . getNumberMaps ( ) == 0 ) { continue ; } if ( job . getNumLoggedMaps ( ) == 0 ) { continue ; } return job ; } } | Filter some jobs being fed to the simulator . For now we filter out killed jobs to facilitate debugging . |
33,166 | public void addColumn ( ColumnName name , boolean primary ) { ColumnHeader < ColumnName > top = new ColumnHeader < ColumnName > ( name , 0 ) ; top . up = top ; top . down = top ; if ( primary ) { Node < ColumnName > tail = head . left ; tail . right = top ; top . left = tail ; top . right = head ; head . left = top ; } else { top . left = top ; top . right = top ; } columns . add ( top ) ; } | Add a column to the table |
33,167 | public void addRow ( boolean [ ] values ) { Node < ColumnName > prev = null ; for ( int i = 0 ; i < values . length ; ++ i ) { if ( values [ i ] ) { ColumnHeader < ColumnName > top = columns . get ( i ) ; top . size += 1 ; Node < ColumnName > bottom = top . up ; Node < ColumnName > node = new Node < ColumnName > ( null , null , bottom , top , top ) ; bottom . down = node ; top . up = node ; if ( prev != null ) { Node < ColumnName > front = prev . right ; node . left = prev ; node . right = front ; prev . right = node ; front . left = node ; } else { node . left = node ; node . right = node ; } prev = node ; } } } | Add a row to the table . |
33,168 | private ColumnHeader < ColumnName > findBestColumn ( ) { int lowSize = Integer . MAX_VALUE ; ColumnHeader < ColumnName > result = null ; ColumnHeader < ColumnName > current = ( ColumnHeader < ColumnName > ) head . right ; while ( current != head ) { if ( current . size < lowSize ) { lowSize = current . size ; result = current ; } current = ( ColumnHeader < ColumnName > ) current . right ; } return result ; } | Find the column with the fewest choices . |
33,169 | private void coverColumn ( ColumnHeader < ColumnName > col ) { LOG . debug ( "cover " + col . head . name ) ; col . right . left = col . left ; col . left . right = col . right ; Node < ColumnName > row = col . down ; while ( row != col ) { Node < ColumnName > node = row . right ; while ( node != row ) { node . down . up = node . up ; node . up . down = node . down ; node . head . size -= 1 ; node = node . right ; } row = row . down ; } } | Hide a column in the table |
33,170 | private List < ColumnName > getRowName ( Node < ColumnName > row ) { List < ColumnName > result = new ArrayList < ColumnName > ( ) ; result . add ( row . head . name ) ; Node < ColumnName > node = row . right ; while ( node != row ) { result . add ( node . head . name ) ; node = node . right ; } return result ; } | Get the name of a row by getting the list of column names that it satisfies . |
33,171 | private int search ( List < Node < ColumnName > > partial , SolutionAcceptor < ColumnName > output ) { int results = 0 ; if ( head . right == head ) { List < List < ColumnName > > result = new ArrayList < List < ColumnName > > ( partial . size ( ) ) ; for ( Node < ColumnName > row : partial ) { result . add ( getRowName ( row ) ) ; } output . solution ( result ) ; results += 1 ; } else { ColumnHeader < ColumnName > col = findBestColumn ( ) ; if ( col . size > 0 ) { coverColumn ( col ) ; Node < ColumnName > row = col . down ; while ( row != col ) { partial . add ( row ) ; Node < ColumnName > node = row . right ; while ( node != row ) { coverColumn ( node . head ) ; node = node . right ; } results += search ( partial , output ) ; partial . remove ( partial . size ( ) - 1 ) ; node = row . left ; while ( node != row ) { uncoverColumn ( node . head ) ; node = node . left ; } row = row . down ; } uncoverColumn ( col ) ; } } return results ; } | Find a solution to the problem . |
33,172 | private void searchPrefixes ( int depth , int [ ] choices , List < int [ ] > prefixes ) { if ( depth == 0 ) { prefixes . add ( choices . clone ( ) ) ; } else { ColumnHeader < ColumnName > col = findBestColumn ( ) ; if ( col . size > 0 ) { coverColumn ( col ) ; Node < ColumnName > row = col . down ; int rowId = 0 ; while ( row != col ) { Node < ColumnName > node = row . right ; while ( node != row ) { coverColumn ( node . head ) ; node = node . right ; } choices [ choices . length - depth ] = rowId ; searchPrefixes ( depth - 1 , choices , prefixes ) ; node = row . left ; while ( node != row ) { uncoverColumn ( node . head ) ; node = node . left ; } row = row . down ; rowId += 1 ; } uncoverColumn ( col ) ; } } } | Generate a list of prefixes down to a given depth . Assumes that the problem is always deeper than depth . |
33,173 | public List < int [ ] > split ( int depth ) { int [ ] choices = new int [ depth ] ; List < int [ ] > result = new ArrayList < int [ ] > ( 100000 ) ; searchPrefixes ( depth , choices , result ) ; return result ; } | Generate a list of row choices to cover the first moves . |
33,174 | private Node < ColumnName > advance ( int goalRow ) { ColumnHeader < ColumnName > col = findBestColumn ( ) ; if ( col . size > 0 ) { coverColumn ( col ) ; Node < ColumnName > row = col . down ; int id = 0 ; while ( row != col ) { if ( id == goalRow ) { Node < ColumnName > node = row . right ; while ( node != row ) { coverColumn ( node . head ) ; node = node . right ; } return row ; } id += 1 ; row = row . down ; } } return null ; } | Make one move from a prefix |
33,175 | private void rollback ( Node < ColumnName > row ) { Node < ColumnName > node = row . left ; while ( node != row ) { uncoverColumn ( node . head ) ; node = node . left ; } uncoverColumn ( row . head ) ; } | Undo a prefix exploration |
33,176 | public int solve ( int [ ] prefix , SolutionAcceptor < ColumnName > output ) { List < Node < ColumnName > > choices = new ArrayList < Node < ColumnName > > ( ) ; for ( int i = 0 ; i < prefix . length ; ++ i ) { choices . add ( advance ( prefix [ i ] ) ) ; } int result = search ( choices , output ) ; for ( int i = prefix . length - 1 ; i >= 0 ; -- i ) { rollback ( choices . get ( i ) ) ; } return result ; } | Given a prefix find solutions under it . |
33,177 | public synchronized void waitFor ( int minResponses , int minSuccesses , int maxExceptions , int millis , String operationName ) throws InterruptedException , TimeoutException { long st = monotonicNow ( ) ; long nextLogTime = st + ( long ) ( millis * WAIT_PROGRESS_INFO_THRESHOLD ) ; long et = st + millis ; while ( true ) { checkAssertionErrors ( ) ; if ( minResponses > 0 && countResponses ( ) >= minResponses ) return ; if ( minSuccesses > 0 && countSuccesses ( ) >= minSuccesses ) return ; if ( ( maxExceptions > 0 && countExceptions ( ) >= maxExceptions ) || ( maxExceptions == 0 && countExceptions ( ) > 0 ) ) { return ; } long now = monotonicNow ( ) ; if ( now > nextLogTime ) { long waited = now - st ; String msg = String . format ( "Waited %s ms (timeout=%s ms) for a response for %s" , waited , millis , operationName ) ; if ( ! successes . isEmpty ( ) ) { msg += ". Succeeded so far: [" + Joiner . on ( "," ) . join ( successes . keySet ( ) ) + "]" ; } if ( ! exceptions . isEmpty ( ) ) { msg += ". Exceptions so far: [" + mapToString ( exceptions ) + "]" ; } if ( successes . isEmpty ( ) && exceptions . isEmpty ( ) ) { msg += ". No responses yet." ; } if ( waited > millis * WAIT_PROGRESS_WARN_THRESHOLD ) { QuorumJournalManager . LOG . warn ( msg ) ; } else { QuorumJournalManager . LOG . info ( msg ) ; } nextLogTime = now + WAIT_PROGRESS_INTERVAL_MILLIS ; } long rem = et - now ; if ( rem <= 0 ) { throw new TimeoutException ( ) ; } rem = Math . min ( rem , nextLogTime - now ) ; rem = Math . max ( rem , 1 ) ; wait ( rem ) ; } } | Wait for the quorum to achieve a certain number of responses . |
33,178 | private synchronized void checkAssertionErrors ( ) { boolean assertsEnabled = false ; assert assertsEnabled = true ; if ( assertsEnabled ) { for ( Throwable t : exceptions . values ( ) ) { if ( t instanceof AssertionError ) { throw ( AssertionError ) t ; } else if ( t instanceof RemoteException && ( ( RemoteException ) t ) . getClassName ( ) . equals ( AssertionError . class . getName ( ) ) ) { throw new AssertionError ( t ) ; } } } } | Check if any of the responses came back with an AssertionError . If so it re - throws it even if there was a quorum of responses . This code only runs if assertions are enabled for this class otherwise it should JIT itself away . |
33,179 | public synchronized void throwQuorumException ( String msg ) throws QuorumException { Preconditions . checkState ( ! exceptions . isEmpty ( ) ) ; throw QuorumException . create ( msg , successes , exceptions ) ; } | Throws exception as a result of this quorum call . |
33,180 | public void add ( final GridmixJob job ) throws InterruptedException { final boolean addToQueue = ! shutdown ; if ( addToQueue ) { final SubmitTask task = new SubmitTask ( job ) ; sem . acquire ( ) ; try { sched . execute ( task ) ; } catch ( RejectedExecutionException e ) { sem . release ( ) ; } } } | Enqueue the job to be submitted per the deadline associated with it . |
33,181 | public void join ( long millis ) throws InterruptedException { if ( ! shutdown ) { throw new IllegalStateException ( "Cannot wait for active submit thread" ) ; } sched . awaitTermination ( millis , TimeUnit . MILLISECONDS ) ; } | Continue running until all queued jobs have been submitted to the cluster . |
33,182 | public void printAllValues ( ) throws Exception { err ( "List of all the available keys:" ) ; Object val = null ; for ( ObjectName oname : hadoopObjectNames ) { err ( ">>>>>>>>jmx name: " + oname . getCanonicalKeyPropertyListString ( ) ) ; MBeanInfo mbinfo = mbsc . getMBeanInfo ( oname ) ; MBeanAttributeInfo [ ] mbinfos = mbinfo . getAttributes ( ) ; for ( MBeanAttributeInfo mb : mbinfos ) { val = mbsc . getAttribute ( oname , mb . getName ( ) ) ; System . out . format ( format , mb . getName ( ) , val . toString ( ) ) ; } } } | print all attributes values |
33,183 | public String getValue ( String key ) throws Exception { Object val = null ; for ( ObjectName oname : hadoopObjectNames ) { try { val = mbsc . getAttribute ( oname , key ) ; } catch ( AttributeNotFoundException anfe ) { continue ; } catch ( ReflectionException re ) { if ( re . getCause ( ) instanceof NoSuchMethodException ) { continue ; } } err ( "Info: key = " + key + "; val = " + val ) ; break ; } return ( val == null ) ? null : val . toString ( ) ; } | get single value by key |
33,184 | public static long getDirLogicalSize ( List < FileStatus > lfs ) { long totalSize = 0L ; if ( null == lfs ) { return totalSize ; } for ( FileStatus fsStat : lfs ) { totalSize += fsStat . getLen ( ) ; } return totalSize ; } | Get the total logical size in the directory |
33,185 | public static long getDirPhysicalSize ( List < FileStatus > lfs ) { long totalSize = 0L ; if ( null == lfs ) { return totalSize ; } for ( FileStatus fsStat : lfs ) { totalSize += fsStat . getLen ( ) * fsStat . getReplication ( ) ; } return totalSize ; } | Get the total physical size in the directory |
33,186 | public static BinaryRecordOutput get ( DataOutput out ) { BinaryRecordOutput bout = ( BinaryRecordOutput ) bOut . get ( ) ; bout . setDataOutput ( out ) ; return bout ; } | Get a thread - local record output for the supplied DataOutput . |
33,187 | public static boolean isSegmentsFile ( String name ) { return name . startsWith ( IndexFileNames . SEGMENTS ) && ! name . equals ( IndexFileNames . SEGMENTS_GEN ) ; } | Check if the file is a segments_N file |
33,188 | public static long generationFromSegmentsFileName ( String fileName ) { if ( fileName . equals ( IndexFileNames . SEGMENTS ) ) { return 0 ; } else if ( fileName . startsWith ( IndexFileNames . SEGMENTS ) ) { return Long . parseLong ( fileName . substring ( 1 + IndexFileNames . SEGMENTS . length ( ) ) , Character . MAX_RADIX ) ; } else { throw new IllegalArgumentException ( "fileName \"" + fileName + "\" is not a segments file" ) ; } } | Parse the generation off the segments file name and return it . |
33,189 | protected InterleavedInputStream createInterleavedInputStream ( InputStream in , int metaDataBlockLength , int dataBlockLength , SimpleSeekableFormat . MetaDataConsumer consumer ) { return new InterleavedInputStream ( in , metaDataBlockLength , dataBlockLength , consumer ) ; } | This factory method can be overwritten by subclass to provide different behavior . It s only called in the constructor . |
33,190 | private boolean moveToNextDataSegment ( ) throws IOException { try { clearDataSegment ( ) ; DataSegmentReader dataSegmentReader = new DataSegmentReader ( dataIn , conf , decompressorCache ) ; dataSegmentIn = dataSegmentReader . getInputStream ( ) ; } catch ( EmptyDataSegmentException e ) { return false ; } catch ( EOFException e ) { throw new CodecPrematureEOFException ( "Truncated .SSF file detected." ) ; } catch ( ClassNotFoundException e ) { throw new RuntimeException ( e ) ; } return true ; } | Returns false if there are no more data segments . |
33,191 | public long seekForward ( ) throws IOException { interleavedIn . skipToLastAvailableMetaDataBlock ( ) ; if ( ! interleavedIn . readMetaDataIfNeeded ( ) ) { throw new EOFException ( "Cannot get a complete metadata block" ) ; } SortedMap < Long , Long > offsetPairs = metaData . getOffsetPairs ( ) ; long uncompressedDataOffset = offsetPairs . lastKey ( ) ; long compressedDataOffset = offsetPairs . get ( uncompressedDataOffset ) ; long toSkip = compressedDataOffset - interleavedIn . getDataOffset ( ) ; if ( toSkip < 0 ) { throw new CorruptedDataException ( "SSF format error: The last offset pair is before the current position in InterleaveStream!" ) ; } try { interleavedIn . skipExactly ( toSkip ) ; } catch ( EOFException e ) { } clearDataSegment ( ) ; return uncompressedDataOffset ; } | This function seeks forward using all available bytes . It returns the offset after the seek . |
33,192 | public void refresh ( long position , long skippedUntilTxid ) throws IOException { checkInitialized ( ) ; if ( isInProgress ( ) ) { LedgerHandle ledger = ledgerProvider . openForReading ( ledgerId ) ; journalInputStream . resetLedger ( ledger ) ; } journalInputStream . position ( position ) ; bin = new BufferedInputStream ( journalInputStream ) ; tracker = new PositionTrackingInputStream ( bin , position ) ; DataInputStream in = new DataInputStream ( tracker ) ; if ( position == 0 ) { logVersion = readLogVersion ( in ) ; } reader = new Reader ( in , logVersion ) ; } | Refresh preferably to a known position |
33,193 | public void blockLocationInfoExpiresIfNeeded ( ) { if ( blkLocInfoExpireTimeout < 0 ) { return ; } long timeNow = System . currentTimeMillis ( ) ; if ( timeBlkLocInfoExpire < timeNow ) { this . writeLock ( ) ; try { long newTimeBlockExpire = Long . MAX_VALUE ; List < LocatedBlock > listToRemove = new ArrayList < LocatedBlock > ( ) ; for ( LocatedBlock lb : blkLocInfoExpireMap . keySet ( ) ) { long expireTime = blkLocInfoExpireMap . get ( lb ) ; if ( expireTime < timeNow ) { if ( DFSClient . LOG . isDebugEnabled ( ) ) { DFSClient . LOG . debug ( "Expire cached block location for " + lb ) ; } listToRemove . add ( lb ) ; } else if ( expireTime < newTimeBlockExpire ) { newTimeBlockExpire = expireTime ; } else { } } super . getLocatedBlocks ( ) . removeAll ( listToRemove ) ; for ( LocatedBlock lb : listToRemove ) { blkLocInfoExpireMap . remove ( lb ) ; } this . timeBlkLocInfoExpire = newTimeBlockExpire ; } finally { this . writeUnlock ( ) ; } } } | Deprecate block location information that has lived for too long |
33,194 | private void initBlkLocInfoExpireMap ( long expireTime ) { if ( blkLocInfoExpireTimeout < 0 ) { return ; } this . blkLocInfoExpireMap = new HashMap < LocatedBlock , Long > ( this . getLocatedBlocks ( ) . size ( ) ) ; for ( LocatedBlock lb : this . getLocatedBlocks ( ) ) { blkLocInfoExpireMap . put ( lb , expireTime ) ; } timeBlkLocInfoExpire = expireTime ; } | Initial the blockExpireMap which keeps track of the expiration time of all block location info . |
33,195 | public boolean isUnderConstructionBlock ( Block block ) { if ( ! isUnderConstruction ( ) ) { return false ; } LocatedBlock lastBlock = this . get ( this . locatedBlockCount ( ) - 1 ) ; if ( ( this . fileLength <= lastBlock . getStartOffset ( ) + lastBlock . getBlockSize ( ) ) && lastBlock . getBlock ( ) . equals ( block ) ) { return true ; } return false ; } | Determine whether the input block is the block under - construction for the file . If the current file is not under - construction always false is returned . |
33,196 | public synchronized Counter findCounter ( String group , String name ) { return getGroup ( group ) . getCounterForName ( name ) ; } | Find a counter given the group and the name . |
33,197 | public synchronized Counter findCounter ( String group , int id , String name ) { return getGroup ( group ) . getCounterForName ( name ) ; } | Find a counter by using strings |
33,198 | public synchronized void incrCounter ( String group , String counter , long amount ) { getGroup ( group ) . getCounterForName ( counter ) . increment ( amount ) ; } | Increments the specified counter by the specified amount creating it if it didn t already exist . |
33,199 | public static Counters sum ( Counters a , Counters b ) { Counters counters = new Counters ( ) ; counters . incrAllCounters ( a ) ; counters . incrAllCounters ( b ) ; return counters ; } | Convenience method for computing the sum of two sets of counters . |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.