public virtual void TestAddBlockRetryShouldReturnBlockWithLocations() { string src = "/testAddBlockRetryShouldReturnBlockWithLocations"; NamenodeProtocols nameNodeRpc = cluster.GetNameNodeRpc(); // create file nameNodeRpc.Create(src, FsPermission.GetFileDefault(), "clientName", new EnumSetWritable <CreateFlag>(EnumSet.Of(CreateFlag.Create)), true, (short)3, 1024, null); // start first addBlock() Log.Info("Starting first addBlock for " + src); LocatedBlock lb1 = nameNodeRpc.AddBlock(src, "clientName", null, null, INodeId.GrandfatherInodeId , null); NUnit.Framework.Assert.IsTrue("Block locations should be present", lb1.GetLocations ().Length > 0); cluster.RestartNameNode(); nameNodeRpc = cluster.GetNameNodeRpc(); LocatedBlock lb2 = nameNodeRpc.AddBlock(src, "clientName", null, null, INodeId.GrandfatherInodeId , null); NUnit.Framework.Assert.AreEqual("Blocks are not equal", lb1.GetBlock(), lb2.GetBlock ()); NUnit.Framework.Assert.IsTrue("Wrong locations with retry", lb2.GetLocations().Length > 0); }
public virtual void TestOpenFilesWithRename() { Path path = new Path("/test"); DoWriteAndAbort(fs, path); // check for zero sized blocks Path fileWithEmptyBlock = new Path("/test/test/test4"); fs.Create(fileWithEmptyBlock); NamenodeProtocols nameNodeRpc = cluster.GetNameNodeRpc(); string clientName = fs.GetClient().GetClientName(); // create one empty block nameNodeRpc.AddBlock(fileWithEmptyBlock.ToString(), clientName, null, null, INodeId .GrandfatherInodeId, null); fs.CreateSnapshot(path, "s2"); fs.Rename(new Path("/test/test"), new Path("/test/test-renamed")); fs.Delete(new Path("/test/test-renamed"), true); NameNode nameNode = cluster.GetNameNode(); NameNodeAdapter.EnterSafeMode(nameNode, false); NameNodeAdapter.SaveNamespace(nameNode); NameNodeAdapter.LeaveSafeMode(nameNode); cluster.RestartNameNode(true); }
public virtual void TestRetryAddBlockWhileInChooseTarget() { string src = "/testRetryAddBlockWhileInChooseTarget"; FSNamesystem ns = cluster.GetNamesystem(); NamenodeProtocols nn = cluster.GetNameNodeRpc(); // create file nn.Create(src, FsPermission.GetFileDefault(), "clientName", new EnumSetWritable <CreateFlag >(EnumSet.Of(CreateFlag.Create)), true, (short)3, 1024, null); // start first addBlock() Log.Info("Starting first addBlock for " + src); LocatedBlock[] onRetryBlock = new LocatedBlock[1]; DatanodeStorageInfo[] targets = ns.GetNewBlockTargets(src, INodeId.GrandfatherInodeId , "clientName", null, null, null, onRetryBlock); NUnit.Framework.Assert.IsNotNull("Targets must be generated", targets); // run second addBlock() Log.Info("Starting second addBlock for " + src); nn.AddBlock(src, "clientName", null, null, INodeId.GrandfatherInodeId, null); NUnit.Framework.Assert.IsTrue("Penultimate block must be complete", CheckFileProgress (src, false)); LocatedBlocks lbs = nn.GetBlockLocations(src, 0, long.MaxValue); NUnit.Framework.Assert.AreEqual("Must be one block", 1, lbs.GetLocatedBlocks().Count ); LocatedBlock lb2 = lbs.Get(0); NUnit.Framework.Assert.AreEqual("Wrong replication", Replication, lb2.GetLocations ().Length); // continue first addBlock() LocatedBlock newBlock = ns.StoreAllocatedBlock(src, INodeId.GrandfatherInodeId, "clientName" , null, targets); NUnit.Framework.Assert.AreEqual("Blocks are not equal", lb2.GetBlock(), newBlock. GetBlock()); // check locations lbs = nn.GetBlockLocations(src, 0, long.MaxValue); NUnit.Framework.Assert.AreEqual("Must be one block", 1, lbs.GetLocatedBlocks().Count ); LocatedBlock lb1 = lbs.Get(0); NUnit.Framework.Assert.AreEqual("Wrong replication", Replication, lb1.GetLocations ().Length); NUnit.Framework.Assert.AreEqual("Blocks are not equal", lb1.GetBlock(), lb2.GetBlock ()); }
/// <exception cref="System.IO.IOException"/> private void TestPlacement(string clientMachine, string clientRack) { // write 5 files and check whether all times block placed for (int i = 0; i < 5; i++) { string src = "/test-" + i; // Create the file with client machine HdfsFileStatus fileStatus = namesystem.StartFile(src, perm, clientMachine, clientMachine , EnumSet.Of(CreateFlag.Create), true, ReplicationFactor, DefaultBlockSize, null , false); LocatedBlock locatedBlock = nameNodeRpc.AddBlock(src, clientMachine, null, null, fileStatus.GetFileId(), null); NUnit.Framework.Assert.AreEqual("Block should be allocated sufficient locations", ReplicationFactor, locatedBlock.GetLocations().Length); if (clientRack != null) { NUnit.Framework.Assert.AreEqual("First datanode should be rack local", clientRack , locatedBlock.GetLocations()[0].GetNetworkLocation()); } nameNodeRpc.AbandonBlock(locatedBlock.GetBlock(), fileStatus.GetFileId(), src, clientMachine ); } }