public virtual void Add(Replica replica) { try { // zig-zag to reduce size of legacy blocks cos.WriteSInt64NoTag(replica.GetBlockId()); cos.WriteRawVarint64(replica.GetBytesOnDisk()); cos.WriteRawVarint64(replica.GetGenerationStamp()); HdfsServerConstants.ReplicaState state = replica.GetState(); // although state is not a 64-bit value, using a long varint to // allow for future use of the upper bits cos.WriteRawVarint64(state.GetValue()); if (state == HdfsServerConstants.ReplicaState.Finalized) { numFinalized++; } numBlocks++; } catch (IOException ioe) { // shouldn't happen, ByteString.Output doesn't throw IOE throw new InvalidOperationException(ioe); } }
/// <exception cref="System.IO.IOException"/> private void WaitForTempReplica(Block bl, int DnN1) { bool tooLongWait = false; int Timeout = 40000; if (Log.IsDebugEnabled()) { Log.Debug("Wait for datanode " + DnN1 + " to appear"); } while (cluster.GetDataNodes().Count <= DnN1) { WaitTil(20); } if (Log.IsDebugEnabled()) { Log.Debug("Total number of DNs " + cluster.GetDataNodes().Count); } cluster.WaitActive(); // Look about specified DN for the replica of the block from 1st DN DataNode dn1 = cluster.GetDataNodes()[DnN1]; string bpid = cluster.GetNamesystem().GetBlockPoolId(); Replica r = DataNodeTestUtils.FetchReplicaInfo(dn1, bpid, bl.GetBlockId()); long start = Time.MonotonicNow(); int count = 0; while (r == null) { WaitTil(5); r = DataNodeTestUtils.FetchReplicaInfo(dn1, bpid, bl.GetBlockId()); long waiting_period = Time.MonotonicNow() - start; if (count++ % 100 == 0) { if (Log.IsDebugEnabled()) { Log.Debug("Has been waiting for " + waiting_period + " ms."); } } if (waiting_period > Timeout) { NUnit.Framework.Assert.IsTrue("Was waiting too long to get ReplicaInfo from a datanode" , tooLongWait); } } HdfsServerConstants.ReplicaState state = r.GetState(); if (Log.IsDebugEnabled()) { Log.Debug("Replica state before the loop " + state.GetValue()); } start = Time.MonotonicNow(); while (state != HdfsServerConstants.ReplicaState.Temporary) { WaitTil(5); state = r.GetState(); if (Log.IsDebugEnabled()) { Log.Debug("Keep waiting for " + bl.GetBlockName() + " is in state " + state.GetValue ()); } if (Time.MonotonicNow() - start > Timeout) { NUnit.Framework.Assert.IsTrue("Was waiting too long for a replica to become TEMPORARY" , tooLongWait); } } if (Log.IsDebugEnabled()) { Log.Debug("Replica state after the loop " + state.GetValue()); } }