/// <summary>Iterate through all items and detect timed-out items</summary> internal virtual void PendingReplicationCheck() { lock (this._enclosing.pendingReplications) { IEnumerator <KeyValuePair <Block, PendingReplicationBlocks.PendingBlockInfo> > iter = this._enclosing.pendingReplications.GetEnumerator(); long now = Time.MonotonicNow(); if (PendingReplicationBlocks.Log.IsDebugEnabled()) { PendingReplicationBlocks.Log.Debug("PendingReplicationMonitor checking Q"); } while (iter.HasNext()) { KeyValuePair <Block, PendingReplicationBlocks.PendingBlockInfo> entry = iter.Next( ); PendingReplicationBlocks.PendingBlockInfo pendingBlock = entry.Value; if (now > pendingBlock.GetTimeStamp() + this._enclosing.timeout) { Block block = entry.Key; lock (this._enclosing.timedOutItems) { this._enclosing.timedOutItems.AddItem(block); } PendingReplicationBlocks.Log.Warn("PendingReplicationMonitor timed out " + block); iter.Remove(); } } } }
/// <summary>How many copies of this block is pending replication?</summary> internal virtual int GetNumReplicas(Block block) { lock (pendingReplications) { PendingReplicationBlocks.PendingBlockInfo found = pendingReplications[block]; if (found != null) { return(found.GetNumReplicas()); } } return(0); }
/// <summary>Add a block to the list of pending Replications</summary> /// <param name="block">The corresponding block</param> /// <param name="targets">The DataNodes where replicas of the block should be placed</param> internal virtual void Increment(Block block, DatanodeDescriptor[] targets) { lock (pendingReplications) { PendingReplicationBlocks.PendingBlockInfo found = pendingReplications[block]; if (found == null) { pendingReplications[block] = new PendingReplicationBlocks.PendingBlockInfo(targets ); } else { found.IncrementReplicas(targets); found.SetTimeStamp(); } } }
/// <summary>Iterate through all items and print them.</summary> internal virtual void MetaSave(PrintWriter @out) { lock (pendingReplications) { @out.WriteLine("Metasave: Blocks being replicated: " + pendingReplications.Count); IEnumerator <KeyValuePair <Block, PendingReplicationBlocks.PendingBlockInfo> > iter = pendingReplications.GetEnumerator(); while (iter.HasNext()) { KeyValuePair <Block, PendingReplicationBlocks.PendingBlockInfo> entry = iter.Next( ); PendingReplicationBlocks.PendingBlockInfo pendingBlock = entry.Value; Block block = entry.Key; @out.WriteLine(block + " StartTime: " + Sharpen.Extensions.CreateDate(pendingBlock .timeStamp) + " NumReplicaInProgress: " + pendingBlock.GetNumReplicas()); } } }
/// <summary>One replication request for this block has finished.</summary> /// <remarks> /// One replication request for this block has finished. /// Decrement the number of pending replication requests /// for this block. /// </remarks> /// <param name="The">DataNode that finishes the replication</param> internal virtual void Decrement(Block block, DatanodeDescriptor dn) { lock (pendingReplications) { PendingReplicationBlocks.PendingBlockInfo found = pendingReplications[block]; if (found != null) { if (Log.IsDebugEnabled()) { Log.Debug("Removing pending replication for " + block); } found.DecrementReplicas(dn); if (found.GetNumReplicas() <= 0) { Sharpen.Collections.Remove(pendingReplications, block); } } } }