Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
HDFS-8543. Erasure Coding: processOverReplicatedBlock() handles strip…
…ed block. Contributed by Walter Su.
- Loading branch information
Showing
6 changed files
with
254 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
116 changes: 116 additions & 0 deletions
116
.../test/java/org/apache/hadoop/hdfs/server/namenode/TestAddOverReplicatedStripedBlocks.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,116 @@ | |||
/** | |||
* Licensed to the Apache Software Foundation (ASF) under one | |||
* or more contributor license agreements. See the NOTICE file | |||
* distributed with this work for additional information | |||
* regarding copyright ownership. The ASF licenses this file | |||
* to you under the Apache License, Version 2.0 (the | |||
* "License"); you may not use this file except in compliance | |||
* with the License. You may obtain a copy of the License at | |||
* | |||
* http://www.apache.org/licenses/LICENSE-2.0 | |||
* | |||
* Unless required by applicable law or agreed to in writing, software | |||
* distributed under the License is distributed on an "AS IS" BASIS, | |||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |||
* See the License for the specific language governing permissions and | |||
* limitations under the License. | |||
*/ | |||
package org.apache.hadoop.hdfs.server.namenode; | |||
|
|||
import org.apache.hadoop.conf.Configuration; | |||
import org.apache.hadoop.fs.Path; | |||
import org.apache.hadoop.hdfs.DFSConfigKeys; | |||
import org.apache.hadoop.hdfs.DFSTestUtil; | |||
import org.apache.hadoop.hdfs.DistributedFileSystem; | |||
import org.apache.hadoop.hdfs.MiniDFSCluster; | |||
import org.apache.hadoop.hdfs.protocol.Block; | |||
import org.apache.hadoop.hdfs.protocol.HdfsConstants; | |||
import org.apache.hadoop.hdfs.protocol.LocatedBlocks; | |||
import org.apache.hadoop.hdfs.protocol.LocatedStripedBlock; | |||
import org.apache.hadoop.hdfs.server.datanode.SimulatedFSDataset; | |||
import org.junit.After; | |||
import org.junit.Before; | |||
import org.junit.Test; | |||
|
|||
import java.io.IOException; | |||
import java.util.Arrays; | |||
import java.util.HashSet; | |||
|
|||
import static org.junit.Assert.assertEquals; | |||
import static org.junit.Assert.assertTrue; | |||
|
|||
public class TestAddOverReplicatedStripedBlocks { | |||
|
|||
private MiniDFSCluster cluster; | |||
private DistributedFileSystem fs; | |||
private final Path dirPath = new Path("/striped"); | |||
private Path filePath = new Path(dirPath, "file"); | |||
private final short DATA_BLK_NUM = HdfsConstants.NUM_DATA_BLOCKS; | |||
private final short PARITY_BLK_NUM = HdfsConstants.NUM_PARITY_BLOCKS; | |||
private final short GROUP_SIZE = DATA_BLK_NUM + PARITY_BLK_NUM; | |||
private final int CELLSIZE = HdfsConstants.BLOCK_STRIPED_CELL_SIZE; | |||
private final int NUM_STRIPE_PER_BLOCK = 1; | |||
private final int BLOCK_SIZE = NUM_STRIPE_PER_BLOCK * CELLSIZE; | |||
private final int numDNs = GROUP_SIZE + 3; | |||
|
|||
@Before | |||
public void setup() throws IOException { | |||
Configuration conf = new Configuration(); | |||
conf.setLong(DFSConfigKeys.DFS_BLOCK_SIZE_KEY, BLOCK_SIZE); | |||
SimulatedFSDataset.setFactory(conf); | |||
cluster = new MiniDFSCluster.Builder(conf).numDataNodes(numDNs).build(); | |||
cluster.waitActive(); | |||
fs = cluster.getFileSystem(); | |||
fs.mkdirs(dirPath); | |||
fs.getClient().createErasureCodingZone(dirPath.toString(), null, CELLSIZE); | |||
} | |||
|
|||
@After | |||
public void tearDown() { | |||
if (cluster != null) { | |||
cluster.shutdown(); | |||
} | |||
} | |||
|
|||
@Test | |||
public void testProcessOverReplicatedStripedBlock() throws Exception { | |||
// create a file which has exact one block group to the first GROUP_SIZE DNs | |||
long fileLen = DATA_BLK_NUM * BLOCK_SIZE; | |||
DFSTestUtil.createStripedFile(cluster, filePath, null, 1, | |||
NUM_STRIPE_PER_BLOCK, false); | |||
LocatedBlocks lbs = cluster.getNameNodeRpc().getBlockLocations( | |||
filePath.toString(), 0, fileLen); | |||
LocatedStripedBlock bg = (LocatedStripedBlock) (lbs.get(0)); | |||
long gs = bg.getBlock().getGenerationStamp(); | |||
String bpid = bg.getBlock().getBlockPoolId(); | |||
long groupId = bg.getBlock().getBlockId(); | |||
Block blk = new Block(groupId, BLOCK_SIZE, gs); | |||
for (int i = 0; i < GROUP_SIZE; i++) { | |||
blk.setBlockId(groupId + i); | |||
cluster.injectBlocks(i, Arrays.asList(blk), bpid); | |||
} | |||
cluster.triggerBlockReports(); | |||
|
|||
// let a internal block be over replicated with 2 redundant blocks. | |||
blk.setBlockId(groupId + 2); | |||
cluster.injectBlocks(numDNs - 3, Arrays.asList(blk), bpid); | |||
cluster.injectBlocks(numDNs - 2, Arrays.asList(blk), bpid); | |||
// let a internal block be over replicated with 1 redundant block. | |||
blk.setBlockId(groupId + 6); | |||
cluster.injectBlocks(numDNs - 1, Arrays.asList(blk), bpid); | |||
|
|||
// update blocksMap | |||
cluster.triggerBlockReports(); | |||
// add to invalidates | |||
cluster.triggerHeartbeats(); | |||
// datanode delete block | |||
cluster.triggerHeartbeats(); | |||
// update blocksMap | |||
cluster.triggerBlockReports(); | |||
|
|||
// verify that all internal blocks exists | |||
lbs = cluster.getNameNodeRpc().getBlockLocations( | |||
filePath.toString(), 0, fileLen); | |||
DFSTestUtil.verifyLocatedStripedBlocks(lbs, GROUP_SIZE); | |||
} | |||
} |