internal virtual void Initialize(FsDatasetImpl fsDataset) { this.fsDataset = fsDataset; }
/// <exception cref="System.IO.IOException"/> private void TestWriteToRbw(FsDatasetImpl dataSet, ExtendedBlock[] blocks) { try { dataSet.RecoverRbw(blocks[Finalized], blocks[Finalized].GetGenerationStamp() + 1, 0L, blocks[Finalized].GetNumBytes()); NUnit.Framework.Assert.Fail("Should not have recovered a finalized replica " + blocks [Finalized]); } catch (ReplicaNotFoundException e) { NUnit.Framework.Assert.IsTrue(e.Message.StartsWith(ReplicaNotFoundException.NonRbwReplica )); } try { dataSet.CreateRbw(StorageType.Default, blocks[Finalized], false); NUnit.Framework.Assert.Fail("Should not have created a replica that's already " + "finalized " + blocks[Finalized]); } catch (ReplicaAlreadyExistsException) { } try { dataSet.RecoverRbw(blocks[Temporary], blocks[Temporary].GetGenerationStamp() + 1, 0L, blocks[Temporary].GetNumBytes()); NUnit.Framework.Assert.Fail("Should not have recovered a temporary replica " + blocks [Temporary]); } catch (ReplicaNotFoundException e) { NUnit.Framework.Assert.IsTrue(e.Message.StartsWith(ReplicaNotFoundException.NonRbwReplica )); } try { dataSet.CreateRbw(StorageType.Default, blocks[Temporary], false); NUnit.Framework.Assert.Fail("Should not have created a replica that had created as " + "temporary " + blocks[Temporary]); } catch (ReplicaAlreadyExistsException) { } dataSet.RecoverRbw(blocks[Rbw], blocks[Rbw].GetGenerationStamp() + 1, 0L, blocks[ Rbw].GetNumBytes()); // expect to be successful try { dataSet.CreateRbw(StorageType.Default, blocks[Rbw], false); NUnit.Framework.Assert.Fail("Should not have created a replica that had created as RBW " + blocks[Rbw]); } catch (ReplicaAlreadyExistsException) { } try { dataSet.RecoverRbw(blocks[Rwr], blocks[Rwr].GetGenerationStamp() + 1, 0L, blocks[ Rwr].GetNumBytes()); NUnit.Framework.Assert.Fail("Should not have recovered a RWR replica " + blocks[Rwr ]); } catch (ReplicaNotFoundException e) { NUnit.Framework.Assert.IsTrue(e.Message.StartsWith(ReplicaNotFoundException.NonRbwReplica )); } try { dataSet.CreateRbw(StorageType.Default, blocks[Rwr], false); NUnit.Framework.Assert.Fail("Should not have created a replica that was waiting to be " + "recovered " + blocks[Rwr]); } catch (ReplicaAlreadyExistsException) { } try { dataSet.RecoverRbw(blocks[Rur], blocks[Rur].GetGenerationStamp() + 1, 0L, blocks[ Rur].GetNumBytes()); NUnit.Framework.Assert.Fail("Should not have recovered a RUR replica " + blocks[Rur ]); } catch (ReplicaNotFoundException e) { NUnit.Framework.Assert.IsTrue(e.Message.StartsWith(ReplicaNotFoundException.NonRbwReplica )); } try { dataSet.CreateRbw(StorageType.Default, blocks[Rur], false); NUnit.Framework.Assert.Fail("Should not have created a replica that was under recovery " + blocks[Rur]); } catch (ReplicaAlreadyExistsException) { } try { dataSet.RecoverRbw(blocks[NonExistent], blocks[NonExistent].GetGenerationStamp() + 1, 0L, blocks[NonExistent].GetNumBytes()); NUnit.Framework.Assert.Fail("Cannot recover a non-existent replica " + blocks[NonExistent ]); } catch (ReplicaNotFoundException e) { NUnit.Framework.Assert.IsTrue(e.Message.Contains(ReplicaNotFoundException.NonExistentReplica )); } dataSet.CreateRbw(StorageType.Default, blocks[NonExistent], false); }
/// <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]); } }
/// <exception cref="System.IO.IOException"/> private void TestAppend(string bpid, FsDatasetImpl dataSet, ExtendedBlock[] blocks ) { long newGS = blocks[Finalized].GetGenerationStamp() + 1; FsVolumeImpl v = (FsVolumeImpl)dataSet.volumeMap.Get(bpid, blocks[Finalized].GetLocalBlock ()).GetVolume(); long available = v.GetCapacity() - v.GetDfsUsed(); long expectedLen = blocks[Finalized].GetNumBytes(); try { v.DecDfsUsed(bpid, -available); blocks[Finalized].SetNumBytes(expectedLen + 100); dataSet.Append(blocks[Finalized], newGS, expectedLen); NUnit.Framework.Assert.Fail("Should not have space to append to an RWR replica" + blocks[Rwr]); } catch (DiskChecker.DiskOutOfSpaceException e) { NUnit.Framework.Assert.IsTrue(e.Message.StartsWith("Insufficient space for appending to " )); } v.DecDfsUsed(bpid, available); blocks[Finalized].SetNumBytes(expectedLen); newGS = blocks[Rbw].GetGenerationStamp() + 1; dataSet.Append(blocks[Finalized], newGS, blocks[Finalized].GetNumBytes()); // successful blocks[Finalized].SetGenerationStamp(newGS); try { dataSet.Append(blocks[Temporary], blocks[Temporary].GetGenerationStamp() + 1, blocks [Temporary].GetNumBytes()); NUnit.Framework.Assert.Fail("Should not have appended to a temporary replica " + blocks[Temporary]); } catch (ReplicaNotFoundException e) { NUnit.Framework.Assert.AreEqual(ReplicaNotFoundException.UnfinalizedReplica + blocks [Temporary], e.Message); } try { dataSet.Append(blocks[Rbw], blocks[Rbw].GetGenerationStamp() + 1, blocks[Rbw].GetNumBytes ()); NUnit.Framework.Assert.Fail("Should not have appended to an RBW replica" + blocks [Rbw]); } catch (ReplicaNotFoundException e) { NUnit.Framework.Assert.AreEqual(ReplicaNotFoundException.UnfinalizedReplica + blocks [Rbw], e.Message); } try { dataSet.Append(blocks[Rwr], blocks[Rwr].GetGenerationStamp() + 1, blocks[Rbw].GetNumBytes ()); NUnit.Framework.Assert.Fail("Should not have appended to an RWR replica" + blocks [Rwr]); } catch (ReplicaNotFoundException e) { NUnit.Framework.Assert.AreEqual(ReplicaNotFoundException.UnfinalizedReplica + blocks [Rwr], e.Message); } try { dataSet.Append(blocks[Rur], blocks[Rur].GetGenerationStamp() + 1, blocks[Rur].GetNumBytes ()); NUnit.Framework.Assert.Fail("Should not have appended to an RUR replica" + blocks [Rur]); } catch (ReplicaNotFoundException e) { NUnit.Framework.Assert.AreEqual(ReplicaNotFoundException.UnfinalizedReplica + blocks [Rur], e.Message); } try { dataSet.Append(blocks[NonExistent], blocks[NonExistent].GetGenerationStamp(), blocks [NonExistent].GetNumBytes()); NUnit.Framework.Assert.Fail("Should not have appended to a non-existent replica " + blocks[NonExistent]); } catch (ReplicaNotFoundException e) { NUnit.Framework.Assert.AreEqual(ReplicaNotFoundException.NonExistentReplica + blocks [NonExistent], e.Message); } newGS = blocks[Finalized].GetGenerationStamp() + 1; dataSet.RecoverAppend(blocks[Finalized], newGS, blocks[Finalized].GetNumBytes()); // successful blocks[Finalized].SetGenerationStamp(newGS); try { dataSet.RecoverAppend(blocks[Temporary], blocks[Temporary].GetGenerationStamp() + 1, blocks[Temporary].GetNumBytes()); NUnit.Framework.Assert.Fail("Should not have appended to a temporary replica " + blocks[Temporary]); } catch (ReplicaNotFoundException e) { NUnit.Framework.Assert.IsTrue(e.Message.StartsWith(ReplicaNotFoundException.UnfinalizedAndNonrbwReplica )); } newGS = blocks[Rbw].GetGenerationStamp() + 1; dataSet.RecoverAppend(blocks[Rbw], newGS, blocks[Rbw].GetNumBytes()); blocks[Rbw].SetGenerationStamp(newGS); try { dataSet.RecoverAppend(blocks[Rwr], blocks[Rwr].GetGenerationStamp() + 1, blocks[Rbw ].GetNumBytes()); NUnit.Framework.Assert.Fail("Should not have appended to an RWR replica" + blocks [Rwr]); } catch (ReplicaNotFoundException e) { NUnit.Framework.Assert.IsTrue(e.Message.StartsWith(ReplicaNotFoundException.UnfinalizedAndNonrbwReplica )); } try { dataSet.RecoverAppend(blocks[Rur], blocks[Rur].GetGenerationStamp() + 1, blocks[Rur ].GetNumBytes()); NUnit.Framework.Assert.Fail("Should not have appended to an RUR replica" + blocks [Rur]); } catch (ReplicaNotFoundException e) { NUnit.Framework.Assert.IsTrue(e.Message.StartsWith(ReplicaNotFoundException.UnfinalizedAndNonrbwReplica )); } try { dataSet.RecoverAppend(blocks[NonExistent], blocks[NonExistent].GetGenerationStamp (), blocks[NonExistent].GetNumBytes()); NUnit.Framework.Assert.Fail("Should not have appended to a non-existent replica " + blocks[NonExistent]); } catch (ReplicaNotFoundException e) { NUnit.Framework.Assert.IsTrue(e.Message.StartsWith(ReplicaNotFoundException.NonExistentReplica )); } }