public virtual void TestNotMatchedReplicaID()
        {
            if (Log.IsDebugEnabled())
            {
                Log.Debug("Running " + GenericTestUtils.GetMethodName());
            }
            ReplicaInPipelineInterface replicaInfo = dn.data.CreateRbw(StorageType.Default, block
                                                                       , false).GetReplica();
            ReplicaOutputStreams streams = null;

            try
            {
                streams = replicaInfo.CreateStreams(true, DataChecksum.NewDataChecksum(DataChecksum.Type
                                                                                       .Crc32, 512));
                streams.GetChecksumOut().Write('a');
                dn.data.InitReplicaRecovery(new BlockRecoveryCommand.RecoveringBlock(block, null,
                                                                                     RecoveryId + 1));
                try
                {
                    dn.SyncBlock(rBlock, InitBlockRecords(dn));
                    NUnit.Framework.Assert.Fail("Sync should fail");
                }
                catch (IOException e)
                {
                    e.Message.StartsWith("Cannot recover ");
                }
                DatanodeProtocol namenode = dn.GetActiveNamenodeForBP(PoolId);
                Org.Mockito.Mockito.Verify(namenode, Org.Mockito.Mockito.Never()).CommitBlockSynchronization
                    (Matchers.Any <ExtendedBlock>(), Matchers.AnyLong(), Matchers.AnyLong(), Matchers.AnyBoolean
                        (), Matchers.AnyBoolean(), Matchers.Any <DatanodeID[]>(), Matchers.Any <string[]>(
                        ));
            }
            finally
            {
                streams.Close();
            }
        }
        /// <exception cref="System.IO.IOException"/>
        internal virtual int AddSomeBlocks(SimulatedFSDataset fsdataset, int startingBlockId
                                           )
        {
            int bytesAdded = 0;

            for (int i = startingBlockId; i < startingBlockId + Numblocks; ++i)
            {
                ExtendedBlock b = new ExtendedBlock(bpid, i, 0, 0);
                // we pass expected len as zero, - fsdataset should use the sizeof actual
                // data written
                ReplicaInPipelineInterface bInfo = fsdataset.CreateRbw(StorageType.Default, b, false
                                                                       ).GetReplica();
                ReplicaOutputStreams @out = bInfo.CreateStreams(true, DataChecksum.NewDataChecksum
                                                                    (DataChecksum.Type.Crc32, 512));
                try
                {
                    OutputStream dataOut = @out.GetDataOut();
                    NUnit.Framework.Assert.AreEqual(0, fsdataset.GetLength(b));
                    for (int j = 1; j <= BlockIdToLen(i); ++j)
                    {
                        dataOut.Write(j);
                        NUnit.Framework.Assert.AreEqual(j, bInfo.GetBytesOnDisk());
                        // correct length even as we write
                        bytesAdded++;
                    }
                }
                finally
                {
                    @out.Close();
                }
                b.SetNumBytes(BlockIdToLen(i));
                fsdataset.FinalizeBlock(b);
                NUnit.Framework.Assert.AreEqual(BlockIdToLen(i), fsdataset.GetLength(b));
            }
            return(bytesAdded);
        }
Beispiel #3
0
 public ReplicaHandler(ReplicaInPipelineInterface replica, FsVolumeReference reference
                       )
 {
     this.replica         = replica;
     this.volumeReference = reference;
 }
Beispiel #4
0
        /// <exception cref="System.IO.IOException"/>
        private void TestWriteToTemporary(FsDatasetImpl dataSet, ExtendedBlock[] blocks)
        {
            try
            {
                dataSet.CreateTemporary(StorageType.Default, blocks[Finalized]);
                NUnit.Framework.Assert.Fail("Should not have created a temporary replica that was "
                                            + "finalized " + blocks[Finalized]);
            }
            catch (ReplicaAlreadyExistsException)
            {
            }
            try
            {
                dataSet.CreateTemporary(StorageType.Default, blocks[Temporary]);
                NUnit.Framework.Assert.Fail("Should not have created a replica that had created as"
                                            + "temporary " + blocks[Temporary]);
            }
            catch (ReplicaAlreadyExistsException)
            {
            }
            try
            {
                dataSet.CreateTemporary(StorageType.Default, blocks[Rbw]);
                NUnit.Framework.Assert.Fail("Should not have created a replica that had created as RBW "
                                            + blocks[Rbw]);
            }
            catch (ReplicaAlreadyExistsException)
            {
            }
            try
            {
                dataSet.CreateTemporary(StorageType.Default, blocks[Rwr]);
                NUnit.Framework.Assert.Fail("Should not have created a replica that was waiting to be "
                                            + "recovered " + blocks[Rwr]);
            }
            catch (ReplicaAlreadyExistsException)
            {
            }
            try
            {
                dataSet.CreateTemporary(StorageType.Default, blocks[Rur]);
                NUnit.Framework.Assert.Fail("Should not have created a replica that was under recovery "
                                            + blocks[Rur]);
            }
            catch (ReplicaAlreadyExistsException)
            {
            }
            dataSet.CreateTemporary(StorageType.Default, blocks[NonExistent]);
            try
            {
                dataSet.CreateTemporary(StorageType.Default, blocks[NonExistent]);
                NUnit.Framework.Assert.Fail("Should not have created a replica that had already been "
                                            + "created " + blocks[NonExistent]);
            }
            catch (Exception e)
            {
                NUnit.Framework.Assert.IsTrue(e.Message.Contains(blocks[NonExistent].GetBlockName
                                                                     ()));
                NUnit.Framework.Assert.IsTrue(e is ReplicaAlreadyExistsException);
            }
            long newGenStamp = blocks[NonExistent].GetGenerationStamp() * 10;

            blocks[NonExistent].SetGenerationStamp(newGenStamp);
            try
            {
                ReplicaInPipelineInterface replicaInfo = dataSet.CreateTemporary(StorageType.Default
                                                                                 , blocks[NonExistent]).GetReplica();
                NUnit.Framework.Assert.IsTrue(replicaInfo.GetGenerationStamp() == newGenStamp);
                NUnit.Framework.Assert.IsTrue(replicaInfo.GetBlockId() == blocks[NonExistent].GetBlockId
                                                  ());
            }
            catch (ReplicaAlreadyExistsException)
            {
                NUnit.Framework.Assert.Fail("createRbw() Should have removed the block with the older "
                                            + "genstamp and replaced it with the newer one: " + blocks[NonExistent]);
            }
        }